@Preauthrize
和@Secured
注释无法在 Spring Oauth 中工作(我提到的所有示例都是针对 Spring 的基本安全性而不是Oauth协议):
我所做的是:
答案 0 :(得分:0)
添加
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
到您的某个配置。我已添加到我的Resource Server配置
@Configuration
@EnableResourceServer
@Order(2)
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId("Sample");
}
@Override
public void configure(HttpSecurity http) throws Exception {
//restrict access using @Secured or @PreAuthorize annotation
http.authorizeRequests().anyRequest().permitAll();
}
}
完美无缺地工作