Example usage for com.liferay.portal.kernel.model CompanyConstants AUTH_TYPE_ID

List of usage examples for com.liferay.portal.kernel.model CompanyConstants AUTH_TYPE_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model CompanyConstants AUTH_TYPE_ID.

Prototype

String AUTH_TYPE_ID

To view the source code for com.liferay.portal.kernel.model CompanyConstants AUTH_TYPE_ID.

Click Source Link

Usage

From source file:com.liferay.docs.mvcportlet.action.EditUserMVCActionCommand.java

License:Open Source License

@Override
protected Object[] updateUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String currentPassword = actionRequest.getParameter("password0");
    String newPassword = actionRequest.getParameter("password1");

    User user = PortalUtil.getSelectedUser(actionRequest);

    if (Validator.isNotNull(currentPassword)) {
        if (Validator.isNull(newPassword)) {
            throw new UserPasswordException.MustNotBeNull(user.getUserId());
        }/* w  w  w .  jav a  2s  . co m*/

        Company company = PortalUtil.getCompany(actionRequest);

        String authType = company.getAuthType();

        Map<String, String[]> headerMap = new HashMap<>();
        Map<String, String[]> parameterMap = new HashMap<>();
        Map<String, Object> resultsMap = new HashMap<>();

        int authResult = Authenticator.FAILURE;

        if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
            authResult = userLocalService.authenticateByEmailAddress(company.getCompanyId(),
                    user.getEmailAddress(), currentPassword, headerMap, parameterMap, resultsMap);
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
            authResult = userLocalService.authenticateByUserId(company.getCompanyId(), user.getUserId(),
                    currentPassword, headerMap, parameterMap, resultsMap);
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
            authResult = userLocalService.authenticateByScreenName(company.getCompanyId(), user.getScreenName(),
                    currentPassword, headerMap, parameterMap, resultsMap);
        }

        if (authResult == Authenticator.FAILURE) {
            throw new UserPasswordException.MustMatchCurrentPassword(user.getUserId());
        }
    } else if (Validator.isNotNull(newPassword)) {
        throw new UserPasswordException.MustNotBeNull(user.getUserId());
    }

    return super.updateUser(actionRequest, actionResponse);
}

From source file:com.liferay.document.library.repository.cmis.CMISRepositoryHandler.java

License:Open Source License

public String getLogin() {
    String login = PrincipalThreadLocal.getName();

    if (Validator.isNull(login)) {
        return login;
    }//from w ww .j  av a2 s. co m

    try {
        Company company = companyLocalService.getCompany(getCompanyId());

        String authType = company.getAuthType();

        if (!authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
            User user = userLocalService.getUser(GetterUtil.getLong(login));

            if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
                login = user.getEmailAddress();
            } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
                login = user.getScreenName();
            }
        }
    } catch (Exception e) {
        throw new RepositoryException(e);
    }

    return login;
}

From source file:com.liferay.document.library.repository.cmis.internal.model.CMISModel.java

License:Open Source License

protected User getUser(String createdBy) {
    User user = null;//ww  w  .j  ava2 s.  c  o  m

    try {
        Company company = CompanyLocalServiceUtil.getCompany(getCompanyId());

        String authType = company.getAuthType();

        if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
            user = UserLocalServiceUtil.getUser(GetterUtil.getLong(createdBy));
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
            user = UserLocalServiceUtil.getUserByEmailAddress(getCompanyId(), createdBy);
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
            user = UserLocalServiceUtil.getUserByScreenName(getCompanyId(), createdBy);
        }
    } catch (Exception e) {
    }

    if (user == null) {
        try {
            user = UserLocalServiceUtil.getDefaultUser(getCompanyId());
        } catch (Exception e) {
        }
    }

    return user;
}

From source file:com.liferay.document.library.repository.external.ExtRepositoryAdapter.java

License:Open Source License

