Package com.liferay.faces.portal.context

Examples of com.liferay.faces.portal.context.LiferayFacesContext


  private String authType;
  private String handleLabel;

  public void authenticate() {

    LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    ActionRequest actionRequest = (ActionRequest) liferayFacesContext.getPortletRequest();
    ActionResponse actionResponse = (ActionResponse) liferayFacesContext.getPortletResponse();
    ThemeDisplay themeDisplay = liferayFacesContext.getThemeDisplay();
    HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest);

    // If the request object is a wrapper that handles special namespacing considerations for portlet session
    // attributes, then get the inner-most wrapped request. This will ensure that the following call to
    // LoginUtil.login(...) will be able to work with a session that has an attribute map shared by the portal.
    if (httpServletRequest.getClass().getName().equals(NAMESPACE_SERVLET_REQUEST_FQCN)) {

      while (httpServletRequest instanceof HttpServletRequestWrapper) {
        HttpServletRequestWrapper httpServletRequestWrapper = (HttpServletRequestWrapper) httpServletRequest;
        httpServletRequest = (HttpServletRequest) httpServletRequestWrapper.getRequest();
      }
    }

    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);

    String handle = loginModelBean.getHandle();
    String password = loginModelBean.getPassword();
    boolean rememberMe = loginModelBean.isRememberMe();

    boolean authenticated = false;
    String feedbackMessageId = null;

    try {

      LoginUtilCompat.invokeLogin(httpServletRequest, httpServletResponse, handle, password, rememberMe,
        authType);

      authenticated = true;
    }
    catch (AuthException e) {
      feedbackMessageId = "authentication-failed";
    }
    catch (CompanyMaxUsersException e) {
      feedbackMessageId = "unable-to-login-because-the-maximum-number-of-users-has-been-reached";
    }
    catch (CookieNotSupportedException e) {
      feedbackMessageId = "authentication-failed-please-enable-browser-cookies";
    }
    catch (NoSuchUserException e) {
      feedbackMessageId = "authentication-failed";
    }
    catch (PasswordExpiredException e) {
      feedbackMessageId = "your-password-has-expired";
    }
    catch (UserEmailAddressException e) {
      feedbackMessageId = "authentication-failed";
    }
    catch (UserLockoutException e) {
      feedbackMessageId = "this-account-has-been-locked";
    }
    catch (UserPasswordException e) {
      feedbackMessageId = "authentication-failed";
    }
    catch (UserScreenNameException e) {
      feedbackMessageId = "authentication-failed";
    }
    catch (Exception e) {
      logger.error(e);
    }

    if (authenticated) {

      try {
        ExternalContext externalContext = liferayFacesContext.getExternalContext();

        if (PropsValuesCompat.PORTAL_JAAS_ENABLE) {
          externalContext.redirect(themeDisplay.getPathMain() + "/portal/protected");
        }
        else {
          String redirect = ParamUtil.getString(actionRequest, "redirect");

          if (Validator.isNotNull(redirect)) {
            redirect = PortalUtilCompat.escapeRedirect(redirect);

            if (!redirect.startsWith(Http.HTTP)) {
              redirect = getCompleteRedirectURL(httpServletRequest, redirect);
            }

            externalContext.redirect(redirect);
          }
          else {
            boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

            if (doActionAfterLogin) {
              return;
            }
            else {

              redirect = getCompleteRedirectURL(httpServletRequest, themeDisplay.getPathMain());
              externalContext.redirect(redirect);
            }
          }
        }
      }
      catch (IOException e) {
        logger.error(e);
        liferayFacesContext.addGlobalUnexpectedErrorMessage();
      }
    }
    else {

      if (feedbackMessageId != null) {
        liferayFacesContext.addGlobalErrorMessage(feedbackMessageId);
      }
    }
  }
