我具有以下SpringBoot Web安全配置。对于授权,我想自动禁止所有请求该认证不包括角色ADMIN
,SUPER_ADMIN
,CUSTOMER
但这种拒绝所有的请求,因此只挑选了denyAll
在springExprFilter因此它投票拒绝访问属性。
我的配置中缺少什么?
@EnableWebSecurity
@RequiredArgsConstructor
@EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private final MemberDetailsService memberDetailsService;
private final JwtRequestFilter jwtRequestFilter;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(memberDetailsService).passwordEncoder(getPasswordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers()
.disable()
.csrf()
.disable()
.authorizeRequests()
// permit all request for authentication
.antMatchers("/v1/authenticate")
.permitAll()
.and()
.authorizeRequests()
// permit all request with the following list of roles
// methods will enforce their own authorization logic
.antMatchers("/v1/members/")
.hasAnyAuthority("ADMIN", "CUSTOMER", "SUPER_ADMIN")
.and()
.authorizeRequests()
.anyRequest()
.denyAll()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
我发现spring安全配置表达式是正确的。问题是,antmatcher.antMatchers("/v1/members/")
不正确。这意味着将请求与/v1/members/
不是预期功能的路径进行匹配。
对于任何有兴趣的人士,我的要求是GET v1/members/:uuid
。
我应该使用通配符.antMatchers("/v1/members/**")
来捕获对成员端点的所有请求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句