Skip to content

Commit a4d5a41

Browse files
committed
chore: update spring boot version
1 parent d0b0990 commit a4d5a41

19 files changed

+137
-141
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.springframework.boot</groupId>
66
<artifactId>spring-boot-starter-parent</artifactId>
7-
<version>2.6.2</version>
7+
<version>2.7.0</version>
88
<relativePath /> <!-- lookup parent from repository -->
99
</parent>
1010
<groupId>com.github.throyer.common.spring-boot</groupId>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.github.throyer.common.springboot;
22

3-
import org.springframework.boot.SpringApplication;
43
import org.springframework.boot.autoconfigure.SpringBootApplication;
54
import org.springframework.cache.annotation.EnableCaching;
6-
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
5+
6+
import static org.springframework.boot.SpringApplication.run;
77

88
@EnableCaching
99
@SpringBootApplication
1010
public class Application {
1111
public static void main(String... args) {
12-
SpringApplication.run(Application.class, args);
12+
run(Application.class, args);
1313
}
1414
}
Lines changed: 85 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
package com.github.throyer.common.springboot.configurations;
22

3+
import static com.github.throyer.common.springboot.constants.SECURITY.ACESSO_NEGADO_URL;
4+
import static com.github.throyer.common.springboot.constants.SECURITY.DAY_MILLISECONDS;
5+
import static com.github.throyer.common.springboot.constants.SECURITY.HOME_URL;
6+
import static com.github.throyer.common.springboot.constants.SECURITY.LOGIN_ERROR_URL;
7+
import static com.github.throyer.common.springboot.constants.SECURITY.LOGIN_URL;
8+
import static com.github.throyer.common.springboot.constants.SECURITY.LOGOUT_URL;
9+
import static com.github.throyer.common.springboot.constants.SECURITY.PASSWORD_PARAMETER;
10+
import static com.github.throyer.common.springboot.constants.SECURITY.PUBLIC_API_ROUTES;
11+
import static com.github.throyer.common.springboot.constants.SECURITY.SESSION_COOKIE_NAME;
12+
import static com.github.throyer.common.springboot.constants.SECURITY.STATIC_FILES;
13+
import static com.github.throyer.common.springboot.constants.SECURITY.TOKEN_SECRET;
14+
import static com.github.throyer.common.springboot.constants.SECURITY.USERNAME_PARAMETER;
15+
import static com.github.throyer.common.springboot.utils.Responses.forbidden;
16+
import static org.springframework.http.HttpMethod.GET;
17+
import static org.springframework.http.HttpMethod.POST;
18+
import static org.springframework.security.config.Customizer.withDefaults;
19+
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
20+
321
import com.github.throyer.common.springboot.domain.session.service.SessionService;
422
import com.github.throyer.common.springboot.middlewares.AuthorizationMiddleware;
23+
524
import org.springframework.beans.factory.annotation.Autowired;
625
import org.springframework.context.annotation.Bean;
726
import org.springframework.context.annotation.Configuration;
827
import org.springframework.core.annotation.Order;
9-
import org.springframework.security.authentication.AuthenticationManager;
10-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
1128
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1229
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
13-
import org.springframework.security.config.annotation.web.builders.WebSecurity;
1430
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
15-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
31+
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
32+
import org.springframework.security.web.SecurityFilterChain;
1633
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1734
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
1835
import org.springframework.stereotype.Component;
1936
import org.springframework.web.cors.CorsConfiguration;
2037

21-
import static com.github.throyer.common.springboot.constants.SECURITY.*;
22-
import static com.github.throyer.common.springboot.utils.Responses.forbidden;
23-
import static org.springframework.http.HttpMethod.GET;
24-
import static org.springframework.http.HttpMethod.POST;
25-
import static org.springframework.security.config.http.SessionCreationPolicy.STATELESS;
26-
2738
@Component
39+
@Configuration
2840
@EnableWebSecurity
2941
@EnableGlobalMethodSecurity(prePostEnabled = true)
3042
public class SpringSecurityConfiguration {
@@ -41,96 +53,75 @@ public SpringSecurityConfiguration(
4153
this.filter = filter;
4254
}
4355

44-
@Order(1)
45-
@Configuration
46-
public class Api extends WebSecurityConfigurerAdapter {
47-
48-
@Override
49-
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
50-
auth.userDetailsService(sessionService)
51-
.passwordEncoder(PASSWORD_ENCODER);
52-
}
53-
54-
@Override
55-
protected void configure(HttpSecurity http) throws Exception {
56-
PUBLIC_API_ROUTES.injectOn(http);
56+
@Bean
57+
public WebSecurityCustomizer webSecurityCustomizer() {
58+
return (web) -> web.ignoring().antMatchers(STATIC_FILES);
59+
}
5760

58-
http
59-
.antMatcher("/api/**")
60-
.authorizeRequests()
61-
.anyRequest()
62-
.authenticated()
63-
.and()
64-
.csrf()
65-
.disable()
66-
.exceptionHandling()
67-
.authenticationEntryPoint((request, response, exception) -> forbidden(response))
68-
.and()
69-
.sessionManagement()
70-
.sessionCreationPolicy(STATELESS)
71-
.and()
72-
.addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class)
73-
.cors()
74-
.configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues());
75-
}
61+
@Bean
62+
@Order(1)
63+
public SecurityFilterChain api(HttpSecurity http) throws Exception {
64+
PUBLIC_API_ROUTES.injectOn(http);
7665

77-
@Override
78-
public void configure(WebSecurity web) {
79-
web
80-
.ignoring()
81-
.antMatchers(STATIC_FILES);
82-
}
66+
http
67+
.httpBasic(withDefaults())
68+
.antMatcher("/api/**")
69+
.authorizeRequests()
70+
.anyRequest()
71+
.authenticated()
72+
.and()
73+
.csrf()
74+
.disable()
75+
.exceptionHandling()
76+
.authenticationEntryPoint((request, response, exception) -> forbidden(response))
77+
.and()
78+
.userDetailsService(sessionService)
79+
.sessionManagement()
80+
.sessionCreationPolicy(STATELESS)
81+
.and()
82+
.addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class)
83+
.cors()
84+
.configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues());
8385

