|
|
@ -13,8 +13,10 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
|
|
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
|
|
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
|
|
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
|
|
|
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
|
|
|
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
|
|
|
|
|
|
|
import ru.ulstu.core.model.RestAuthenticationFailureHandler;
|
|
|
|
import ru.ulstu.user.controller.UserController;
|
|
|
|
import ru.ulstu.user.controller.UserController;
|
|
|
|
import ru.ulstu.user.model.UserRoleConstants;
|
|
|
|
import ru.ulstu.user.model.UserRoleConstants;
|
|
|
|
import ru.ulstu.user.service.UserService;
|
|
|
|
import ru.ulstu.user.service.UserService;
|
|
|
@ -35,17 +37,20 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|
|
|
private final AuthenticationSuccessHandler authenticationSuccessHandler;
|
|
|
|
private final AuthenticationSuccessHandler authenticationSuccessHandler;
|
|
|
|
private final LogoutSuccessHandler logoutSuccessHandler;
|
|
|
|
private final LogoutSuccessHandler logoutSuccessHandler;
|
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
|
|
|
|
private final AuthenticationFailureHandler authenticationFailureHandler;
|
|
|
|
|
|
|
|
|
|
|
|
public SecurityConfiguration(UserService userService,
|
|
|
|
public SecurityConfiguration(UserService userService,
|
|
|
|
BCryptPasswordEncoder bCryptPasswordEncoder,
|
|
|
|
BCryptPasswordEncoder bCryptPasswordEncoder,
|
|
|
|
AuthenticationSuccessHandler authenticationSuccessHandler,
|
|
|
|
AuthenticationSuccessHandler authenticationSuccessHandler,
|
|
|
|
LogoutSuccessHandler logoutSuccessHandler,
|
|
|
|
LogoutSuccessHandler logoutSuccessHandler,
|
|
|
|
ApplicationProperties applicationProperties) {
|
|
|
|
ApplicationProperties applicationProperties,
|
|
|
|
|
|
|
|
RestAuthenticationFailureHandler authenticationFailureHandler) {
|
|
|
|
this.userService = userService;
|
|
|
|
this.userService = userService;
|
|
|
|
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
|
|
|
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
|
|
|
this.authenticationSuccessHandler = authenticationSuccessHandler;
|
|
|
|
this.authenticationSuccessHandler = authenticationSuccessHandler;
|
|
|
|
this.logoutSuccessHandler = logoutSuccessHandler;
|
|
|
|
this.logoutSuccessHandler = logoutSuccessHandler;
|
|
|
|
this.applicationProperties = applicationProperties;
|
|
|
|
this.applicationProperties = applicationProperties;
|
|
|
|
|
|
|
|
this.authenticationFailureHandler = authenticationFailureHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -76,6 +81,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|
|
|
.formLogin()
|
|
|
|
.formLogin()
|
|
|
|
.loginPage("/login")
|
|
|
|
.loginPage("/login")
|
|
|
|
.successHandler(authenticationSuccessHandler)
|
|
|
|
.successHandler(authenticationSuccessHandler)
|
|
|
|
|
|
|
|
.failureHandler(authenticationFailureHandler)
|
|
|
|
.permitAll()
|
|
|
|
.permitAll()
|
|
|
|
.and()
|
|
|
|
.and()
|
|
|
|
.logout()
|
|
|
|
.logout()
|
|
|
|