Search in sources :

Example 1 with ReservedUserScreenNameException

use of com.liferay.portal.ReservedUserScreenNameException in project liferay-ide by liferay.

the class UserLocalServiceImpl method validateScreenName.

protected void validateScreenName(long companyId, long userId, String screenName) throws PortalException, SystemException {
    if (Validator.isNull(screenName)) {
        throw new UserScreenNameException();
    }
    ScreenNameValidator screenNameValidator = ScreenNameValidatorFactory.getInstance();
    if (!screenNameValidator.validate(companyId, screenName)) {
        throw new UserScreenNameException();
    }
    if (Validator.isNumber(screenName)) {
        if (!PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) {
            throw new UserScreenNameException();
        }
        if (!screenName.equals(String.valueOf(userId))) {
            Group group = groupPersistence.fetchByPrimaryKey(GetterUtil.getLong(screenName));
            if (group != null) {
                throw new UserScreenNameException();
            }
        }
    }
    for (char c : screenName.toCharArray()) {
        if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.PERIOD) && (c != CharPool.UNDERLINE)) {
            throw new UserScreenNameException();
        }
    }
    String[] anonymousNames = BaseServiceImpl.ANONYMOUS_NAMES;
    for (String anonymousName : anonymousNames) {
        if (StringUtil.equalsIgnoreCase(screenName, anonymousName)) {
            throw new UserScreenNameException();
        }
    }
    User user = userPersistence.fetchByC_SN(companyId, screenName);
    if ((user != null) && (user.getUserId() != userId)) {
        throw new DuplicateUserScreenNameException("{userId=" + userId + "}");
    }
    String friendlyURL = StringPool.SLASH + screenName;
    Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);
    if ((group != null) && (group.getClassPK() != userId)) {
        throw new GroupFriendlyURLException(GroupFriendlyURLException.DUPLICATE);
    }
    int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);
    if (exceptionType != -1) {
        throw new UserScreenNameException(new GroupFriendlyURLException(exceptionType));
    }
    String[] reservedScreenNames = PrefsPropsUtil.getStringArray(companyId, PropsKeys.ADMIN_RESERVED_SCREEN_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_RESERVED_SCREEN_NAMES);
    for (String reservedScreenName : reservedScreenNames) {
        if (StringUtil.equalsIgnoreCase(screenName, reservedScreenName)) {
            throw new ReservedUserScreenNameException();
        }
    }
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) GroupFriendlyURLException(com.liferay.portal.GroupFriendlyURLException) ScreenNameValidator(com.liferay.portal.security.auth.ScreenNameValidator) User(com.liferay.portal.model.User) DuplicateUserScreenNameException(com.liferay.portal.DuplicateUserScreenNameException) ReservedUserScreenNameException(com.liferay.portal.ReservedUserScreenNameException) ReservedUserScreenNameException(com.liferay.portal.ReservedUserScreenNameException) DuplicateUserScreenNameException(com.liferay.portal.DuplicateUserScreenNameException) UserScreenNameException(com.liferay.portal.UserScreenNameException)

Aggregations

DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)1 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)1 ReservedUserScreenNameException (com.liferay.portal.ReservedUserScreenNameException)1 UserScreenNameException (com.liferay.portal.UserScreenNameException)1 Group (com.liferay.portal.model.Group)1 User (com.liferay.portal.model.User)1 UserGroup (com.liferay.portal.model.UserGroup)1 ScreenNameValidator (com.liferay.portal.security.auth.ScreenNameValidator)1