Spring AuthenticationSuccessHandler


      Click here to attend Spring Framework 4.x and certification course with a discount

package nl.kameroom.security;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import nl.kameroom.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

public class AuthenticationHandler implements AuthenticationSuccessHandler{

 private UserManager userManager = null;

 @Autowired
 public void setLoginService(UserManager um) {
 userManager = um;
 }

 @Override
 public void onAuthenticationSuccess(HttpServletRequest request,
 HttpServletResponse response, Authentication authentication) throws IOException,
 ServletException {
 userManager.updateLastLogin(((User)authentication.getPrincipal()).getUsername());
 response.sendRedirect("/kameroom/profile/profile.k");

 }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s