【发布时间】:2020-02-21 12:51:57
【问题描述】:
我已经设置了一个 OAUTH 授权服务器,它应该允许客户端请求令牌。它还应该允许管理员用户执行其他操作。
在我的网络安全配置中:
@Configuration
@EnableWebSecurity
public class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
private @Autowired CustomAuthenticationProvider authenticationProvider;
private @Autowired CustomAuthenticationEntryPoint entryPoint;
@Override
@Bean
protected AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().httpBasic().and().cors().and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/oauth/token").permitAll()
.anyRequest()
.authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(entryPoint)
.defaultAuthenticationEntryPointFor(entryPoint, new AntPathRequestMatcher("/api/v1/**"));
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider);
}
}
理想情况下,当管理员用户尝试调用“/api/v1/**”下的任何端点时,他们应该经过身份验证 - 事实上,他们是。
现在的问题是,当身份验证失败时,身份验证条目端点将被忽略。我不明白这是为什么。
我什至包括了“默认身份验证入口点”,只是为了看看这是否有帮助,但它没有。
请问,我该如何解决?
【问题讨论】:
标签: spring-boot spring-security oauth-2.0