1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
public class LoginAction extends ActionSupport implements SessionAware, Preparable, AuthenticationSuccessHandler {
private UserDetails userDetails;
private User userConnecte;
private Map session;
@Autowired
private UserBO userBO;
// DI via spring
public void setUserBO(UserBO userBO) {
this.userBO = userBO;
}
/**
* Getters and setters
* @return
*/
public User getUserConnecte() {
return userConnecte;
}
public void setUserConnecte(User userConnecte) {
this.userConnecte = userConnecte;
}
public User getSession() {
return session;
}
public void setSession(Map session) {
this.session = session;
}
public void prepare() throws Exception {
// TODO Auto-generated method stub
}
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (!(auth instanceof AnonymousAuthenticationToken)) {
this.userDetails = (UserDetails) auth.getPrincipal();
}
this.userConnecte = this.userBO.retournerUserByEmail(this.userDetails.getUsername());
this.session = ActionContext.getContext().getSession();
session.put("userConnecte", this.userConnecte);
} |
Partager