Пример #1
0
 public void checkRoles(ComponentSystemEvent event) {
   if (getUserAuth() == null
       && JSFUtils.getUserName() != null
       && !JSFUtils.getUserName().isEmpty()) {
     userAuth = userRepository.findByUsername(JSFUtils.getUserName());
     setUserAuth(userAuth);
     logOperationsController.save("LOGIN", JSFUtils.getUserName(), "LOGIN");
   }
   String acl = "" + event.getComponent().getAttributes().get("roles");
   for (String a : acl.split(",")) {
     if ("ANY".equalsIgnoreCase(a)) {
       if (JSFUtils.getUserName() != null && JSFUtils.getUserName().length() > 0) {
         return;
       }
     }
     if (isInRole(a.trim())) {
       return;
     }
   }
   try {
     logger.info(acl + " - non consentito!");
     FacesContext context = FacesContext.getCurrentInstance();
     ConfigurableNavigationHandler handler =
         (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();
     handler.performNavigation("administration");
   } catch (Exception e) {
     e.printStackTrace();
     // Se siamo qui il redirect è fallito.
     // A questo punto, piuttosto che lasciare andare l'utente dove
     // non deve.. runtime exception!
     throw new RuntimeException("Accesso non consentito");
   }
 }
Пример #2
0
 public UserAuth getUserAuth() {
   if (userAuth == null && JSFUtils.getUserName() != null && !JSFUtils.getUserName().isEmpty()) {
     userAuth = userRepository.findByUsername(JSFUtils.getUserName());
     logOperationsController.save("LOGIN", JSFUtils.getUserName(), "LOGIN");
     setUserAuth(userAuth);
   }
   return userAuth;
 }
Пример #3
0
 public String changePassword() {
   if (getUserAuth().getOldPassword() == null || getUserAuth().getOldPassword().trim().isEmpty()) {
     FacesMessage message = new FacesMessage();
     message.setDetail("La password corrente e' vuota!");
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     message.setSummary("Errore password corrente");
     FacesContext.getCurrentInstance().addMessage("pwd:opwd", message);
     return null;
   }
   String oldPassword = PasswordUtils.createPassword(getUserAuth().getOldPassword());
   if (!oldPassword.equals(getUserAuth().getPassword())) {
     FacesMessage message = new FacesMessage();
     message.setDetail("La password corrente non e' corretta!");
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     message.setSummary("Errore password corrente");
     FacesContext.getCurrentInstance().addMessage("pwd:opwd", message);
     return null;
   }
   if (getUserAuth().getNewPassword() == null || getUserAuth().getNewPassword().length() == 0) {
     FacesMessage message = new FacesMessage();
     message.setDetail("La nuova password non e' stata inserita in entrambi i campi di testo!");
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     message.setSummary("Errore nuova password");
     FacesContext.getCurrentInstance().addMessage("pwd:npwd", message);
     return null;
   }
   if (getUserAuth().getConfirmPassword() == null
       || getUserAuth().getConfirmPassword().length() == 0) {
     FacesMessage message = new FacesMessage();
     message.setDetail("La nuova password non e' stata inserita in entrambi i campi di testo!");
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     message.setSummary("Errore nuova password");
     FacesContext.getCurrentInstance().addMessage("pwd:cpwd", message);
     return null;
   }
   if (!userAuth.getNewPassword().equals(userAuth.getConfirmPassword())) {
     FacesMessage message = new FacesMessage();
     message.setDetail(
         "Sono stati inseriti valori diversi nei due campi di testo relativi alla nuova password!");
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     message.setSummary("Errore nuova password");
     FacesContext.getCurrentInstance().addMessage("pwd:cpwd", message);
     return null;
   }
   String newPassword = PasswordUtils.createPassword(getUserAuth().getNewPassword());
   getUserAuth().setPassword(newPassword);
   userRepository.update(getUserAuth());
   logOperationsController.save(
       OperazioniLog.MODIFY,
       JSFUtils.getUserName(),
       "cambio pwd utente: " + this.userAuth.getUsername());
   ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
   try {
     extCtx.redirect(extCtx.encodeActionURL(LOGOUT));
   } catch (Exception e) {
     FacesMessage message = new FacesMessage("Errore generico, riprovare piu' tardi!");
     message.setSeverity(FacesMessage.SEVERITY_ERROR);
     message.setSummary("Errore generico");
     FacesContext.getCurrentInstance().addMessage("pwd:cpwd", message);
     return null;
   }
   return null;
 }
Пример #4
0
 public String goToChangePassword() {
   this.userAuth = userRepository.findByUsername(JSFUtils.getUserName());
   return CAMBIO_PASSWORD + REDIRECT_PARAM;
 }