84-
@Bean
85-
@Override
86-
protected AuthenticationManager authenticationManager() throws Exception {
87-
return super.authenticationManager();
88-
}
86+
return http.build();
8987
}
9088

89+
@Bean
9190
@Order(2)
92-
@Configuration
93-
public class App extends WebSecurityConfigurerAdapter {
94-
@Override
95-
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
96-
auth.
97-
userDetailsService(sessionService)
98-
.passwordEncoder(PASSWORD_ENCODER);
99-
}
100-
101-
@Override
102-
protected void configure(HttpSecurity http) throws Exception {
91+
public SecurityFilterChain app(HttpSecurity http) throws Exception {
92+
http
93+
.antMatcher("/app/**")
94+
.authorizeRequests()
95+
.antMatchers(GET, LOGIN_URL, "/app", "/app/register", "/app/recovery/**")
96+
.permitAll()
97+
.antMatchers(POST, "/app/register", "/app/recovery/**")
98+
.permitAll()
99+
.anyRequest()
100+
.authenticated()
101+
.and()
102+
.csrf()
103+
.disable()
104+
.userDetailsService(sessionService)
105+
.formLogin()
106+
.loginPage(LOGIN_URL)
107+
.failureUrl(LOGIN_ERROR_URL)
108+
.defaultSuccessUrl(HOME_URL)
109+
.usernameParameter(USERNAME_PARAMETER)
110+
.passwordParameter(PASSWORD_PARAMETER)
111+
.and()
112+
.rememberMe()
113+
.userDetailsService(sessionService)
114+
.key(TOKEN_SECRET)
115+
.tokenValiditySeconds(DAY_MILLISECONDS)
116+
.and()
117+
.logout()
118+
.deleteCookies(SESSION_COOKIE_NAME)
119+
.logoutRequestMatcher(new AntPathRequestMatcher(LOGOUT_URL))
120+
.logoutSuccessUrl(LOGIN_URL)
121+
.and()
122+
.exceptionHandling()
123+
.accessDeniedPage(ACESSO_NEGADO_URL);
103124

104-
http
105-
.antMatcher("/app/**")
106-
.authorizeRequests()
107-
.antMatchers(GET, LOGIN_URL, "/app", "/app/register", "/app/recovery/**")
108-
.permitAll()
109-
.antMatchers(POST, "/app/register", "/app/recovery/**")
110-
.permitAll()
111-
.anyRequest()
112-
.authenticated()
113-
.and()
114-
.csrf()
115-
.disable()
116-
.formLogin()
117-
.loginPage(LOGIN_URL)
118-
.failureUrl(LOGIN_ERROR_URL)
119-
.defaultSuccessUrl(HOME_URL)
120-
.usernameParameter(USERNAME_PARAMETER)
121-
.passwordParameter(PASSWORD_PARAMETER)
122-
.and()
123-
.rememberMe()
124-
.key(TOKEN_SECRET)
125-
.tokenValiditySeconds(DAY_MILLISECONDS)
126-
.and()
127-
.logout()
128-
.deleteCookies(SESSION_COOKIE_NAME)
129-
.logoutRequestMatcher(new AntPathRequestMatcher(LOGOUT_URL))
130-
.logoutSuccessUrl(LOGIN_URL)
131-
.and()
132-
.exceptionHandling()
133-
.accessDeniedPage(ACESSO_NEGADO_URL);
134-
}
125+
return http.build();
135126
}
136127
}

src/main/java/com/github/throyer/common/springboot/configurations/SpringWebConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5-
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
65
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
76
import org.springframework.web.servlet.config.annotation.CorsRegistry;
87
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

src/main/java/com/github/throyer/common/springboot/controllers/app/UserController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.github.throyer.common.springboot.controllers.app;
22

