Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openrewrite test #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 74 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -18,12 +18,12 @@
<profile.tls/>

<springdoc-openapi-ui.version>1.4.3</springdoc-openapi-ui.version>
<mapstruct.version>1.3.1.Final</mapstruct.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>

<selenide.version>5.15.0</selenide.version>
<google-guava.version>29.0-jre</google-guava.version>

<wro4j-sb-starter.version>0.7.1</wro4j-sb-starter.version>
<wro4j.version>1.9.0</wro4j.version>

<!-- client deps -->
<webjar-jquery.version>3.5.1</webjar-jquery.version>
Expand All @@ -34,7 +34,7 @@
<!-- code quality -->
<archunit-junit5.version>0.14.1</archunit-junit5.version>
<sonar-maven-plugin.version>3.6.0.1398</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.5</jacoco-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<maven.checkstyle.plugin.version>3.1.0</maven.checkstyle.plugin.version>
<puppycrawl.checkstyle.version>8.36.1</puppycrawl.checkstyle.version>
<puppycrawl.checkstyle.config.file>src/main/resources/checkstyle.xml</puppycrawl.checkstyle.config.file>
Expand All @@ -51,7 +51,7 @@

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
Expand All @@ -72,11 +72,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>eu.michael-simons</groupId>
<artifactId>wro4j-spring-boot-starter</artifactId>
<version>${wro4j-sb-starter.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
Expand All @@ -85,7 +81,7 @@
<!-- security-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>

<dependency>
Expand All @@ -100,6 +96,18 @@
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>

<!-- processors/code generators -->
<dependency>
Expand Down Expand Up @@ -162,12 +170,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -202,7 +204,28 @@
<finalName>${build.profile}-${project.version}-app</finalName>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>

<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<wroManagerFactory>
ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
</wroManagerFactory>
<cssDestinationFolder>${project.build.directory}/classes/static/css</cssDestinationFolder>
<jsDestinationFolder>${project.build.directory}/classes/static/js</jsDestinationFolder>
<wroFile>${basedir}/src/main/resources/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/resources/wro.properties</extraConfigFile>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down Expand Up @@ -331,6 +354,39 @@
</executions>
</plugin>

<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>4.40.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0</recipe>
<recipe>org.openrewrite.java.migrate.UpgradeToJava17</recipe>
<recipe>org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration</recipe>
<recipe>org.openrewrite.java.logging.slf4j.Log4jToSlf4j</recipe>
<recipe>org.openrewrite.java.logging.slf4j.ParameterizedLogging</recipe>
<recipe>org.openrewrite.java.cleanup.CommonStaticAnalysis</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>4.33.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>1.17.0</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-logging-frameworks</artifactId>
<version>1.18.0</version>
</dependency>
</dependencies>
</plugin>

</plugins>
</build>

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gt/app/config/CachingHttpHeadersFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gt/app/config/ReqLogFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -17,8 +17,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

req.put("req.remoteHost", request.getRemoteHost());

if (request instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
if (request instanceof HttpServletRequest httpServletRequest) {
req.put("req.requestURI", httpServletRequest.getRequestURI());
StringBuffer requestURL = httpServletRequest.getRequestURL();
if (requestURL != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gt/app/config/WebConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
import jakarta.servlet.ServletContext;
import java.util.EnumSet;

@Configuration
Expand Down Expand Up @@ -42,7 +42,7 @@ private void initCachingHttpHeadersFilter(ServletContext servletContext, EnumSet
}

@Bean
public FilterRegistrationBean<ReqLogFilter> loggingFilter() {
FilterRegistrationBean<ReqLogFilter> loggingFilter() {
FilterRegistrationBean<ReqLogFilter> registrationBean = new FilterRegistrationBean<>();

registrationBean.setFilter(new ReqLogFilter());
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/gt/app/config/security/AppUserDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@Getter
public class AppUserDetails extends User {

private static final long serialVersionUID = 1;

private Long id;
private String firstName;

Expand Down Expand Up @@ -48,9 +50,15 @@ public Collection<String> getGrantedAuthorities() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
AppUserDetails that = (AppUserDetails) o;
return id.equals(that.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import java.util.Optional;

@Component
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/gt/app/config/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@Configuration
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {
public class SecurityConfig {

private static final String[] AUTH_WHITELIST = {
"/swagger-resources/**",
Expand All @@ -30,25 +30,25 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/" //landing page is allowed for all
};

private final AppUserDetailsService appUserDetailsService;
// private final AppUserDetailsService appUserDetailsService;
//
// @Autowired
// public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
// authenticationManagerBuilder
// .userDetailsService(appUserDetailsService)
// .passwordEncoder(passwordEncoder());
// }

@Autowired
public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder
.userDetailsService(appUserDetailsService)
.passwordEncoder(passwordEncoder());
}

@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.headers().frameOptions().sameOrigin()
.and()
.authorizeRequests()
.antMatchers(AUTH_WHITELIST).permitAll()
.antMatchers("/admin/**").hasAuthority(Constants.ROLE_ADMIN)
.antMatchers("/user/**").hasAuthority(Constants.ROLE_USER)
.antMatchers("/api/**").authenticated()//individual api will be secured differently
.authorizeHttpRequests()
.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers("/admin/**").hasAuthority(Constants.ROLE_ADMIN)
.requestMatchers("/user/**").hasAuthority(Constants.ROLE_USER)
.requestMatchers("/api/**").authenticated()//individual api will be secured differently
.anyRequest().authenticated() //this one will catch the rest patterns
.and()
.csrf().disable()
Expand All @@ -60,11 +60,12 @@ protected void configure(HttpSecurity http) throws Exception {
.logoutUrl("/auth/logout")
.logoutSuccessUrl("/?logout")
.permitAll();
return http.build();

}

@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/gt/app/config/security/SecurityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public static Optional<String> getCurrentUserLogin() {
public static Long getCurrentUserId() {

User user = getCurrentUserDetails();
if (user instanceof AppUserDetails) {
AppUserDetails appUserDetails = (AppUserDetails) user;
if (user instanceof AppUserDetails appUserDetails) {
return appUserDetails.getId();
}
return null;
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/gt/app/domain/Authority.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

@Entity
@Setter
public class Authority implements GrantedAuthority {

private static final long serialVersionUID = 1;

@Id
@Column(length = 16)
private String name;
Expand All @@ -22,8 +24,12 @@ public String getAuthority() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Authority authority1 = (Authority) o;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gt/app/domain/BaseAuditingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import jakarta.persistence.*;
import java.time.Instant;

@MappedSuperclass
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gt/app/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import lombok.Data;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;

@Data
@MappedSuperclass
Expand Down
Loading