public String login() {
    IUser storedUser = authenticator.checkCredential(username, password);
    String outcome;

    if (storedUser != null) {
      setLoggedIn(true);
      user = storedUser;
      loginEvent.fire(new LoginEvent(storedUser, requestedRole, requestedStoreId));
      LOG.info(String.format("Successful login: username %s.", getUserName()));
      outcome =
          isStoreRequired()
              ? NavigationElements.STORE_MAIN.getNavigationOutcome()
              : NavigationElements.ENTERPRISE_MAIN.getNavigationOutcome();
    } else {
      FacesContext context = FacesContext.getCurrentInstance();
      String message =
          context
              .getApplication()
              .evaluateExpressionGet(context, "#{strings['login.failed.text']}", String.class);
      context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
      outcome = NavigationElements.LOGIN.getNavigationOutcome();
      LOG.warn(String.format("Failed login: username %s.", getUserName()));
    }
    return outcome;
  }
  public String logout() {
    username = "";
    password = credFactory.createPlainPassword("");
    requestedRole = UserRole.ENTERPRISE_MANAGER;
    requestedStoreId = 0;

    logoutEvent.fire(new LogoutEvent(user));
    user = null;

    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    return NavigationElements.LOGIN.getNavigationOutcome();
  }