Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package be.hainaut.Evaluation.utils;
  2.  
  3.  
  4. import java.io.Serializable;
  5.  
  6. import javax.enterprise.context.RequestScoped;
  7. import javax.faces.bean.ManagedBean;
  8. import javax.faces.context.FacesContext;
  9. import javax.inject.Inject;
  10. import javax.security.auth.login.LoginException;
  11. import javax.servlet.http.HttpServletRequest;
  12.  
  13. import be.hainaut.Evaluation.enums.MessagesTypes;
  14. import be.hainaut.Evaluation.enums.Pages;
  15. import be.hainaut.common_secu.login.LoginBean;
  16.  
  17. @ManagedBean
  18. @RequestScoped
  19. public class LoginUtils implements Serializable {
  20.    
  21.     private static final long serialVersionUID = 8381555025416209759L;
  22.  
  23.     private String username;
  24.    
  25.     private String password;
  26.    
  27.     @Inject
  28.     private LoginBean loginBean;
  29.    
  30.     @Inject
  31.     private MessagesController messages;
  32.    
  33.     @Inject
  34.     private PageController pageController;
  35.    
  36.     @Inject
  37.     private AppInfo appInfo;
  38.    
  39.     public String login() {
  40.         FacesContext context = FacesContext.getCurrentInstance();
  41.         HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
  42.         try {
  43.             loginBean.login(request, this.username.toUpperCase(), this.password.toUpperCase());
  44.             if (!appInfo.initApp(this.username.toUpperCase())) {
  45.                 messages.addMessage(MessagesTypes.ERROR, "Erreur d'authentification", "Vous n'avez pas les autorisations pour cette application.");
  46.                 return "";
  47.             }
  48.             return pageController.getToPageFromMenu(Pages.accueil.getName());
  49.         } catch (LoginException e) {
  50.             e.printStackTrace();
  51.             messages.addMessage(MessagesTypes.ERROR, "Erreur d'authentification", "Vérifiez votre login et votre mot de passe");
  52.             return "";
  53.         }
  54.     }
  55.    
  56.     public String testTimeout() {
  57.         return "Logout";
  58.     }
  59.  
  60.     public String getUsername() {
  61.         return username;
  62.     }
  63.  
  64.     public void setUsername(String username) {
  65.         this.username = username;
  66.     }
  67.  
  68.     public String getPassword() {
  69.         return password;
  70.     }
  71.  
  72.     public void setPassword(String password) {
  73.         this.password = password;
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement