Spring Security 3注销无效

时间:2011-07-14 08:39:30

标签: spring-security logout

我是春天安全的新手。我在spring security 3中创建了一个例子。

我遇到了问题。我能够使用默认登录页面成功登录,但是当我注销时,我已成功重定向到我的loggedout.jsp,但在检查更改URL时,我看到我仍然登录。

春天security.xml

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    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/security
        http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <http pattern="/loggedout.jsp" security="none" />

    <http auto-config='true'>
        <intercept-url pattern="/**" access="ROLE_USER" />
        <logout logout-success-url="/loggedout.jsp" invalidate-session="true"
            delete-cookies="JSESSIONID" />

        <!-- <remember-me key="myAppKey" /> -->
        <!-- <session-management invalid-session-url="/timeout.jsp">
            <concurrency-control max-sessions="1"
                error-if-maximum-exceeded="true" />
        </session-management> -->
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="vrajesh" password="vrajesh"
                    authorities="ROLE_USER,ROLE_ADMIN" />
                <user name="test" password="test"
                    authorities="ROLE_USER,ROLE_ADMIN" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

    <!--
        <http pattern="/loggedout.jsp" security="none"/>
        <http use-expressions="true">
            <intercept-url pattern="/**" access="ROLE_USER" />
            <form-login />
            <logout logout-success-url="/loggedout.jsp"
                delete-cookies="JSESSIONID"/>
            <remember-me />
            <session-management invalid-session-url="/timeout.jsp">
                <concurrency-control max-sessions="1"
                    error-if-maximum-exceeded="true" />
            </session-management>
        </http>
    -->

</beans:beans>

这是我在每个页面上的退出链接:

<p><a href="j_spring_security_logout">Logout</a></p>

这是我的loggedout.jsp

<p>
You have been logged out. <a href="<c:url value='/'/>">Start again</a>.
</p>

在我的loggedout.jsp中,如果我点击“重新开始”链接,它应该显示登录页面,但它不显示。相反,我登录了应用程序。

请帮助我,如果我遗失任何东西,请告诉我。

2 个答案:

答案 0 :(得分:4)

每个页面上的注销链接应为:

<p><a href="/j_spring_security_logout">Logout</a></p>

答案 1 :(得分:0)

引用j_spring_security_logout时遇到问题,所以我这样做了:

1.-在spring-security.xml添加到部分:

<logout logout-url="/logout.html"/>

2.-在我的控制器中我只有:

@RequestMapping(value = "logout.html", method = RequestMethod.GET)
    public String logout(ModelMap model, HttpServletRequest request) {
        return "loginform";
    }

3.-在我的 .jsp

 <a href="${pageContext.request.contextPath}/logout.html"><fmt:message key="text.exit" /></a>

它完美无瑕地工作:)

您可以查看其他退出配置here