Ejemplo n.º 1
0
  /**
   * Performs logout.
   *
   * @return navigation page
   */
  public String logout() {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    try {
      this.user = null;
      request.logout();
      // clear the session
      ((HttpSession) context.getExternalContext().getSession(false)).invalidate();
      this.log.infof("Logout: %s -->success", this.username);
      JsfUtil.addSuccessMessage("Odhlášení se zdařilo.");

    } catch (ServletException ex) {
      JsfUtil.addErrorMessage("Odhlášení se nezdařilo.");
      this.log.infof("Logout: %s -->unsuccessful", this.username);
    }
    return "/login";
  }
Ejemplo n.º 2
0
  /** Performs login. */
  public void login() {

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    try {
      Principal userPrincipal = request.getUserPrincipal();
      if (request.getUserPrincipal() != null) {
        request.logout();
      }
      request.login(this.username, this.password);
      userPrincipal = request.getUserPrincipal();
      // System.out.println("Prihlasen " + username);
      this.log.infof("Login: %s -->success", this.username);
      this.user = this.userManager.getUserByUsername(this.username);
      JsfUtil.addSuccessMessage("Přihlášení se zdařilo.");

    } catch (ServletException ex) {
      JsfUtil.addErrorMessage("Přihlášení se nezdařilo.");
      System.out.println("Neprihlasen, pokus byl " + this.username + " " + this.password);
      this.log.infof("Login: %s --> unsuccessful", this.username);
    }
  }