Skip to content

Commit 58089e0

Browse files
committed
Fixed #103, Fixed #102
1 parent 2d8c0ee commit 58089e0

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

src/main/java/org/woehlke/simpleworklist/config/di/WebSecurityConfig.java

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,44 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
4141
private final AuthenticationManagerBuilder authenticationManagerBuilder;
4242
private final AuthenticationSuccessHandler loginSuccessHandler;
4343
private final UserAccountSecurityService userAccountSecurityService;
44+
private final ApplicationProperties applicationProperties;
4445

4546
@Autowired
4647
public WebSecurityConfig(
4748
AuthenticationManagerBuilder authenticationManagerBuilder,
4849
LoginSuccessHandler loginSuccessHandler,
49-
UserAccountSecurityService userAccountSecurityService
50-
) {
50+
UserAccountSecurityService userAccountSecurityService,
51+
ApplicationProperties applicationProperties) {
5152
this.authenticationManagerBuilder = authenticationManagerBuilder;
5253
this.loginSuccessHandler = loginSuccessHandler;
5354
this.userAccountSecurityService = userAccountSecurityService;
55+
this.applicationProperties = applicationProperties;
5456
}
5557

5658
@Override
5759
protected void configure(HttpSecurity http) throws Exception {
5860
http
5961
.headers().disable()
6062
.authorizeRequests()
61-
.antMatchers(antPatternsPublic)
63+
.antMatchers(applicationProperties.getWebSecurity().getAntPatternsPublic())
6264
.permitAll()
6365
.anyRequest()
6466
.fullyAuthenticated()
6567
.and()
6668
.formLogin()
67-
.loginPage(loginPage)
68-
.usernameParameter(usernameParameter).passwordParameter(passwordParameter)
69-
.loginProcessingUrl(loginProcessingUrl)
70-
.failureForwardUrl(failureForwardUrl)
71-
.defaultSuccessUrl(defaultSuccessUrl)
69+
.loginPage(applicationProperties.getWebSecurity().getLoginPage())
70+
.usernameParameter(applicationProperties.getWebSecurity().getUsernameParameter())
71+
.passwordParameter(applicationProperties.getWebSecurity().getPasswordParameter())
72+
.loginProcessingUrl(applicationProperties.getWebSecurity().getLoginProcessingUrl())
73+
.failureForwardUrl(applicationProperties.getWebSecurity().getFailureForwardUrl())
74+
.defaultSuccessUrl(applicationProperties.getWebSecurity().getDefaultSuccessUrl())
7275
.successHandler(loginSuccessHandler)
7376
.permitAll()
7477
.and()
7578
.logout()
76-
.logoutUrl(logoutUrl)
77-
.deleteCookies(cookieNamesToClear)
78-
.invalidateHttpSession(invalidateHttpSession)
79+
.logoutUrl(applicationProperties.getWebSecurity().getLogoutUrl())
80+
.deleteCookies(applicationProperties.getWebSecurity().getCookieNamesToClear())
81+
.invalidateHttpSession(applicationProperties.getWebSecurity().getInvalidateHttpSession())
7982
.permitAll()
8083
.and()
8184
.csrf()
@@ -84,30 +87,14 @@ protected void configure(HttpSecurity http) throws Exception {
8487
.accessDeniedPage("/error/error-403");
8588
}
8689

87-
private final static String loginProcessingUrl = "/j_spring_security_check";
88-
private final static String logoutUrl = "/logout";
89-
private final static String[] cookieNamesToClear = {"JSESSIONID"};
90-
private final static boolean invalidateHttpSession = true;
91-
private final static String defaultSuccessUrl = "/";
92-
private final static String failureForwardUrl = "/login?login_error=1";
93-
private final static String usernameParameter = "j_username";
94-
private final static String passwordParameter = "j_password";
95-
private final static String loginPage = "/login";
96-
private final static String[] antPatternsPublic = {
97-
"/webjars/**", "/css/**", "/img/**", "/js/**", "/favicon.ico",
98-
"/test*/**", "/login*", "/register*", "/confirm*/**",
99-
"/resetPassword*", "/passwordResetConfirm*/**", "/error*"
100-
};
101-
private final static int strengthBCryptPasswordEncoder = 10;
102-
10390
@Bean
10491
public UserDetailsService userDetailsService(){
10592
return this.userAccountSecurityService;
10693
}
10794

10895
@Bean
10996
public PasswordEncoder encoder(){
110-
int strength = strengthBCryptPasswordEncoder;
97+
int strength = applicationProperties.getWebSecurity().getStrengthBCryptPasswordEncoder();
11198
return new BCryptPasswordEncoder(strength);
11299
}
113100

@@ -122,7 +109,7 @@ public AuthenticationManager authenticationManager() throws Exception {
122109
public UsernamePasswordAuthenticationFilter authenticationFilter() throws Exception {
123110
UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter();
124111
filter.setAuthenticationManager(authenticationManager());
125-
filter.setFilterProcessesUrl(loginProcessingUrl);
112+
filter.setFilterProcessesUrl(applicationProperties.getWebSecurity().getLoginProcessingUrl());
126113
return filter;
127114
}
128115
}

0 commit comments

Comments
 (0)