【发布时间】:2019-09-19 14:15:12
【问题描述】:
我正在使用 Spring 和 tutorial 构建 Oauth 服务器。
在资源服务器实施期间,我注意到令牌密钥端点 (/oauth/token_key) 不是公开的。
基于this doc,我尝试将以下内容添加到 AuthorizationServerConfigurerAdapter:
security.tokenKeyAccess("permitAll()")
.checkTokenAccess("hasAuthority('ROLE_TRUSTED_CLIENT')");
还有:
security.tokenKeyAccess("isAnonymous() || hasAuthority('ROLE_TRUSTED_CLIENT')")
.checkTokenAccess("hasAuthority('ROLE_TRUSTED_CLIENT')");
两种配置均无效。我还尝试在我的 WebSecurityAdapter 上添加规则:
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/oauth/token_key").permitAll();
}
现在我会看到一个对话框,询问登录名和密码,当我点击取消时,我会收到以下信息:
There was an unexpected error (type=Unauthorized, status=401).
Unauthorized
org.springframework.security.access.AccessDeniedException: You need to authenticate to see a shared key
at org.springframework.security.oauth2.provider.endpoint.TokenKeyEndpoint.getKey(TokenKeyEndpoint.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
(...)
我错过了什么吗?
【问题讨论】:
标签: spring-security oauth-2.0 spring-oauth2