2015-07-21 86 views
0

我已經在應用程序中實現了spring-security-oauth2,並付出了很多努力。 一切工作正常。該資源僅被授權令牌訪問。 但是,當我嘗試使用授權標頭訪問不安全的資源時,它會驗證訪問令牌。訪問不安全資源時訪問令牌無效oauth2

如果訪問令牌有效,那麼它的工作權限,但如果訪問令牌無效,它會顯示錯誤Invalid access_token

回答

1

Spring安全攔截每個請求並檢查access_token的有效性,除非顯式用戶指定允許訪問URl。如果你想不攔截URL模式和檢查認證 一樣,那麼代碼會像

<http ...> 
    <intercept-url pattern="/app/**" access="IS_AUTHENTICATED_FULLY" /> 
    <intercept-url pattern="/oauth2/resource/**" access="ROLE_USER" /> 
</http> 

但是,如果你要訪問的資源,沒有任何安全的,你可以做這樣的事情:

<http pattern="/resources/**" security="none"/> 

希望能夠解決您的問題

1

您必須在OAuth配置文件中配置HTTP模式。檢查您是否使用'*'配置網址

<http pattern="/detail/**" create-session="never" 
     entry-point-ref="oauthAuthenticationEntryPoint" 
     xmlns="http://www.springframework.org/schema/security"> 
     <anonymous enabled="false" /> 
     <!-- intercept-url pattern --> 
     <intercept-url pattern="/detail/**" access="IS_AUTHENTICATED_FULLY" /> 
     <custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" /> 
     <access-denied-handler ref="oauthAccessDeniedHandler" /> 
    </http> 

例如,在上述配置中,我已經使所有啓動「詳細信息」的API受到保護。您也可能在不知不覺中/無意中使API獲得保護。確保你沒有!