Search in sources :

Example 11 with PasswordPolicy

use of com.liferay.portal.model.PasswordPolicy in project liferay-ide by liferay.

the class UserLocalServiceImpl method checkPasswordExpired.

/**
 * Checks if the user's password is expired based on the password policy,
 * and performs maintenance on the user's grace login and password reset
 * data.
 *
 * @param  user the user
 * @throws PortalException if the user's password has expired and the grace
 *         login limit has been exceeded
 * @throws SystemException if a system exception occurred
 */
@Override
public void checkPasswordExpired(User user) throws PortalException, SystemException {
    if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
        return;
    }
    PasswordPolicy passwordPolicy = user.getPasswordPolicy();
    if (isPasswordExpired(user)) {
        int graceLoginCount = user.getGraceLoginCount();
        if (graceLoginCount < passwordPolicy.getGraceLimit()) {
            user.setGraceLoginCount(++graceLoginCount);
            userPersistence.update(user);
        } else {
            user.setDigest(StringPool.BLANK);
            userPersistence.update(user);
            throw new PasswordExpiredException();
        }
    }
    if (passwordPolicy.isChangeable() && passwordPolicy.isChangeRequired()) {
        if (user.getLastLoginDate() == null) {
            user.setPasswordReset(true);
            userPersistence.update(user);
        }
    }
}
Also used : PasswordExpiredException(com.liferay.portal.PasswordExpiredException) PasswordPolicy(com.liferay.portal.model.PasswordPolicy)

Example 12 with PasswordPolicy

use of com.liferay.portal.model.PasswordPolicy in project liferay-ide by liferay.

the class UserLocalServiceImpl method validatePassword.

protected void validatePassword(long companyId, long userId, String password1, String password2) throws PortalException, SystemException {
    if (Validator.isNull(password1) || Validator.isNull(password2)) {
        throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
    }
    if (!password1.equals(password2)) {
        throw new UserPasswordException(UserPasswordException.PASSWORDS_DO_NOT_MATCH);
    }
    PasswordPolicy passwordPolicy = passwordPolicyLocalService.getPasswordPolicyByUserId(userId);
    PwdToolkitUtil.validate(companyId, userId, password1, password2, passwordPolicy);
}
Also used : UserPasswordException(com.liferay.portal.UserPasswordException) PasswordPolicy(com.liferay.portal.model.PasswordPolicy)

Aggregations

PasswordPolicy (com.liferay.portal.model.PasswordPolicy)12 Date (java.util.Date)8 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)5 User (com.liferay.portal.model.User)5 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)4 PasswordExpiredException (com.liferay.portal.PasswordExpiredException)4 ReservedUserEmailAddressException (com.liferay.portal.ReservedUserEmailAddressException)4 UserEmailAddressException (com.liferay.portal.UserEmailAddressException)4 UserLockoutException (com.liferay.portal.UserLockoutException)4 UserPasswordException (com.liferay.portal.UserPasswordException)4 CompanyMaxUsersException (com.liferay.portal.CompanyMaxUsersException)3 ContactBirthdayException (com.liferay.portal.ContactBirthdayException)3 ContactFirstNameException (com.liferay.portal.ContactFirstNameException)3 ContactFullNameException (com.liferay.portal.ContactFullNameException)3 ContactLastNameException (com.liferay.portal.ContactLastNameException)3 DuplicateOpenIdException (com.liferay.portal.DuplicateOpenIdException)3 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)3 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)3 ModelListenerException (com.liferay.portal.ModelListenerException)3 NoSuchImageException (com.liferay.portal.NoSuchImageException)3