簡體   English   中英

在 Spring-Security-Oauth2 中無需 access_token 即可訪問受保護資源

[英]Protected resource being access without access_token in Spring-Security-Oauth2

在我的應用程序中,我實現了 spring-security-oauth2。 除了一種情況外,一切都很好。

場景是,我登錄系統,我得到 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 過濾器。 我使用這樣的身份驗證對象在我的過濾器中打印 client_id -

 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
   System.out.println("----------->>>" + ((OAuth2Authentication) authentication).getAuthorizationRequest().getClientId());

使用 access_token 我得到 client_id-"test1" 並且在第一次請求之后,如果我在沒有 access_token 的情況下執行相同的請求,我再次得到相同的 client_id="test1"

並且資源也被訪問。

我努力嘗試,但代碼中沒有任何漏洞。 任何幫助將不勝感激。

這對我有用:

create-session = "never"更改為create-session = "stateless"

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM