how to get redirected to a method at login/logout before target-url called in spring-security, spring mvc -


i trying record current time of login(in method or object) once login successful , assign lastlogin time current login time @ logout. using spring security login, logout. don't know how take control method before goes target-url.

spring-security.xml -

<security:form-login login-page="/login"  login-processing-url="/home/currenttime" authentication-failure-url="/login?error=true" default-target-url="/home"/>  <security:logout invalidate-session="true"             logout-success-url="/home/copylastlogintocurrentlogintime" logout-url="/logout" /> 

controller - /home -

 @requestmapping(value = "/currenttime", method = requestmethod.get)         public void recordcurrentlogintime(model model) { //code record current time }      @requestmapping(value = "/copylastlogintocurrentlogintime", method = requestmethod.get)     public void changelastlogintime(model model) {//code copy current last time } 

problem - error 404 - project-title/j_spring_security_check url. , when try debug, doesn't come controller methods @ all. should use filters or else purpose?

i have seen springsecurity : redirect logged in users page , how process form login using spring security / spring mvc. couldn't achieve target.

i new spring security , need move in right direction.

  • thanks

write own authenticationsuccesshandler , logoutsuccesshandler.

example :

spring-security.xml :

<security:form-login login-page="/login"     login-processing-url="/login_check"     authentication-failure-url="/login?error=true"     authentication-success-handler-ref="myauthenticationsuccesshandler" />  <security:logout     logout-url="/logout"     success-handler-ref="mylogoutsuccesshandler" /> 

authenticationsuccesshandler

@component public class myauthenticationsuccesshandler extends simpleurlauthenticationsuccesshandler {      @autowired     private userservice userservice;      @override     public void onauthenticationsuccess(httpservletrequest request, httpservletresponse response,         authentication authentication) throws ioexception, servletexception {          // changelastlogintime(username)         userservice.changelastlogintime(authentication.getname());          setdefaulttargeturl("/home");         super.onauthenticationsuccess(request, response, authentication);     } } 

logoutsuccesshandler

@component public class mylogoutsuccesshandler extends simpleurllogoutsuccesshandler {      @override     public void onlogoutsuccess(httpservletrequest request, httpservletresponse response,             authentication authentication) throws ioexception, servletexception {          if (authentication != null) {             //          }          setdefaulttargeturl("/login");         super.onlogoutsuccess(request, response, authentication);            } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -