Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

spring - Call to j_spring_security_logout not working

I'm trying to setup the logut of my application with j_spring_security_logout but for some reason it's not working, I keep getting a 404 error.

I'm calling the function like this:

<a href="<c:url value="/j_spring_security_logout"/>"><img border="0" id="logout" src="./img/logout.png" /></a>

I have in WebContent/jsp/ my application main page, and the login and logout pages are in WebContent/login/.

I've also checked this other post Problem with Spring security's logout but the solution given there is not working for me.

Here you can see my web.xml

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>
     org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter> 

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

And here my spring-security.xml

<http auto-config="true">
    <intercept-url pattern="/*" access="ROLE_USER" />
    <form-login login-page="/login/login.jsp" 
                authentication-failure-url="/login/errorLogin.jsp"/>
    <logout logout-success-url="/" logout-url="/login/logout.jsp" />
</http>

<beans:bean id="myAuthenticationProvider" 
    class="myapp.web.authentication.WSAuthenticationProvider">
</beans:bean>

<authentication-manager>
    <authentication-provider ref="myAuthenticationProvider"/>
</authentication-manager>

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the logout-url refers to a virtual URL, you need not have any resource by that name. You can do either this:

<logout logout-success-url="/" logout-url="/j_spring_security_logout" />

and the link on your page like this

<c:url value="/j_spring_security_logout" var="logoutUrl" />
<a href="${logoutUrl}">Log Out</a>

OR this:

<logout logout-success-url="/" logout-url="/logout" />

and the link as follows:

<c:url value="/logout" var="logoutUrl" />
<a href="${logoutUrl}">Log Out</a>

You were mixing both thats why you were getting 404 error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...