huanghongfa
2021-02-01 b3c6911c1e78563dc04998dd7bfb510130a9fcec
springcloud_k8s_panzhihuazhihuishequ/auth/src/main/java/com/panzhihua/auth/config/SecurityConfig.java
@@ -1,11 +1,9 @@
package com.panzhihua.auth.config;
import com.panzhihua.auth.handel.UserAuthenticationProvider;
import com.panzhihua.auth.handel.UserLoginFailureHandler;
import com.panzhihua.auth.handel.UserLoginSuccessHandler;
import com.panzhihua.auth.handel.UserLogoutSuccessHandler;
import com.panzhihua.auth.handel.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -20,6 +18,7 @@
 * SpringSecurity配置类
 * @Author youcong
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    /**
@@ -27,6 +26,8 @@
     */
    @Resource
    private UserAuthenticationProvider userAuthenticationProvider;
    /**
     * 加密方式
@@ -72,7 +73,7 @@
                .and()
                // 配置登录成功自定义处理类
                .formLogin()
                .successHandler(new UserLoginSuccessHandler())
//                .successHandler(new UserLoginSuccessHandler())
                // 配置登录失败自定义处理类
                .failureHandler(new UserLoginFailureHandler())
                .and()
@@ -84,6 +85,9 @@
                .and()
                // 开启跨域
                .cors()
                //异常处理(权限拒绝、登录失效等)
                .and().exceptionHandling()
                .authenticationEntryPoint(new AjaxAuthenticationEntryPoint())//匿名用户访问无权限资源时的异常处理;
                .and()
                // 取消跨站请求伪造防护
                .csrf().disable();