Skip to content

Commit b2c03fb

Browse files
committed
work
1 parent d58c5e9 commit b2c03fb

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,23 @@
33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
55
import org.springframework.boot.context.properties.EnableConfigurationProperties;
6-
import org.springframework.context.ApplicationContext;
76
import org.springframework.context.annotation.Bean;
87
import org.springframework.context.annotation.Configuration;
9-
import org.springframework.core.io.support.SpringFactoriesLoader;
108
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
119
import org.springframework.data.web.config.EnableSpringDataWebSupport;
1210
import org.springframework.scheduling.annotation.EnableAsync;
13-
import org.springframework.security.authentication.*;
11+
import org.springframework.security.authentication.AuthenticationProvider;
1412
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
15-
import org.springframework.security.config.annotation.ObjectPostProcessor;
16-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
17-
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
13+
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1814
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
19-
import org.springframework.security.config.annotation.web.builders.WebSecurity;
20-
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
2115
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
22-
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
23-
import org.springframework.security.config.annotation.web.configurers.DefaultLoginPageConfigurer;
2416
import org.springframework.security.core.userdetails.UserDetailsService;
2517
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
2618
import org.springframework.security.crypto.password.PasswordEncoder;
2719
import org.springframework.security.web.SecurityFilterChain;
28-
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
29-
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
30-
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
31-
import org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter;
32-
import org.springframework.web.accept.ContentNegotiationStrategy;
33-
import org.springframework.web.accept.HeaderContentNegotiationStrategy;
3420
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
35-
import org.woehlke.java.simpleworklist.domain.security.access.ApplicationUserDetailsService;
36-
37-
import java.util.HashMap;
38-
import java.util.List;
39-
import java.util.Map;
4021

22+
import org.woehlke.java.simpleworklist.domain.security.access.ApplicationUserDetailsService;
4123

4224
@Configuration
4325
@EnableAsync
@@ -51,6 +33,7 @@
5133
SimpleworklistProperties.class
5234
})
5335
@EnableWebSecurity
36+
@EnableMethodSecurity(securedEnabled = true)
5437
public class WebSecurityConfig /* extends WebSecurityConfigurerAdapter implements WebSecurityConfigurer<WebSecurity> */ {
5538

5639
//private final AuthenticationManagerBuilder authenticationManagerBuilder;
@@ -255,8 +238,9 @@ public void configure(HttpSecurity builder) throws Exception {
255238
256239
}
257240
*/
241+
258242
@Bean
259-
public DaoAuthenticationProvider authenticationProvider(){
243+
public AuthenticationProvider authenticationProvider(){
260244
DaoAuthenticationProvider d = new DaoAuthenticationProvider();
261245
d.setPasswordEncoder(encoder());
262246
d.setUserDetailsService(userDetailsService());
@@ -289,7 +273,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
289273
)
290274
.csrf()
291275
.and()
292-
.logout((logout)-> logout
276+
.logout((logout) -> logout
293277
.logoutUrl(simpleworklistProperties.getWebSecurity().getLogoutUrl())
294278
.deleteCookies(simpleworklistProperties.getWebSecurity().getCookieNamesToClear())
295279
.invalidateHttpSession(simpleworklistProperties.getWebSecurity().getInvalidateHttpSession())

src/main/java/org/woehlke/java/simpleworklist/domain/UserSelfserviceController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public String userPasswordStore(
188188
return "user/selfservice/password";
189189
}
190190
if(!userAuthorizationService.confirmUserByLoginAndPassword(
191-
user.getUserEmail(), userChangePasswordForm.getOldUserPassword())
191+
user.getUserEmail(),
192+
userChangePasswordForm.getOldUserPassword())
192193
){
193194
log.info("old Password is wrong");
194195
String objectName = "userChangePasswordForm";

src/main/java/org/woehlke/java/simpleworklist/domain/db/user/accountpassword/UserAccountPasswordServiceImpl.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.security.authentication.AuthenticationManager;
6+
import org.springframework.security.authentication.AuthenticationProvider;
67
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
78
import org.springframework.security.core.Authentication;
89
import org.springframework.security.core.userdetails.UserDetails;
@@ -22,20 +23,26 @@ public class UserAccountPasswordServiceImpl implements UserAccountPasswordServic
2223

2324
private final UserAccountRepository userAccountRepository;
2425
private final PasswordEncoder encoder;
25-
private final AuthenticationManager authenticationManager;
26+
//private final AuthenticationManager authenticationManager;
27+
private final AuthenticationProvider authenticationProvider;
2628

2729
@Autowired
28-
public UserAccountPasswordServiceImpl(UserAccountRepository userAccountRepository, AuthenticationManager authenticationManager) {
30+
public UserAccountPasswordServiceImpl(
31+
UserAccountRepository userAccountRepository,
32+
//AuthenticationManager authenticationManager,
33+
AuthenticationProvider authenticationProvider
34+
) {
2935
this.userAccountRepository = userAccountRepository;
36+
this.authenticationProvider = authenticationProvider;
3037
int strength = 10;
3138
this.encoder = new BCryptPasswordEncoder(strength);
32-
this.authenticationManager = authenticationManager;
39+
//this.authenticationManager = authenticationManager;
3340
}
3441

3542
@Override
3643
public UserDetails updatePassword(UserDetails user, String newPassword) {
3744
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword());
38-
Authentication authenticationResult = authenticationManager.authenticate(token);
45+
Authentication authenticationResult = authenticationProvider.authenticate(token);
3946
if (authenticationResult.isAuthenticated()) {
4047
UserAccount ua = userAccountRepository.findByUserEmail(user.getUsername());
4148
String pwEncoded = encoder.encode(newPassword);

src/main/java/org/woehlke/java/simpleworklist/domain/security/access/UserAuthorizationServiceImpl.java

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

33
import lombok.extern.slf4j.Slf4j;
44
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.security.authentication.AuthenticationManager;
5+
//import org.springframework.security.authentication.AuthenticationManager;
6+
import org.springframework.security.authentication.AuthenticationProvider;
67
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
78
import org.springframework.security.core.Authentication;
89
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@@ -21,16 +22,18 @@
2122
public class UserAuthorizationServiceImpl implements UserAuthorizationService {
2223

2324
private final UserAccountRepository userAccountRepository;
24-
private final AuthenticationManager authenticationManager;
25+
//private final AuthenticationManager authenticationManager;
26+
private final AuthenticationProvider authenticationProvider;
2527
private final PasswordEncoder encoder;
2628

2729
@Autowired
2830
public UserAuthorizationServiceImpl(
2931
UserAccountRepository userAccountRepository,
30-
AuthenticationManager authenticationManager
31-
) {
32+
//AuthenticationManager authenticationManager
33+
AuthenticationProvider authenticationProvider) {
3234
this.userAccountRepository = userAccountRepository;
33-
this.authenticationManager = authenticationManager;
35+
this.authenticationProvider = authenticationProvider;
36+
//this.authenticationManager = authenticationManager;
3437
int strength = 10;
3538
this.encoder = new BCryptPasswordEncoder(strength);
3639
}
@@ -46,7 +49,7 @@ public void changeUsersPassword(
4649
user.getUserEmail(),
4750
userAccountFormBean.getOldUserPassword()
4851
);
49-
Authentication authenticationResult = authenticationManager.authenticate(token);
52+
Authentication authenticationResult = authenticationProvider.authenticate(token);
5053
if(authenticationResult.isAuthenticated()){
5154
UserAccount ua = userAccountRepository.findByUserEmail(user.getUserEmail());
5255
String pwEncoded = this.encoder.encode(userAccountFormBean.getUserPassword());
@@ -64,7 +67,7 @@ public boolean confirmUserByLoginAndPassword(
6467
userEmail,
6568
oldUserPassword
6669
);
67-
Authentication authenticationResult = authenticationManager.authenticate(token);
70+
Authentication authenticationResult = authenticationProvider.authenticate(token);
6871
String oldPwEncoded = this.encoder.encode(oldUserPassword);
6972
log.info(userEmail+", "+oldPwEncoded);
7073
return authenticationResult.isAuthenticated();

0 commit comments

Comments
 (0)