private String _getLogin() {
    String login = PrincipalThreadLocal.getName();

    if (Validator.isNull(login) || _isDefaultUser(login)) {
        return PropsUtil.get(PropsKeys.DL_REPOSITORY_GUEST_USERNAME);
    }/*from w w  w  . j a  va 2  s.  c  o  m*/

    try {
        String authType = getAuthType();

        if (!authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
            User user = userLocalService.getUser(GetterUtil.getLong(login));

            if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
                login = user.getEmailAddress();
            } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
                login = user.getScreenName();
            }
        }
    } catch (PortalException | SystemException e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to get login to connect to external repository " + _extRepository, e);
        }

        login = null;
    }

    return login;
}

From source file:com.liferay.document.library.repository.external.model.ExtRepositoryModelAdapter.java

License:Open Source License

protected User getUser(String extRepositoryUserName) {
    User user = null;/*from   w w  w  . j a  v a2 s.  com*/

    if (Validator.isNotNull(extRepositoryUserName)) {
        String liferayLogin = _extRepositoryAdapter.getLiferayLogin(extRepositoryUserName);

        try {
            String authType = _extRepositoryAdapter.getAuthType();

            if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
                user = UserLocalServiceUtil.getUser(GetterUtil.getLong(liferayLogin));
            } else if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
                user = UserLocalServiceUtil.getUserByEmailAddress(getCompanyId(), liferayLogin);
            } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
                user = UserLocalServiceUtil.getUserByScreenName(getCompanyId(), liferayLogin);
            }
        } catch (Exception e) {
        }
    }

    if (user == null) {
        try {
            user = UserLocalServiceUtil.getDefaultUser(getCompanyId());
        } catch (Exception e) {
        }
    }

    return user;
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java

License:Open Source License

protected void sendRedirect(ActionRequest actionRequest, ActionResponse actionResponse,
        ThemeDisplay themeDisplay, User user, String password) throws Exception {

    String login = null;//from ww w .  j  a  va 2 s  . c o m

    Company company = themeDisplay.getCompany();

    String authType = company.getAuthType();

    if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
        login = String.valueOf(user.getUserId());
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
        login = user.getScreenName();
    } else {
        login = user.getEmailAddress();
    }

    HttpServletRequest request = _portal.getHttpServletRequest(actionRequest);

    String redirect = _portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    if (Validator.isNotNull(redirect)) {
        HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

        _authenticatedSessionManager.login(request, response, login, password, false, null);
    } else {
        PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid());

        loginURL.setParameter("login", login);

        redirect = loginURL.toString();
    }

    actionResponse.sendRedirect(redirect);
}

From source file:com.liferay.my.account.web.internal.portlet.action.UpdatePasswordMVCActionCommand.java

License:Open Source License

protected void authenticateUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String currentPassword = actionRequest.getParameter("password0");
    String newPassword = actionRequest.getParameter("password1");

    User user = _portal.getSelectedUser(actionRequest);

    if (Validator.isNotNull(currentPassword)) {
        if (Validator.isNull(newPassword)) {
            throw new UserPasswordException.MustNotBeNull(user.getUserId());
        }/*w w  w. ja v a  2  s.  c o m*/

        Company company = _portal.getCompany(actionRequest);

        String authType = company.getAuthType();

        Map<String, String[]> headerMap = new HashMap<>();
        Map<String, String[]> parameterMap = new HashMap<>();
        Map<String, Object> resultsMap = new HashMap<>();

        int authResult = Authenticator.FAILURE;

        if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
            authResult = _userLocalService.authenticateByEmailAddress(company.getCompanyId(),
                    user.getEmailAddress(), currentPassword, headerMap, parameterMap, resultsMap);
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
            authResult = _userLocalService.authenticateByUserId(company.getCompanyId(), user.getUserId(),
                    currentPassword, headerMap, parameterMap, resultsMap);
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
            authResult = _userLocalService.authenticateByScreenName(company.getCompanyId(),
                    user.getScreenName(), currentPassword, headerMap, parameterMap, resultsMap);
        }

        if (authResult == Authenticator.FAILURE) {
            throw new UserPasswordException.MustMatchCurrentPassword(user.getUserId());
        }
    } else if (Validator.isNotNull(newPassword)) {
        throw new UserPasswordException.MustNotBeNull(user.getUserId());
    }
}