spring-security-core - Can I issue a redirect/forward from an event (like onInteractiveAuthenticationSuccessEvent)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

spring-security-core - Can I issue a redirect/forward from an event (like onInteractiveAuthenticationSuccessEvent)

micke_
Hi

I'm trying to figure out a graceful way of redirecting a user to a greeting page the very first time they login.

I figure I can do this in the action which all users are sent to after a successful login by storing some state on the user domain object.

Would prefer to put this somewhere else though, like for example in the authentication success event. Not sure how I can trigger a redirect from in there though...

Any ideas?

Many thanks,
 Micke
Reply | Threaded
Open this post in threaded view
|

Re: spring-security-core - Can I issue a redirect/forward from an event (like onInteractiveAuthenticationSuccessEvent)

micke_
Just in case anyone else is looking to do something similar this is what I ended up with.

On my User domain object I added a state field and then added a custom authentication success handler as follows:

class MyAuthenticationSuccessHandler extends AjaxAwareAuthenticationSuccessHandler{
UserService userService
SpringSecurityService springSecurityService
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication){
User user = springSecurityService.currentUser
logger.debug "${user} state=${user.state}"
if(user.state == User.STATE_CREATED){
//users first ever login, redirect to greet/welcome page
//Not just created any longer set to normal!
userService.updateUserState(user, User.STATE_NORMAL)
logger.debug "returning greeting page"
redirectStrategy.sendRedirect(request, response, '/greet/welcome');
}
else{
super.onAuthenticationSuccess(request, response, authentication)
}
}
}




On 25 April 2014 21:55, Mikael Andersson <[hidden email]> wrote:
Hi

I'm trying to figure out a graceful way of redirecting a user to a greeting page the very first time they login.

I figure I can do this in the action which all users are sent to after a successful login by storing some state on the user domain object.

Would prefer to put this somewhere else though, like for example in the authentication success event. Not sure how I can trigger a redirect from in there though...

Any ideas?

Many thanks,
 Micke