Пример #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");
   }
 }
Пример #2
0
 public void continuar(String page) {
   FacesMessage msg = null;
   final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
   try {
     externalContext.redirect(page);
   } catch (final IOException e) {
     msg =
         new FacesMessage(
             FacesMessage.SEVERITY_WARN,
             Messages.getString("LoginBean.message.error.login"), // $NON-NLS-1$
             Messages.getString("LoginBean.message.error.login.detail")); // $NON-NLS-1$
     FacesContext.getCurrentInstance().addMessage(null, msg);
     LogManager.error(Messages.getString("LoginBean.log.message.error.login"), e); // $NON-NLS-1$
   }
 }
Пример #3
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$
 }