簡體   English   中英

春季安全許可證全部需要授權標頭

[英]Spring security permitAll requires Authorization header

我有一個具有兩個REST端點的應用程序:

  • GET / api / products(不安全)
  • POST / api / products(安全)

對於第一個端點,我不想發送“授權”標頭。 為此,我配置以下xml:

<security:intercept-url pattern="/api/products" method="GET" access="permitAll"/>

對於第二個端點,我確實想發送“授權”標頭。 因此,我配置此xml:

<security:intercept-url pattern="/api/products" method="POST" access="hasRole('ROLE_ADMIN')"/>

令我驚訝的是,GET / api / products需要一個“ Authorization”標頭,它返回401。POST / api / products的工作原理非常好。 我只是發送了帶有有效值的“授權”標頭,一切正常。

我意識到將<security:intercept-url>與access =“ permitAll”結合使用不會禁用對“ Authorization”標頭的需求,這是正確的嗎? 如果是這樣,我可以設置哪種配置來實現我的目標?

我正在使用Spring Security 4

您應該只刪除<security:intercept-url pattern="/api/products" method="GET" access="permitAll"/>並且不為/api/products GET資源指定任何安全配置。

暫無
暫無

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

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