3+
import java.util.Optional;
4+
35
import com.github.throyer.common.springboot.domain.pagination.service.Pagination;
6+
import com.github.throyer.common.springboot.domain.toast.Toasts;
47
import com.github.throyer.common.springboot.domain.toast.Type;
58
import com.github.throyer.common.springboot.domain.user.repository.UserRepository;
6-
import com.github.throyer.common.springboot.domain.user.repository.custom.NativeQueryUserRepository;
79
import com.github.throyer.common.springboot.domain.user.service.RemoveUserService;
8-
import com.github.throyer.common.springboot.domain.toast.Toasts;
9-
import java.util.Optional;
10+
1011
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.security.access.prepost.PreAuthorize;
1213
import org.springframework.stereotype.Controller;

src/main/java/com/github/throyer/common/springboot/domain/management/repository/SoftDeleteRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.github.throyer.common.springboot.domain.management.repository;
22

3-
import com.github.throyer.common.springboot.domain.management.entity.Auditable;
43
import static com.github.throyer.common.springboot.domain.management.repository.Queries.DELETE_ALL;
54
import static com.github.throyer.common.springboot.domain.management.repository.Queries.DELETE_BY_ID;
65

6+
import com.github.throyer.common.springboot.domain.management.entity.Auditable;
7+
78
import org.springframework.data.jpa.repository.JpaRepository;
8-
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
99
import org.springframework.data.jpa.repository.Modifying;
1010
import org.springframework.data.jpa.repository.Query;
1111
import org.springframework.data.repository.NoRepositoryBean;

src/main/java/com/github/throyer/common/springboot/domain/recovery/model/RecoveryRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import javax.validation.constraints.Email;
44
import javax.validation.constraints.NotEmpty;
5-
import javax.validation.constraints.NotNull;
6-
import lombok.Data;
5+
76
import lombok.Getter;
87
import lombok.Setter;
98

src/main/java/com/github/throyer/common/springboot/domain/recovery/model/Update.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import javax.validation.constraints.Email;
77
import javax.validation.constraints.NotEmpty;
8-
import javax.validation.constraints.NotNull;
98
import javax.validation.constraints.Size;
9+
10+
import org.springframework.validation.BindingResult;
11+
1012
import lombok.Data;
1113
import lombok.NoArgsConstructor;
12-
import org.springframework.validation.BindingResult;
1314

1415
@Data
1516
@NoArgsConstructor
@@ -31,8 +32,9 @@ public class Update {
3132
public Update(Codes codes) {
3233
copyProperties(codes, this);
3334
}
34-
35-
public void validate(BindingResult result) { }
35+
36+
public void validate(BindingResult result) {
37+
}
3638

3739
public String code() {
3840
return format("%s%s%s%s", first, second, third, fourth);

src/main/java/com/github/throyer/common/springboot/domain/role/entity/Role.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.throyer.common.springboot.domain.role.entity;
22

3-
import com.github.throyer.common.springboot.domain.management.entity.Auditable;
3+
import static com.github.throyer.common.springboot.domain.management.repository.Queries.NON_DELETED_CLAUSE;
4+
45
import java.util.Objects;
56

67
import javax.persistence.Column;
@@ -11,13 +12,14 @@
1112
import javax.persistence.Table;
1213

1314
import com.fasterxml.jackson.annotation.JsonIgnore;
14-
import static com.github.throyer.common.springboot.domain.management.repository.Queries.NON_DELETED_CLAUSE;
15-
import lombok.Data;
15+
import com.github.throyer.common.springboot.domain.management.entity.Auditable;
1616

1717
import org.hibernate.annotations.Where;
1818
import org.springframework.security.core.GrantedAuthority;
1919

20-
@Data
20+
import lombok.Getter;
21+
22+
@Getter
2123
@Entity
2224
@Table(name = "role")
2325
@Where(clause = NON_DELETED_CLAUSE)
@@ -46,7 +48,8 @@ public class Role extends Auditable implements GrantedAuthority {
4648
@Column(nullable = true, unique = true)
4749
private String description;
4850

49-
public Role() { }
51+
public Role() {
52+
}
5053

5154
public Role(String initials) {
5255
this.initials = initials;
@@ -87,5 +90,5 @@ public String toString() {
8790
public String getAuthority() {
8891
return this.getInitials();
8992
}
90-
93+
9194
}

src/main/java/com/github/throyer/common/springboot/domain/user/model/UserDetails.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package com.github.throyer.common.springboot.domain.user.model;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
3+
import static java.util.Optional.ofNullable;
44

55
import java.util.ArrayList;
66
import java.util.List;
77

8+
import com.github.throyer.common.springboot.domain.management.model.Entity;
89
import com.github.throyer.common.springboot.domain.role.entity.Role;
910
import com.github.throyer.common.springboot.domain.user.entity.User;
10-
import com.github.throyer.common.springboot.domain.management.model.Entity;
11+
1112
import io.swagger.v3.oas.annotations.media.Schema;
1213
import lombok.Getter;
1314

14-
import static java.util.Optional.ofNullable;
15-
1615
@Getter
1716
@Schema(name = "User", requiredProperties = {"id", "name", "email", "roles"})
1817
public class UserDetails implements Entity {

0 commit comments

Comments
 (0)