java - Spring security. unbelievable behavior -
i have strange spring security behaviour.
security configuration:
<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.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> <http use-expressions="true" > <intercept-url pattern="/home.jsp" access="permitall" /> <intercept-url pattern="/*" access="isauthenticated()"/> <form-login login-page="/" authentication-failure-url="/loginfailed" default-target-url="/index" /> <logout logout-success-url="/logout" /> </http> <authentication-manager> <authentication-provider ref="provider" /> </authentication-manager> </beans:beans> controller:
@controller public class homecontroller { @requestmapping("/index") public string success(model model) { system.out.println("/index"); return "index"; } @requestmapping(value="/loginfailed", method = requestmethod.get ) public string loginerror(model model, redirectattributes redirectattributes ) throws exception { redirectattributes.addattribute("message", "incorrect combination of login , password"); system.out.println("/loginfailed"); return "redirect:home.jsp"; } @requestmapping(value="/logout", method = requestmethod.get ) public string logout(model model, redirectattributes redirectattributes) throws exception { redirectattributes.addattribute("message", "success logout"); system.out.println("/logout"); return "redirect:home.jsp"; } ... } if on url http://localhost:8080/ui/(root application url) type
first activity:
1 input correct password --> http://localhost:8080/ui/index in log see /index isauthenttificated() == true
2 press logout --> http://localhost:8080/ui/ , log empty isauthenttificated() == false
3 input correct password --> http://localhost:8080/ui/home.jsp?message=success+logout , see /logout in console isauthenttificated() == true
4 press logout --> go http://localhost:8080/ui/ , log empty isauthenttificated() == false
5 input correct password --> go http://localhost:8080/ui/ , log empty isauthenttificated() == false
i don't understand rules spring security select controller use.
i think spring invokes right servlets use wrong urls.
what noticed forgot add following configuration
<intercept-url pattern="/loginfailed" access="permitall" /> <intercept-url pattern="/" access="permitall" /> or @ least pages related login/error pages should exempted authentication.
Comments
Post a Comment