View Full Code Here


  public String getAuthType() {

    if (authType == null) {

      LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();

      try {
        ThemeDisplay themeDisplay = liferayFacesContext.getThemeDisplay();
        Company company = themeDisplay.getCompany();

        authType = company.getAuthType();
      }
      catch (SystemException e) {
        logger.error(e);
        liferayFacesContext.addGlobalErrorMessage("Unable to determine authentication type");
        authType = CompanyConstants.AUTH_TYPE_EA;
      }
    }

    return authType;
View Full Code Here

      new Object[] {
        submittedRegistrant.getFirstName(), submittedRegistrant.getLastName(),
        submittedRegistrant.getEmailAddress(), submittedRegistrant.getCaptchaText()
      });

    LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    long creatorUserId = liferayFacesContext.getUser().getUserId();
    long companyId = liferayFacesContext.getCompanyId();
    Locale locale = liferayFacesContext.getLocale();

    try {
      boolean active = true;
      boolean autoScreenName = false;
      boolean sendEmail = true;
      RegistrantServiceUtil.add(creatorUserId, companyId, locale, submittedRegistrant, active, autoScreenName,
        sendEmail);

      String key = "thank-you-for-registering";
      liferayFacesContext.addGlobalInfoMessage(key, submittedRegistrant.getEmailAddress());
      submittedRegistrant.clearProperties();
    }
    catch (DuplicateUserScreenNameException e) {
      liferayFacesContext.addGlobalErrorMessage("the-screen-name-you-requested-is-already-taken");
    }
    catch (DuplicateUserEmailAddressException e) {
      liferayFacesContext.addGlobalErrorMessage("the-email-address-you-requested-is-already-taken");
    }
    catch (UserPasswordException e) {

      switch (e.getType()) {

      case UserPasswordException.PASSWORD_ALREADY_USED: {
        liferayFacesContext.addGlobalErrorMessage(
          "that-password-has-already-been-used-please-enter-in-a-different-password");

        break;
      }

      case UserPasswordException.PASSWORD_CONTAINS_TRIVIAL_WORDS: {
        liferayFacesContext.addGlobalErrorMessage(
          "that-password-uses-common-words-please-enter-in-a-password-that-is-harder-to-guess-i-e-contains-a-mix-of-numbers-and-letters");

        break;
      }

      case UserPasswordException.PASSWORD_INVALID: {
        liferayFacesContext.addGlobalErrorMessage(
          "that-password-is-invalid-please-enter-in-a-different-password");

        break;
      }

      case UserPasswordException.PASSWORD_LENGTH: {

        try {
          Company company = CompanyLocalServiceUtil.getCompany(companyId);
          PasswordPolicy passwordPolicy = company.getDefaultUser().getPasswordPolicy();
          liferayFacesContext.addGlobalErrorMessage(
            "that-password-is-too-short-or-too-long-please-make-sure-your-password-is-between-x-and-512-characters",
            new Object[] { String.valueOf(passwordPolicy.getMinLength()) });

        }
        catch (Exception e1) {
          logger.error(e.getMessage(), e);
          liferayFacesContext.addGlobalUnexpectedErrorMessage();
        }

        break;
      }

      case UserPasswordException.PASSWORD_NOT_CHANGEABLE: {
        liferayFacesContext.addGlobalErrorMessage("your-password-cannot-be-changed");

        break;
      }

      case UserPasswordException.PASSWORD_SAME_AS_CURRENT: {
        liferayFacesContext.addGlobalErrorMessage(
          "your-new-password-cannot-be-the-same-as-your-old-password-please-enter-in-a-different-password");

        break;
      }

      case UserPasswordException.PASSWORD_TOO_TRIVIAL: {
        liferayFacesContext.addGlobalErrorMessage("that-password-is-too-trivial");

        break;
      }

      case UserPasswordException.PASSWORD_TOO_YOUNG: {

        try {
          Company company = CompanyLocalServiceUtil.getCompany(companyId);
          PasswordPolicy passwordPolicy = company.getDefaultUser().getPasswordPolicy();
          liferayFacesContext.addGlobalErrorMessage(
            "you-cannot-change-your-password-yet-please-wait-at-least-x-before-changing-your-password-again",
            new Object[] { String.valueOf(passwordPolicy.getMinAge() * 1000) });

        }
        catch (Exception e1) {
          logger.error(e.getMessage(), e);
          liferayFacesContext.addGlobalUnexpectedErrorMessage();
        }

        break;
      }

      case UserPasswordException.PASSWORDS_DO_NOT_MATCH: {
        liferayFacesContext.addGlobalErrorMessage(
          "the-passwords-you-entered-do-not-match-each-other-please-re-enter-your-password");

        break;
      }

      default: {
        break;
      }
      }
    }
    catch (Exception e) {
      logger.error(e.getMessage(), e);
      liferayFacesContext.addGlobalUnexpectedErrorMessage();
    }
  }
View Full Code Here

  private String portletResourcePrimaryKey;

  public String getPortletResourcePrimaryKey() {

    if (portletResourcePrimaryKey == null) {
      LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
      long plid = liferayFacesContext.getPlid();
      Portlet portlet = liferayFacesContext.getPortlet();
      String portletId = portlet.getPortletId();
      portletResourcePrimaryKey = PortletPermissionUtil.getPrimaryKey(plid, portletId);
    }

    return portletResourcePrimaryKey;
View Full Code Here

TOP

Related Classes of com.liferay.faces.portal.context.LiferayFacesContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.