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

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

Introduction

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

Prototype

String AUTH_TYPE_SN

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

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());
        }/*  ww w  .j  ava 2  s .c o  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;
    }//  ww  w  .  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;/*from w w w  .ja  v  a2s . 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.jav  a 2 s .co  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;//  w  w  w . j av a 2s. c  o m

    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;//w w  w  .j  a va  2  s .co  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());
        }//from   w w w  . ja  v  a 2s  .c  om

        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());
    }
}

From source file:com.slemarchand.quick.sign.up.web.portlet.QuickSignUpPortlet.java

License:Open Source License

protected User addUser(ActionRequest actionRequest, ActionResponse actionResponse, String password)
        throws SystemException, PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    String authType = company.getAuthType();

    boolean autoPassword = false;
    String password1 = null;/*from w  w w . ja v  a  2 s  .  c o  m*/
    String password2 = null;
    boolean autoScreenName = !authType.equals(CompanyConstants.AUTH_TYPE_SN);
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = 0;
    String openId = StringPool.BLANK;
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = StringPool.BLANK;
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    int prefixId = 0;
    int suffixId = 0;
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = 1;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = StringPool.BLANK;
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = true;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    password1 = password;
    password2 = password;

    User user = UserServiceUtil.addUser(company.getCompanyId(), autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName,
            middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
            groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    long userId = user.getUserId();

    user = UserLocalServiceUtil.updatePasswordReset(userId, false);

    PasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(userId);
    passwordPolicy.setChangeRequired(false);
    PasswordPolicyLocalServiceUtil.updatePasswordPolicy(passwordPolicy);

    if (_USERS_REMINDER_QUERIES_ENABLED) {
        user = UserLocalServiceUtil.updateReminderQuery(userId, StringPool.DASH, UUID.randomUUID().toString());
    }

    user = UserLocalServiceUtil.updateAgreedToTermsOfUse(userId, true);

    return user;
}

From source file:com.slemarchand.quick.sign.up.web.portlet.QuickSignUpPortlet.java

License:Open Source License

protected String getLogin(ThemeDisplay themeDisplay, ActionRequest actionRequest, User user)
        throws SystemException {

    Company company = themeDisplay.getCompany();

    String authType = company.getAuthType();

    String login;/*from www  .j av a  2  s  .c om*/

    if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
        login = user.getEmailAddress();
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
        login = user.getScreenName();
    } else {
        login = Long.toString(user.getUserId());
    }

    return login;
}