This commit is contained in:
2022-08-29 10:59:44 +08:00
committed by GitHub
parent d024e2ce19
commit f4bc489bb6
@@ -18,15 +18,16 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
* prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..] * prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..]
* secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用 * secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用
* jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用. * jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用.
* 开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
*/ */
@Configurable @Configurable
@EnableWebSecurity @EnableWebSecurity
//开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
private CustomAccessDeniedHandler customAccessDeniedHandler; private CustomAccessDeniedHandler customAccessDeniedHandler;
@Qualifier("userDetailServiceImpl") @Qualifier("userDetailServiceImpl")
@Autowired @Autowired
private UserDetailsService userDetailsService; private UserDetailsService userDetailsService;
@@ -61,13 +62,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/login/**", "/initUserData")//不拦截登录相关方法 .antMatchers("/login/**", "/initUserData")//不拦截登录相关方法
.permitAll() .permitAll()
//.antMatchers("/user").hasRole("ADMIN") // user接口只有ADMIN角色的可以访问 //.antMatchers("/user").hasRole("ADMIN") // user接口只有ADMIN角色的可以访问
// .anyRequest() //.anyRequest()
// .authenticated()// 任何尚未匹配的URL只需要验证用户即可访问 //.authenticated()// 任何尚未匹配的URL只需要验证用户即可访问
.anyRequest() .anyRequest()
.access("@rbacPermission.hasPermission(request, authentication)")//根据账号权限访问 .access("@rbacPermission.hasPermission(request, authentication)")//根据账号权限访问
.and() .and()
.formLogin() .formLogin()
// .loginPage("/") //.loginPage("/")
.loginPage("/login") //登录请求页 .loginPage("/login") //登录请求页
.loginProcessingUrl("/login") //登录POST请求路径 .loginProcessingUrl("/login") //登录POST请求路径
.usernameParameter("username") //登录用户名参数 .usernameParameter("username") //登录用户名参数
@@ -92,7 +93,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/** /**
* 密码加密算法 * 密码加密算法
*
* @return * @return
*/ */
@Bean @Bean
@@ -100,4 +100,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }
} }