@Override
  protected String[] doLogin(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    long companyId = PortalUtil.getCompanyId(request);

    if (!isEnabled(companyId)) {
      return null;
    }

    String login = ParamUtil.getString(request, getLoginParam());

    if (Validator.isNull(login)) {
      return null;
    }

    String password = ParamUtil.getString(request, getPasswordParam());

    if (Validator.isNull(password)) {
      return null;
    }

    Company company = PortalUtil.getCompany(request);

    String authType = company.getAuthType();

    long userId = 0;

    if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
      userId = _userLocalService.getUserIdByEmailAddress(company.getCompanyId(), login);
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
      userId = _userLocalService.getUserIdByScreenName(company.getCompanyId(), login);
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
      userId = GetterUtil.getLong(login);
    } else {
      return null;
    }

    if (userId > 0) {
      User user = _userLocalService.getUserById(userId);

      String userPassword = user.getPassword();

      if (!user.isPasswordEncrypted()) {
        userPassword = PasswordEncryptorUtil.encrypt(userPassword);
      }

      String encPassword = PasswordEncryptorUtil.encrypt(password, userPassword);

      if (!userPassword.equals(password) && !userPassword.equals(encPassword)) {

        return null;
      }
    }

    String[] credentials =
        new String[] {String.valueOf(userId), password, Boolean.FALSE.toString()};

    return credentials;
  }
  @Override
  protected void processFilter(
      HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
      throws Exception {

    // The portlet TCK has two tests named GetRemoteUserNullTestPortlet. One
    // tests an action request and the other tests a render request. Those
    // two tests assume that the current user is not authenticated. This
    // filter skips automatic authentication as a workaround for those two
    // tests.

    HttpSession httpSession = request.getSession();

    if (httpSession.getAttribute(_TCK_SKIP_LOGIN) == Boolean.TRUE) {
      processFilter(PortletTCKAutoLoginFilter.class.getName(), request, response, filterChain);

      return;
    }

    String[] portletIds = request.getParameterValues("portletName");

    if (portletIds != null) {
      for (String portlet : portletIds) {
        if (portlet.endsWith("GetRemoteUserNullTestPortlet")) {
          httpSession.setAttribute(_TCK_SKIP_LOGIN, Boolean.TRUE);

          processFilter(PortletTCKAutoLoginFilter.class.getName(), request, response, filterChain);

          return;
        }
      }
    }

    User tckUser =
        _userLocalService.fetchUserByEmailAddress(
            PortalUtil.getCompanyId(request), "*****@*****.**");

    if (tckUser != null) {
      request.setAttribute(WebKeys.USER_ID, tckUser.getUserId());
    }

    processFilter(PortletTCKAutoLoginFilter.class.getName(), request, response, filterChain);
  }
    @Override
    public ResourceBundle getResourceBundle(Locale locale) {
      try {
        PortletRequest portletRequest = _portletRequestThreadLocal.get();

        long companyId = PortalUtil.getCompanyId(portletRequest);

        String portletResource = ParamUtil.getString(portletRequest, "portletResource");

        Portlet portlet = _portletLocalService.getPortletById(companyId, portletResource);

        HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest);

        PortletConfig portletConfig =
            PortletConfigFactoryUtil.create(portlet, httpServletRequest.getServletContext());

        return new AggregateResourceBundle(
            super.getResourceBundle(locale), portletConfig.getResourceBundle(locale));
      } catch (Exception e) {
        _log.error(e, e);
      }

      return super.getResourceBundle(locale);
    }