【发布时间】:2020-06-29 12:17:38
【问题描述】:
我正在开发一个spring-boot应用,它的spring安全配置如下:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.antMatchers("/actuator/**", "/login*", "/logout*")
.permitAll();
httpSecurity
.cors().and()
.csrf().disable()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/taas/v1/**").hasRole("admin")
.antMatchers("/taas/v1/teams", "/taas/v1/profiles", "/taas/v1/tests/summary").hasRole("tester")
.antMatchers( "/taas/v1/teams", "/taas/v1/tests/summary").hasRole("user")
.anyRequest().authenticated()
.and()
.exceptionHandling().accessDeniedHandler(customAccessDeniedHandler)
.and()
.httpBasic()
.and()
.formLogin()
.successHandler(customAuthenticationSuccessHandler)
.failureHandler(customAuthenticationFailureHandler)
.and()
.logout()
.logoutSuccessHandler(customLogoutSuccessHandler())
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID");
}
}
即使我已经为每个角色设置了 url 模式。所有用户都可以访问 antMatchers() 中提到的所有端点。角色为user 的用户不应访问/taas/v1/profiles。但是当我尝试通过以user 登录来访问该端点时,我收到了响应,但预期的响应是403 forbidden。
我请求某人为我提供解决方法。
【问题讨论】:
-
你使用@EnableWebSecurity注解了吗?
-
@ShababbKarim 是的
-
@ShababbKarim 我试过不行
标签: spring spring-boot spring-security