[英]Spring Security Oauth2 generating jsessiond even when create-session=“stateless” is used
我在我的應用程序中使用Spring Security Oauth2進行身份驗證,這是無狀態的。 下面是spring配置文件的代碼片段
我還在所有jsps中使用了<%@ page session="false" %>
。
<http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request -->
<!-- parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter"
after="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<http auto-config="true" create-session="stateless">
<intercept-url pattern="/oauth/**" access="ROLE_USER" />
<intercept-url pattern="/welcome*" access="ROLE_USER" />
<intercept-url pattern="/test" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed"
authentication-success-handler-ref="customAuthenticationSuccessHandler" />
<logout logout-success-url="/logout" />
<custom-filter ref="preAuthFilter" after="PRE_AUTH_FILTER" />
<custom-filter ref="oauth2ClientFilter" after="EXCEPTION_TRANSLATION_FILTER" />
</http>`
我還創建了自己的授權端點(/ authorizeTest),因為Ouath2(/ oauth / authorize)提供的授權端點將AuthorizationRequest作為會話屬性。 以下是CustomAuthorizationEndPoint的代碼片段
<beans:bean id="customAuthorizationEndpoint"
class="com.mkyong.common.controller.CustomAuthorizationEndpoint">
<beans:property name="tokenGranter" ref="authorizationCodeTokenGranter" />
<beans:property name="clientDetailsService" ref="clientDetails" />
<beans:property name="oAuth2RequestFactory" ref="customOAuth2RequestFactory" />
<beans:property name="authorizationCodeServices"
ref="inMemoryAuthorizationCodeServices" />
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
<beans:bean id="authorizationCodeTokenGranter"
class="org.springframework.security.oauth2.provider.code.AuthorizationCodeTokenGranter">
<beans:constructor-arg index="0" ref="tokenServices" />
<beans:constructor-arg index="1"
ref="authorizationCodeServices" />
<beans:constructor-arg index="2" ref="clientDetails" />
<beans:constructor-arg index="3"
ref="customOAuth2RequestFactory" />
</beans:bean>
<beans:bean id="customOAuth2RequestFactory"
class="com.mkyong.common.controller.CustomOAuth2RequestFactory">
<beans:constructor-arg ref="clientDetails" />
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="customAuthorizationRequest" ref="customAuthorizationRequest" />
</beans:bean>
<beans:bean id="customAuthorizationRequest"
class="com.mkyong.common.controller.CustomAuthorizationRequest">
</beans:bean>
<beans:bean id="authorizationCodeServices"
class="org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices">
<beans:constructor-arg ref="dataSource" />
</beans:bean>
但是我仍然會產生jsession。
使用create-session="stateless"
意味着您告訴Spring Security不要為用戶創建會話或存儲身份驗證信息。 如果他們覺得需要(oauth是一個單獨的項目),它不會阻止其他庫創建會話。
我真的不明白為什么你將應用程序標記為無狀態,因為你正在使用像登錄這樣的東西。 如果您不允許創建會話,那么授權代碼流會如何工作? 如何重定向授權請求以及服務器在重定向到該請求時如何知道用戶是否經過身份驗證? 驗證將丟失,因為沒有會話將其綁定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.