![](/img/trans.png)
[英]Configuring resource server with RemoteTokenServices in Spring Security Oauth2
[英]Spring Oauth2 RemoteTokenServices error on extractAuthentication
我有一個資源服務器和一個身份驗證服務器。
在資源請求時,它通過/oauth/check_token
端點上的auth服務器驗證收到的access_token。 這給出了使我的請求崩潰的響應。
響應發送為:
Written [{exp=1433335640, scope=[read, write], authorities=[ROLE_USER], client_id=client-w-s}] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@58a88f5a]
當我的資源服務器收到它時:
2015-06-03 14:17:48.277 DEBUG 9492 --- [nio-8181-exec-3] o.s.web.client.RestTemplate : POST request for "http://localhost:6707/oauth/check_token" resulted in 200 (OK)
2015-06-03 14:17:48.277 DEBUG 9492 --- [nio-8181-exec-3] o.s.web.client.RestTemplate : Reading [interface java.util.Map] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@67409450]
2015-06-03 14:17:48.283 ERROR 9492 --- [nio-8181-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
java.lang.ArrayStoreException: null
at java.util.ArrayList.toArray(Unknown Source)
at org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter.extractAuthentication(DefaultAccessTokenConverter.java:139)
這是一段失敗的代碼:
Collection<? extends GrantedAuthority> authorities = null;
if (user==null && map.containsKey(AUTHORITIES)) {
@SuppressWarnings("unchecked")
String[] roles = ((Collection<String>)map.get(AUTHORITIES)).toArray(new String[0]);
authorities = AuthorityUtils.createAuthorityList(roles);
}
我在調試模式下運行以檢查map
的值,並且一切似乎都應該從我的身份驗證服務器構建的響應中判斷出來。
請告訴我是否需要發布更多信息。
有沒有人遇到過這種情況或對解決方法有任何線索?
我找到了“解決方案”。
我的pom文件中存在版本不匹配的情況。 當我的身份驗證服務器運行spring-security-oauth2-2.0.5.RELEASE
我的資源服務器正在運行spring-security-oauth2-2.0.7.RELEASE
。
版本對響應的聲明不同。
我認為從spring-security-oauth2 2.0.7.RELEASE開始,DefaultAccessTokenConverter實現中存在錯誤,因為此行:
如果( user == null && map.containsKey(AUTHORITIES)){...}
為什么使用“ user == null ”條件? “用戶”變量不為null,因此條件永遠不會為真,並且不會填充Authority數組。
我認為這是Spring Security Oauth2實現錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.