|
@@ -1,94 +1,94 @@
|
|
|
-package com.bizmatics.service.config.security;
|
|
|
-
|
|
|
-import com.bizmatics.service.config.security.handler.*;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
-import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
|
|
|
-
|
|
|
-/**
|
|
|
- * spring Security配置安全控制中心
|
|
|
- *
|
|
|
- * @author zhoukb
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-@EnableWebSecurity
|
|
|
-@EnableGlobalMethodSecurity(prePostEnabled = true)
|
|
|
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
- /**
|
|
|
- * 依赖注入自定义的登录成功处理器
|
|
|
- */
|
|
|
- @Autowired
|
|
|
- private FuryAuthSuccessHandler furyAuthSuccessHandler;
|
|
|
- /**
|
|
|
- * 依赖注入自定义的登录失败处理器
|
|
|
- */
|
|
|
- @Autowired
|
|
|
- private FuryAuthFailureHandler furyAuthFailureHandler;
|
|
|
- /**
|
|
|
- * 依赖注入自定义的注销成功的处理器
|
|
|
- */
|
|
|
- @Autowired
|
|
|
- private MyLogoutSuccessHandler myLogoutSuccessHandler;
|
|
|
- @Autowired
|
|
|
- private AnonymousAuthenticationEntryPoint anonymousAuthenticationEntryPoint;
|
|
|
-
|
|
|
- /**
|
|
|
- * 注册没有权限的处理器
|
|
|
- */
|
|
|
- @Autowired
|
|
|
- private RestAuthAccessDeniedHandler restAuthAccessDeniedHandler;
|
|
|
-
|
|
|
- /***注入自定义的CustomPermissionEvaluator*/
|
|
|
- @Bean
|
|
|
- public DefaultWebSecurityExpressionHandler webSecurityExpressionHandler() {
|
|
|
- DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
|
|
|
- handler.setPermissionEvaluator(new CustomPermissionEvaluator());
|
|
|
- return handler;
|
|
|
- }
|
|
|
-
|
|
|
- /***注入我们自己的登录逻辑验证器AuthenticationProvider*/
|
|
|
- @Autowired
|
|
|
- private AuthenticationProvider authenticationProvider;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
- //这里可启用我们自己的登陆验证逻辑
|
|
|
- auth.authenticationProvider(authenticationProvider);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 配置spring security的控制逻辑
|
|
|
- */
|
|
|
- @Override
|
|
|
- protected void configure(HttpSecurity http) throws Exception {
|
|
|
- http.cors().and().csrf().disable();
|
|
|
- http.authorizeRequests()
|
|
|
- // 放行接口
|
|
|
- .antMatchers("/login","/user/register").permitAll()
|
|
|
- // 除上面外的所有请求全部需要鉴权认证
|
|
|
- .anyRequest().authenticated()
|
|
|
- .and()
|
|
|
- .formLogin()
|
|
|
- //loginProcessingUrl用于指定前后端分离的时候调用后台登录接口的名称
|
|
|
- .loginProcessingUrl("/login")
|
|
|
- // 异常处理(权限拒绝、登录失效等)
|
|
|
- .and().exceptionHandling()
|
|
|
- .authenticationEntryPoint(anonymousAuthenticationEntryPoint)//匿名用户访问无权限资源时的异常处理
|
|
|
- .accessDeniedHandler(restAuthAccessDeniedHandler)//登录用户没有权限访问资源
|
|
|
- // 登入
|
|
|
- .and().formLogin().permitAll()
|
|
|
- .successHandler(furyAuthSuccessHandler)
|
|
|
- .failureHandler(furyAuthFailureHandler)
|
|
|
- // 登出
|
|
|
- .and().logout().permitAll()//允许所有用户
|
|
|
- .logoutSuccessHandler(myLogoutSuccessHandler);
|
|
|
-
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.bizmatics.service.config.security;
|
|
|
+//
|
|
|
+//import com.bizmatics.service.config.security.handler.*;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.context.annotation.Bean;
|
|
|
+//import org.springframework.context.annotation.Configuration;
|
|
|
+//import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
+//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
+//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
+//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
+//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
|
+//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
+//import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * spring Security配置安全控制中心
|
|
|
+// *
|
|
|
+// * @author zhoukb
|
|
|
+// */
|
|
|
+//@Configuration
|
|
|
+//@EnableWebSecurity
|
|
|
+//@EnableGlobalMethodSecurity(prePostEnabled = true)
|
|
|
+//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
+// /**
|
|
|
+// * 依赖注入自定义的登录成功处理器
|
|
|
+// */
|
|
|
+// @Autowired
|
|
|
+// private FuryAuthSuccessHandler furyAuthSuccessHandler;
|
|
|
+// /**
|
|
|
+// * 依赖注入自定义的登录失败处理器
|
|
|
+// */
|
|
|
+// @Autowired
|
|
|
+// private FuryAuthFailureHandler furyAuthFailureHandler;
|
|
|
+// /**
|
|
|
+// * 依赖注入自定义的注销成功的处理器
|
|
|
+// */
|
|
|
+// @Autowired
|
|
|
+// private MyLogoutSuccessHandler myLogoutSuccessHandler;
|
|
|
+// @Autowired
|
|
|
+// private AnonymousAuthenticationEntryPoint anonymousAuthenticationEntryPoint;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 注册没有权限的处理器
|
|
|
+// */
|
|
|
+// @Autowired
|
|
|
+// private RestAuthAccessDeniedHandler restAuthAccessDeniedHandler;
|
|
|
+//
|
|
|
+// /***注入自定义的CustomPermissionEvaluator*/
|
|
|
+// @Bean
|
|
|
+// public DefaultWebSecurityExpressionHandler webSecurityExpressionHandler() {
|
|
|
+// DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
|
|
|
+// handler.setPermissionEvaluator(new CustomPermissionEvaluator());
|
|
|
+// return handler;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /***注入我们自己的登录逻辑验证器AuthenticationProvider*/
|
|
|
+// @Autowired
|
|
|
+// private AuthenticationProvider authenticationProvider;
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
+// //这里可启用我们自己的登陆验证逻辑
|
|
|
+// auth.authenticationProvider(authenticationProvider);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 配置spring security的控制逻辑
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// protected void configure(HttpSecurity http) throws Exception {
|
|
|
+// http.cors().and().csrf().disable();
|
|
|
+// http.authorizeRequests()
|
|
|
+// // 放行接口
|
|
|
+// .antMatchers("/login","/user/register").permitAll()
|
|
|
+// // 除上面外的所有请求全部需要鉴权认证
|
|
|
+// .anyRequest().authenticated()
|
|
|
+// .and()
|
|
|
+// .formLogin()
|
|
|
+// //loginProcessingUrl用于指定前后端分离的时候调用后台登录接口的名称
|
|
|
+// .loginProcessingUrl("/login")
|
|
|
+// // 异常处理(权限拒绝、登录失效等)
|
|
|
+// .and().exceptionHandling()
|
|
|
+// .authenticationEntryPoint(anonymousAuthenticationEntryPoint)//匿名用户访问无权限资源时的异常处理
|
|
|
+// .accessDeniedHandler(restAuthAccessDeniedHandler)//登录用户没有权限访问资源
|
|
|
+// // 登入
|
|
|
+// .and().formLogin().permitAll()
|
|
|
+// .successHandler(furyAuthSuccessHandler)
|
|
|
+// .failureHandler(furyAuthFailureHandler)
|
|
|
+// // 登出
|
|
|
+// .and().logout().permitAll()//允许所有用户
|
|
|
+// .logoutSuccessHandler(myLogoutSuccessHandler);
|
|
|
+//
|
|
|
+// }
|
|
|
+//}
|