Skip to content

Commit

Permalink
Use itm java codeformat (#16)
Browse files Browse the repository at this point in the history
* code formatter / linter added
  • Loading branch information
martind260 committed Sep 26, 2023
1 parent b3bced0 commit 8564419
Show file tree
Hide file tree
Showing 135 changed files with 28,903 additions and 5,374 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Don't forget to give the project a star! Thanks again!
5. Push to the Branch (`git push origin feature/AmazingFeature`)
6. Open a Pull Request

### Coding Conventions

We use the [itm-java-codeformat](https://github.com/it-at-m/itm-java-codeformat) project to apply code formatting conventions.
To add those conventions to your favorite IDE, please have a look at the [README of itm-java-codeformat](https://github.com/it-at-m/itm-java-codeformat#verwendung).

## License

Distributed under the MIT License. See `LICENSE` for more information.
Expand Down
101 changes: 101 additions & 0 deletions apigateway/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name = "Checker">
<property name="charset" value="UTF-8"/>

<property name="severity" value="error"/>

<property name="fileExtensions" value="java, properties, xml"/>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="NoLineWrap">
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
</module>
<module name="LeftCurly" />
<module name="RightCurly" />
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<property name="allowEmptyCatches" value="true"/>
<property name="ignoreEnhancedForColon" value="false"/>
<property name="tokens"
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>
<module name="GenericWhitespace">
<message key="ws.followed"
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
<message key="ws.preceded"
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
<message key="ws.illegalFollow"
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
<message key="ws.notPreceded"
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="OneStatementPerLine"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="tokens"
value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
STATIC_INIT, INSTANCE_INIT, CTOR_DEF, VARIABLE_DEF, RECORD_DEF,
COMPACT_CTOR_DEF"/>
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapDot"/>
<property name="tokens" value="DOT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapComma"/>
<property name="tokens" value="COMMA"/>
<property name="option" value="EOL"/>
</module>

<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
</module>
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF, RECORD_DEF"/>
</module>
<module name="NoWhitespaceBefore">
<property name="tokens"
value="COMMA, SEMI, POST_INC, POST_DEC, DOT,
LABELED_STAT, METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="ParenPad"/>
<module name="AnnotationLocation">
<property name="allowSamelineMultipleAnnotations" value="false"/>
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>
<property name="allowSamelineParameterizedAnnotation" value="false"/>
</module>
<module name="AbbreviationAsWordInName"/>
<module name="UnusedLocalVariable"/>
</module>
</module>
55 changes: 55 additions & 0 deletions apigateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<logstash.encoder.version>7.0.1</logstash.encoder.version>
<apache.commons.lang.version>3.12.0</apache.commons.lang.version>
<jvm.options>-Dorg.conscrypt.native.workdir=$(pwd)</jvm.options>
<itm-codeformat.version>1.0.3</itm-codeformat.version>
</properties>


Expand Down Expand Up @@ -179,6 +180,60 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.28.0</version>
<dependencies>
<dependency>
<groupId>de.muenchen.itm</groupId>
<artifactId>itm-java-codeformat</artifactId>
<version>${itm-codeformat.version}</version>
</dependency>
</dependencies>
<configuration>
<java>
<includes>
<include>src/main/java/**/*.java</include> <!-- Check application code -->
<include>src/test/java/**/*.java</include> <!-- Check application tests code -->
</includes>
<eclipse>
<file>itm-java-codeformat/java_codestyle_formatter.xml</file>
</eclipse>
<trimTrailingWhitespace/>
<endWithNewline/>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>9.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


/**
* To do some base configuration for the non blocking client-server framework
* named Netty via properties use the properties listed in the link down below:
*
* @see <a href="https://projectreactor.io/docs/netty/release/api/constant-values.html">https://projectreactor.io/docs/netty/release/api/constant-values.html</a>
* @see <a href=
* "https://projectreactor.io/docs/netty/release/api/constant-values.html">https://projectreactor.io/docs/netty/release/api/constant-values.html</a>
*
* As listed below, this above mentioned properties should be set before the application startup:
* As listed below, this above mentioned properties should be set before the application
* startup:
*
* <ul>
* <li>As command line argument: e.g. -Dreactor.netty.pool.maxConnections=1000.
* <li>As environmental property in Openshift: e.g. with key REACTOR_NETTY_POOL_MAXCONNECTIONS and value 1000.
* <li>As programatically set property before call {@link SpringApplication#run} in {@link ApiGatewayApplication#main}: e.g. <code>System.setProperty("reactor.netty.pool.maxConnections", "1000");</code>.
* </ul>
* <ul>
* <li>As command line argument: e.g. -Dreactor.netty.pool.maxConnections=1000.
* <li>As environmental property in Openshift: e.g. with key REACTOR_NETTY_POOL_MAXCONNECTIONS
* and value 1000.
* <li>As programatically set property before call {@link SpringApplication#run} in
* {@link ApiGatewayApplication#main}: e.g.
* <code>System.setProperty("reactor.netty.pool.maxConnections", "1000");</code>.
* </ul>
*
* To get more information about Spring Cloud Gateway visit the following link:
* To get more information about Spring Cloud Gateway visit the following link:
*
* @see <a href="https://cloud.spring.io/spring-cloud-gateway/reference/html/">https://cloud.spring.io/spring-cloud-gateway/reference/html/</a>
* @see <a href=
* "https://cloud.spring.io/spring-cloud-gateway/reference/html/">https://cloud.spring.io/spring-cloud-gateway/reference/html/</a>
*/
@SpringBootApplication(
scanBasePackages = {"de.muenchen.dave"}
)
@SpringBootApplication(scanBasePackages = { "de.muenchen.dave" })
public class ApiGatewayApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*/
package de.muenchen.dave.configuration;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -13,11 +17,6 @@
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;


/**
* This class supplies the endpoint which provides the gui.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;


@Configuration
@Profile("no-security")
public class NoSecurityConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package de.muenchen.dave.configuration;

import de.muenchen.dave.util.GatewayUtils;
import java.time.Duration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -19,9 +20,6 @@
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;
import reactor.core.publisher.Mono;

import java.time.Duration;


@Configuration
@Profile("!no-security")
public class SecurityConfiguration {
Expand Down Expand Up @@ -51,7 +49,8 @@ public SecurityWebFilterChain springSecurityFilterChain(final ServerHttpSecurity
.pathMatchers("/api/*/info",
"/actuator/health",
"/actuator/info",
"/actuator/metrics").permitAll()
"/actuator/metrics")
.permitAll()
// only authenticated
.anyExchange().authenticated()
.and()
Expand All @@ -71,8 +70,7 @@ public SecurityWebFilterChain springSecurityFilterChain(final ServerHttpSecurity
@Override
public Mono<Void> onAuthenticationSuccess(final WebFilterExchange webFilterExchange, final Authentication authentication) {
webFilterExchange.getExchange().getSession().subscribe(
webSession -> webSession.setMaxIdleTime(Duration.ofSeconds(SecurityConfiguration.this.springSessionTimeoutSeconds))
);
webSession -> webSession.setMaxIdleTime(Duration.ofSeconds(SecurityConfiguration.this.springSessionTimeoutSeconds)));
return super.onAuthenticationSuccess(webFilterExchange, authentication);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/
package de.muenchen.dave.configuration;

import java.time.Duration;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

import java.time.Duration;

/**
* VueCacheConfigurer setzt Cache Header für die von Vue gebauten Resourcen. Sie enthalten im Namen ein Hash,
* VueCacheConfigurer setzt Cache Header für die von Vue gebauten Resourcen. Sie enthalten im Namen
* ein Hash,
* deswegen sollte das Caching hier keine Probleme machen.
*/
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.springframework.session.config.annotation.web.server.EnableSpringWebSession;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;


/**
* This class configures Hazelcast as the ReactiveSessionRepository.
*/
Expand All @@ -45,13 +44,14 @@ public ServerOAuth2AuthorizedClientRepository authorizedClientRepository() {
}

@Bean
public ReactiveSessionRepository<MapSession> reactiveSessionRepository(@Qualifier("hazelcastInstance") @Autowired final HazelcastInstance hazelcastInstance) {
public ReactiveSessionRepository<MapSession> reactiveSessionRepository(
@Qualifier("hazelcastInstance") @Autowired final HazelcastInstance hazelcastInstance) {
final IMap<String, Session> map = hazelcastInstance.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
return new ReactiveMapSessionRepository(map);
}

@Bean
@Profile({"local", "test"})
@Profile({ "local", "test" })
public Config localConfig(@Value("${spring.session.timeout}") final int timeout) {
final var hazelcastConfig = new Config();
hazelcastConfig.setInstanceName(this.hazelcastInstanceName);
Expand All @@ -71,13 +71,12 @@ public Config localConfig(@Value("${spring.session.timeout}") final int timeout)
}

@Bean
@Profile({"dev", "kon", "prod", "demo", "konexternal", "prodexternal"})
@Profile({ "dev", "kon", "prod", "demo", "konexternal", "prodexternal" })
public Config config(@Value("${spring.session.timeout}") final int timeout) {
final var hazelcastConfig = new Config();
hazelcastConfig.setInstanceName(this.hazelcastInstanceName);
hazelcastConfig.setClusterName(this.groupConfigName);


this.addSessionTimeoutToHazelcastConfig(hazelcastConfig, timeout);

hazelcastConfig.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
Expand All @@ -95,7 +94,7 @@ public Config config(@Value("${spring.session.timeout}") final int timeout) {
* by setting a reasonable value for time to live.
*
* @param hazelcastConfig to add the timeout.
* @param sessionTimeout for security session.
* @param sessionTimeout for security session.
*/
private void addSessionTimeoutToHazelcastConfig(final Config hazelcastConfig, final int sessionTimeout) {
final var sessionConfig = new MapConfig();
Expand All @@ -106,4 +105,3 @@ private void addSessionTimeoutToHazelcastConfig(final Config hazelcastConfig, fi
hazelcastConfig.addMapConfig(sessionConfig);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*/
package de.muenchen.dave.controller;

import static org.springframework.hateoas.server.reactive.WebFluxLinkBuilder.linkTo;
import static org.springframework.hateoas.server.reactive.WebFluxLinkBuilder.methodOn;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -14,12 +18,6 @@
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.List;

import static org.springframework.hateoas.server.reactive.WebFluxLinkBuilder.linkTo;
import static org.springframework.hateoas.server.reactive.WebFluxLinkBuilder.methodOn;


/**
* Endpoint for pinging with an authorized request
* to check for available or expired security sessions.
Expand Down
Loading

0 comments on commit 8564419

Please sign in to comment.