Exemplo n.º 1
0
 public void login(ActionEvent actionEvent) {
   SecurityUtils.getSubject()
       .login(new UsernamePasswordToken(getNombre(), getClave(), isRemember()));
   WebUtils.getAndClearSavedRequest(
       (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
   logeado = SecurityUtils.getSubject().isAuthenticated();
   final RequestContext context = RequestContext.getCurrentInstance();
   FacesMessage msg = null;
   if (logeado) {
     msg =
         new FacesMessage(
             FacesMessage.SEVERITY_INFO,
             Messages.getString("LoginBean.message.welcome"), // $NON-NLS-1$
             nombre);
     LogManager.info(Messages.getString("LoginBean.log.message.access", nombre)); // $NON-NLS-1$
   } else {
     msg =
         new FacesMessage(
             FacesMessage.SEVERITY_WARN,
             Messages.getString("LoginBean.message.error"), // $NON-NLS-1$
             Messages.getString("LoginBean.message.error.details")); // $NON-NLS-1$
     LogManager.warn(Messages.getString("LoginBean.log.message.error", nombre)); // $NON-NLS-1$
   }
   FacesContext.getCurrentInstance().addMessage(null, msg);
   context.addCallbackParam("estaLogeado", logeado);
   if (logeado) {
     continuar("home.xhtml");
   }
 }
Exemplo n.º 2
0
 public void logout() {
   SecurityUtils.getSubject().logout();
   final HttpSession session =
       (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
   if (session != null) {
     session.invalidate();
   }
   logeado = false;
   continuar("login.xhtml");
   LogManager.info(Messages.getString("LoginBean.log.message.logout", nombre)); // $NON-NLS-1$
 }