【问题标题】:Spring Security session-fixation-protection="none" Requires HTTP Page Prior to Auth RequestSpring Security session-fixation-protection="none" 在 Auth 请求之前需要 HTTP 页面
【发布时间】:2011-04-09 21:21:16
【问题描述】:

我必须在我的应用程序(基于表单的登录)中使用 session-fixation-protection="none",因为我必须在 https(用于登录)和 http(用于所有其他页面)之间切换,并且在我直接深入到登录页面 (https) 或从另一个 https 页面登录。主要问题似乎是我必须先从 http 页面开始,然后是我的登录页面(https 页面),然后它才能正确登陆 default-target-url 页面(http 页面)。如果我直接进入 https 登录页面,我会得到以下异常(请参阅调试跟踪),并且登录页面在 http 协议下重新显示,然后我可以登录,但它是通过 http 登录的。现在有人为什么会这样吗?

配置:

<beans:beans
    xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:annotation-config />
    <context:component-scan base-package="dc" />
    <global-method-security />
    <http access-denied-page="/auth/denied.html">
         <intercept-url filters="none" pattern="/javax.faces.resource/**" />
         <intercept-url filters="none" pattern="/services/rest-api/1.0/**" />
         <intercept-url filters="none" pattern="/preregistered/*"/>
         <intercept-url
            pattern="/**/*.xhtml"
            access="ROLE_NONE_GETS_ACCESS" />
         <intercept-url
            pattern="/auth/*"
            access="ROLE_ANONYMOUS,ROLE_USER"/>
         <intercept-url
            pattern="/preregistered/*"
            access="ROLE_ANONYMOUS,ROLE_USER"/>
         <intercept-url
            pattern="/registered/*"
            access="ROLE_USER"
            requires-channel="http"/>
        <form-login
            login-processing-url="/j_spring_security_check.html"
            login-page="/auth/login.html"
            default-target-url="/registered/home.html"
            authentication-failure-url="/auth/login.html" />
         <logout invalidate-session="true" 
              logout-url="/auth/logout.html" 
              success-handler-ref="DCLogoutSuccessHandler"/>
        <anonymous username="guest" granted-authority="ROLE_ANONYMOUS"/>
        <custom-filter after="FORM_LOGIN_FILTER" ref="xmlAuthenticationFilter" />
        <session-management session-fixation-protection="none"/>
    </http>
    <!-- Configure the authentication provider -->
    <authentication-manager alias="am">
        <authentication-provider user-service-ref="userManager">
                <password-encoder ref="passwordEncoder" />
        </authentication-provider>
        <authentication-provider ref="xmlAuthenticationProvider" />
    </authentication-manager>
</beans:beans> 

调试跟踪:

04:38:26,754 DEBUG ExceptionTranslationFilter:153 - Access is denied (user is anonymous); redirecting to authentication entry point
org.springframework.security.access.AccessDeniedException: Access is denied is in the debug trace. 04:38:26,755 DEBUG HttpSessionEventPublisher:66 - Publishing event: org.springframework.security.web.session.HttpSessionCreatedEvent[source=org.apache.catalina.session.StandardSessionFacade@b3977b]
04:38:26,755 DEBUG HttpSessionRequestCache:39 - DefaultSavedRequest added to Session: DefaultSavedRequest[http://pfg-prod-web01.reliam.com/dreamcatcher/registered/home.html]
04:38:26,756 DEBUG ExceptionTranslationFilter:177 - Calling Authentication entry point.
04:38:26,756 DEBUG DefaultRedirectStrategy:36 - Redirecting to 'http://pfg-prod-web01.reliam.com/dreamcatcher/auth/login.html;jsessionid=11F5897DD5FD398E9083BCC95CBF1C86'
04:38:26,756 DEBUG HttpSessionSecurityContextRepository:338 - SecurityContext is empty or anonymous - context will not be stored in HttpSession. 

【问题讨论】:

    标签: spring-security


    【解决方案1】:

    这里的第二个选项解决了我的情况:

    http://forum.springsource.org/archive/index.php/t-65651.html

    【讨论】:

    • 您应该始终在此处粘贴代码,以防您引用的文章被删除。
    • 现在发生了什么:(
    【解决方案2】:

    如果您还没有这样做,也许您可​​以尝试添加以下侦听器。

    <listener>
        <listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
    </listener> 
    

    【讨论】:

    • 是的,我现在已经配置好了,但同样的问题。注销并尝试重新登录后,我在登录表单的 url 地址上得到 auth/login.html;jsessionid=6223D4A350010EA78CAF6DDB1E8E5510。如果我再次尝试(注销后第二次),我会进入。
    • 我注意到的一件事是当我注销并转到 https 上的 auth/login.html 页面时,这是正确的。然后我尝试登录,但它失败了,然后我在 http 上使用 host/app/auth/…
    • 在原始问题(调试跟踪)中发布了上面的更新,有什么想法吗?
    猜你喜欢
    • 2018-01-26
    • 2018-11-23
    • 2017-11-17
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2017-09-14
    相关资源
    最近更新 更多