org.shoulder.security.authentication.FormAuthenticationSecurityConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shoulder-security Show documentation
Show all versions of shoulder-security Show documentation
Shoulder 基础模块,基于 Spring Security + Spring Boot Web的安全模块,除了提供用户认证、授权、会话管理等基础功能,还允许轻松更换认证模式,如
Session / Token(JWT) 模式切换。
package org.shoulder.security.authentication;
import org.shoulder.security.SecurityConst;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
/**
* 用户名、密码认证(表单登录)配置
* 使用 spring security 默认提供的用户名密码认证
*
* @author lym
*/
public class FormAuthenticationSecurityConfig extends SecurityConfigurerAdapter {
protected AuthenticationSuccessHandler authenticationSuccessHandler;
protected AuthenticationFailureHandler authenticationFailureHandler;
public FormAuthenticationSecurityConfig(AuthenticationSuccessHandler authenticationSuccessHandler, AuthenticationFailureHandler authenticationFailureHandler) {
this.authenticationSuccessHandler = authenticationSuccessHandler;
this.authenticationFailureHandler = authenticationFailureHandler;
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.formLogin()
.loginPage(SecurityConst.URL_REQUIRE_AUTHENTICATION)
.loginProcessingUrl(SecurityConst.URL_AUTHENTICATION_FORM)
.successHandler(authenticationSuccessHandler)
.failureHandler(authenticationFailureHandler);
}
}