1
在我的應用程序中,我實現了spring-security-oauth2。除了一種情況,evrything工作正常。受保護的資源在Spring-Security-Oauth2中無access_token訪問
情景是,我登錄系統,我得到oauth2 access_token。我通過提供該令牌請求受保護的資源,我得到結果。我再次做同樣的請求沒有任何頭(沒有access_token),這次我也得到了受保護的資源。
我保護的資源相關的代碼:
<http pattern="/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="true" />
<intercept-url pattern="/users" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />
<custom-filter ref="customFilter" position="FORM_LOGIN_FILTER"/>
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
而且我已經使用CUSTM過濾器。我打印使用認證對象喜歡這 -
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
System.out.println("----------->>>" + ((OAuth2Authentication) authentication).getAuthorizationRequest().getClientId());
隨着我的access_token得到client_id-「測試1」和 第一次請求之後,如果我沒有做我的access_token再次得到相同的CLIENT_ID同樣的請求CLIENT_ID在我的過濾器= 「test1」
並且還訪問資源。
我努力了,但沒有在代碼中出現任何循環漏洞。 任何幫助將不勝感激。
我試過了。但對我來說這不起作用 – Anita