use of com.liferay.portal.UserPasswordException in project liferay-ide by liferay.
the class UserLocalServiceImpl method authenticate.
/**
* Attempts to authenticate the user by their login and password, while
* using the AuthPipeline.
*
* <p>
* Authentication type specifies what <code>login</code> contains.The valid
* values are:
* </p>
*
* <ul>
* <li>
* <code>CompanyConstants.AUTH_TYPE_EA</code> - <code>login</code> is the
* user's email address
* </li>
* <li>
* <code>CompanyConstants.AUTH_TYPE_SN</code> - <code>login</code> is the
* user's screen name
* </li>
* <li>
* <code>CompanyConstants.AUTH_TYPE_ID</code> - <code>login</code> is the
* user's primary key
* </li>
* </ul>
*
* @param companyId the primary key of the user's company
* @param login either the user's email address, screen name, or primary
* key depending on the value of <code>authType</code>
* @param password the user's password
* @param authType the type of authentication to perform
* @param headerMap the header map from the authentication request
* @param parameterMap the parameter map from the authentication request
* @param resultsMap the map of authentication results (may be nil). After
* a succesful authentication the user's primary key will be placed
* under the key <code>userId</code>.
* @return the authentication status. This can be {@link
* com.liferay.portal.security.auth.Authenticator#FAILURE}
* indicating that the user's credentials are invalid, {@link
* com.liferay.portal.security.auth.Authenticator#SUCCESS}
* indicating a successful login, or {@link
* com.liferay.portal.security.auth.Authenticator#DNE} indicating
* that a user with that login does not exist.
* @throws PortalException if <code>login</code> or <code>password</code>
* was <code>null</code>
* @throws SystemException if a system exception occurred
* @see com.liferay.portal.security.auth.AuthPipeline
*/
protected int authenticate(long companyId, String login, String password, String authType, Map<String, String[]> headerMap, Map<String, String[]> parameterMap, Map<String, Object> resultsMap) throws PortalException, SystemException {
if (PropsValues.AUTH_LOGIN_DISABLED) {
return Authenticator.FAILURE;
}
login = StringUtil.toLowerCase(login.trim());
long userId = GetterUtil.getLong(login);
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
if (Validator.isNull(login)) {
throw new UserEmailAddressException();
}
} else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
if (Validator.isNull(login)) {
throw new UserScreenNameException();
}
} else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
if (Validator.isNull(login)) {
throw new UserIdException();
}
}
if (Validator.isNull(password)) {
throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
}
int authResult = Authenticator.FAILURE;
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
authResult = AuthPipeline.authenticateByEmailAddress(PropsKeys.AUTH_PIPELINE_PRE, companyId, login, password, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
authResult = AuthPipeline.authenticateByScreenName(PropsKeys.AUTH_PIPELINE_PRE, companyId, login, password, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
authResult = AuthPipeline.authenticateByUserId(PropsKeys.AUTH_PIPELINE_PRE, companyId, userId, password, headerMap, parameterMap);
}
// Get user
User user = null;
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
user = fetchUserByEmailAddress(companyId, login);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
user = fetchUserByScreenName(companyId, login);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
user = userPersistence.fetchByPrimaryKey(GetterUtil.getLong(login));
}
if (user == null) {
return Authenticator.DNE;
}
if (user.isDefaultUser()) {
if (_log.isInfoEnabled()) {
_log.info("Authentication is disabled for the default user");
}
return Authenticator.DNE;
} else if (!user.isActive()) {
if (_log.isInfoEnabled()) {
_log.info("Authentication is disabled for inactive user " + user.getUserId());
}
return Authenticator.FAILURE;
}
if (!user.isPasswordEncrypted()) {
user.setPassword(PasswordEncryptorUtil.encrypt(user.getPassword()));
user.setPasswordEncrypted(true);
userPersistence.update(user);
}
// Check password policy to see if the is account locked out or if the
// password is expired
checkLockout(user);
checkPasswordExpired(user);
// Authenticate against the User_ table
boolean skipLiferayCheck = false;
if (authResult == Authenticator.SKIP_LIFERAY_CHECK) {
authResult = Authenticator.SUCCESS;
skipLiferayCheck = true;
} else if ((authResult == Authenticator.SUCCESS) && PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK) {
boolean authenticated = PwdAuthenticator.authenticate(login, password, user.getPassword());
if (authenticated) {
authResult = Authenticator.SUCCESS;
} else {
authResult = Authenticator.FAILURE;
}
}
if (authResult == Authenticator.SUCCESS) {
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
authResult = AuthPipeline.authenticateByEmailAddress(PropsKeys.AUTH_PIPELINE_POST, companyId, login, password, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
authResult = AuthPipeline.authenticateByScreenName(PropsKeys.AUTH_PIPELINE_POST, companyId, login, password, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
authResult = AuthPipeline.authenticateByUserId(PropsKeys.AUTH_PIPELINE_POST, companyId, userId, password, headerMap, parameterMap);
}
}
if (authResult == Authenticator.SUCCESS) {
if (resultsMap != null) {
resultsMap.put("userId", user.getUserId());
}
if (skipLiferayCheck || !PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK || Validator.isNull(user.getDigest())) {
String digest = user.getDigest(password);
user.setDigest(digest);
userPersistence.update(user);
}
}
if (authResult == Authenticator.FAILURE) {
try {
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
AuthPipeline.onFailureByEmailAddress(PropsKeys.AUTH_FAILURE, companyId, login, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
AuthPipeline.onFailureByScreenName(PropsKeys.AUTH_FAILURE, companyId, login, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
AuthPipeline.onFailureByUserId(PropsKeys.AUTH_FAILURE, companyId, userId, headerMap, parameterMap);
}
user = userPersistence.fetchByPrimaryKey(user.getUserId());
if (user == null) {
return Authenticator.DNE;
}
if (!LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
PasswordPolicy passwordPolicy = user.getPasswordPolicy();
user = userPersistence.fetchByPrimaryKey(user.getUserId());
int failedLoginAttempts = user.getFailedLoginAttempts();
int maxFailures = passwordPolicy.getMaxFailure();
if ((failedLoginAttempts >= maxFailures) && (maxFailures != 0)) {
if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
AuthPipeline.onMaxFailuresByEmailAddress(PropsKeys.AUTH_MAX_FAILURES, companyId, login, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
AuthPipeline.onMaxFailuresByScreenName(PropsKeys.AUTH_MAX_FAILURES, companyId, login, headerMap, parameterMap);
} else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
AuthPipeline.onMaxFailuresByUserId(PropsKeys.AUTH_MAX_FAILURES, companyId, userId, headerMap, parameterMap);
}
}
}
} catch (Exception e) {
_log.error(e, e);
}
}
return authResult;
}
use of com.liferay.portal.UserPasswordException in project liferay-ide by liferay.
the class UserLocalServiceImpl method updatePassword.
/**
* Updates the user's password, optionally with tracking and validation of
* the change.
*
* @param userId the primary key of the user
* @param password1 the user's new password
* @param password2 the user's new password confirmation
* @param passwordReset whether the user should be asked to reset their
* password the next time they login
* @param silentUpdate whether the password should be updated without being
* tracked, or validated. Primarily used for password imports.
* @return the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public User updatePassword(long userId, String password1, String password2, boolean passwordReset, boolean silentUpdate) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
if (!silentUpdate) {
validatePassword(user.getCompanyId(), userId, password1, password2);
}
String oldEncPwd = user.getPassword();
if (!user.isPasswordEncrypted()) {
oldEncPwd = PasswordEncryptorUtil.encrypt(user.getPassword());
}
String newEncPwd = PasswordEncryptorUtil.encrypt(password1);
if (user.hasCompanyMx()) {
mailService.updatePassword(user.getCompanyId(), userId, password1);
}
user.setPassword(newEncPwd);
user.setPasswordUnencrypted(password1);
user.setPasswordEncrypted(true);
user.setPasswordReset(passwordReset);
user.setPasswordModifiedDate(new Date());
user.setDigest(StringPool.BLANK);
user.setGraceLoginCount(0);
if (!silentUpdate) {
user.setPasswordModified(true);
}
try {
userPersistence.update(user);
} catch (ModelListenerException mle) {
String msg = GetterUtil.getString(mle.getCause().getMessage());
if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
String passwordHistory = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.LDAP_ERROR_PASSWORD_HISTORY);
if (msg.contains(passwordHistory)) {
throw new UserPasswordException(UserPasswordException.PASSWORD_ALREADY_USED);
}
}
throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
}
if (!silentUpdate) {
user.setPasswordModified(false);
passwordTrackerLocalService.trackPassword(userId, oldEncPwd);
}
return user;
}
use of com.liferay.portal.UserPasswordException in project liferay-ide by liferay.
the class UserLocalServiceImpl method addUserWithWorkflow.
/**
* Adds a user with workflow.
*
* <p>
* This method handles the creation and bookkeeping of the user including
* its resources, metadata, and internal data structures. It is not
* necessary to make subsequent calls to any methods to setup default
* groups, resources, etc.
* </p>
*
* @param creatorUserId the primary key of the creator
* @param companyId the primary key of the user's company
* @param autoPassword whether a password should be automatically generated
* for the user
* @param password1 the user's password
* @param password2 the user's password confirmation
* @param autoScreenName whether a screen name should be automatically
* generated for the user
* @param screenName the user's screen name
* @param emailAddress the user's email address
* @param facebookId the user's facebook ID
* @param openId the user's OpenID
* @param locale the user's locale
* @param firstName the user's first name
* @param middleName the user's middle name
* @param lastName the user's last name
* @param prefixId the user's name prefix ID
* @param suffixId the user's name suffix ID
* @param male whether the user is male
* @param birthdayMonth the user's birthday month (0-based, meaning 0 for
* January)
* @param birthdayDay the user's birthday day
* @param birthdayYear the user's birthday year
* @param jobTitle the user's job title
* @param groupIds the primary keys of the user's groups
* @param organizationIds the primary keys of the user's organizations
* @param roleIds the primary keys of the roles this user possesses
* @param userGroupIds the primary keys of the user's user groups
* @param sendEmail whether to send the user an email notification about
* their new account
* @param serviceContext the service context to be applied (optionally
* <code>null</code>). Can set the UUID (with the <code>uuid</code>
* attribute), asset category IDs, asset tag names, and expando
* bridge attributes for the user.
* @return the new user
* @throws PortalException if the user's information was invalid
* @throws SystemException if a system exception occurred
*/
@Override
@SuppressWarnings("deprecation")
public User addUserWithWorkflow(long creatorUserId, long companyId, boolean autoPassword, String password1, String password2, boolean autoScreenName, String screenName, String emailAddress, long facebookId, String openId, Locale locale, String firstName, String middleName, String lastName, int prefixId, int suffixId, boolean male, int birthdayMonth, int birthdayDay, int birthdayYear, String jobTitle, long[] groupIds, long[] organizationIds, long[] roleIds, long[] userGroupIds, boolean sendEmail, ServiceContext serviceContext) throws PortalException, SystemException {
// User
Company company = companyPersistence.findByPrimaryKey(companyId);
screenName = getLogin(screenName);
openId = StringUtil.trim(openId);
Date now = new Date();
if (PrefsPropsUtil.getBoolean(companyId, PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE)) {
autoScreenName = true;
}
// PLACEHOLDER 01
long userId = counterLocalService.increment();
EmailAddressGenerator emailAddressGenerator = EmailAddressGeneratorFactory.getInstance();
if ((emailAddress == null) || emailAddressGenerator.isGenerated(emailAddress)) {
emailAddress = StringPool.BLANK;
} else {
emailAddress = StringUtil.toLowerCase(emailAddress.trim());
}
if (!PrefsPropsUtil.getBoolean(companyId, PropsKeys.USERS_EMAIL_ADDRESS_REQUIRED) && Validator.isNull(emailAddress)) {
emailAddress = emailAddressGenerator.generate(companyId, userId);
}
validate(companyId, userId, autoPassword, password1, password2, autoScreenName, screenName, emailAddress, openId, firstName, middleName, lastName, organizationIds);
if (!autoPassword) {
if (Validator.isNull(password1) || Validator.isNull(password2)) {
throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
}
}
if (autoScreenName) {
ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();
try {
screenName = screenNameGenerator.generate(companyId, userId, emailAddress);
} catch (Exception e) {
throw new SystemException(e);
}
}
User defaultUser = getDefaultUser(companyId);
FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();
String fullName = fullNameGenerator.getFullName(firstName, middleName, lastName);
String greeting = LanguageUtil.format(locale, "welcome-x", " " + fullName, false);
User user = userPersistence.create(userId);
if (serviceContext != null) {
String uuid = serviceContext.getUuid();
if (Validator.isNotNull(uuid)) {
user.setUuid(uuid);
}
}
user.setCompanyId(companyId);
user.setCreateDate(now);
user.setModifiedDate(now);
user.setDefaultUser(false);
user.setContactId(counterLocalService.increment());
if (Validator.isNotNull(password1)) {
user.setPassword(PasswordEncryptorUtil.encrypt(password1));
user.setPasswordUnencrypted(password1);
}
user.setPasswordEncrypted(true);
PasswordPolicy passwordPolicy = defaultUser.getPasswordPolicy();
boolean passwordReset = false;
if (passwordPolicy != null) {
if (passwordPolicy.isChangeable() && passwordPolicy.isChangeRequired()) {
passwordReset = true;
}
addPasswordPolicyUsers(passwordPolicy.getPasswordPolicyId(), new long[] { userId });
}
user.setPasswordReset(passwordReset);
user.setDigest(StringPool.BLANK);
user.setScreenName(screenName);
user.setEmailAddress(emailAddress);
user.setFacebookId(facebookId);
Long ldapServerId = (Long) serviceContext.getAttribute("ldapServerId");
if (ldapServerId != null) {
user.setLdapServerId(ldapServerId);
} else {
user.setLdapServerId(-1);
}
user.setOpenId(openId);
user.setLanguageId(LocaleUtil.toLanguageId(locale));
user.setTimeZoneId(defaultUser.getTimeZoneId());
user.setGreeting(greeting);
user.setFirstName(firstName);
user.setMiddleName(middleName);
user.setLastName(lastName);
user.setJobTitle(jobTitle);
user.setStatus(WorkflowConstants.STATUS_DRAFT);
user.setExpandoBridgeAttributes(serviceContext);
userPersistence.update(user, serviceContext);
// Contact
String creatorUserName = StringPool.BLANK;
if (creatorUserId <= 0) {
creatorUserId = user.getUserId();
// Don't grab the full name from the User object because it doesn't
// have a corresponding Contact object yet
// creatorUserName = user.getFullName();
} else {
User creatorUser = userPersistence.findByPrimaryKey(creatorUserId);
creatorUserName = creatorUser.getFullName();
}
Date birthday = getBirthday(birthdayMonth, birthdayDay, birthdayYear);
Contact contact = contactPersistence.create(user.getContactId());
contact.setCompanyId(user.getCompanyId());
contact.setUserId(creatorUserId);
contact.setUserName(creatorUserName);
contact.setCreateDate(now);
contact.setModifiedDate(now);
contact.setClassName(User.class.getName());
contact.setClassPK(user.getUserId());
contact.setAccountId(company.getAccountId());
contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID);
contact.setEmailAddress(user.getEmailAddress());
contact.setFirstName(firstName);
contact.setMiddleName(middleName);
contact.setLastName(lastName);
contact.setPrefixId(prefixId);
contact.setSuffixId(suffixId);
contact.setMale(male);
contact.setBirthday(birthday);
contact.setJobTitle(jobTitle);
contactPersistence.update(contact, serviceContext);
// Group
groupLocalService.addGroup(user.getUserId(), GroupConstants.DEFAULT_PARENT_GROUP_ID, User.class.getName(), user.getUserId(), null, null, 0, StringPool.SLASH + screenName, false, true, null);
if (groupIds != null) {
List<Group> groups = new ArrayList<Group>();
for (long groupId : groupIds) {
Group group = groupLocalService.fetchGroup(groupId);
if (group != null) {
groups.add(group);
} else {
if (_log.isWarnEnabled()) {
_log.warn("Group " + groupId + " does not exist");
}
}
}
groupLocalService.addUserGroups(userId, groups);
}
addDefaultGroups(userId);
// Organizations
updateOrganizations(userId, organizationIds, false);
if (roleIds != null) {
roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
userPersistence.setRoles(userId, roleIds);
}
addDefaultRoles(userId);
if (userGroupIds != null) {
if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
for (long userGroupId : userGroupIds) {
userGroupLocalService.copyUserGroupLayouts(userGroupId, new long[] { userId });
}
}
userPersistence.setUserGroups(userId, userGroupIds);
}
addDefaultUserGroups(userId);
// Resources
resourceLocalService.addResources(companyId, 0, creatorUserId, User.class.getName(), user.getUserId(), false, false, false);
if (serviceContext != null) {
updateAsset(creatorUserId, user, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());
}
if ((serviceContext == null) || serviceContext.isIndexingEnabled()) {
reindex(user);
}
// Workflow
long workflowUserId = creatorUserId;
if (workflowUserId == userId) {
workflowUserId = defaultUser.getUserId();
}
ServiceContext workflowServiceContext = serviceContext;
if (workflowServiceContext == null) {
workflowServiceContext = new ServiceContext();
}
workflowServiceContext.setAttribute("autoPassword", autoPassword);
workflowServiceContext.setAttribute("passwordUnencrypted", password1);
workflowServiceContext.setAttribute("sendEmail", sendEmail);
WorkflowHandlerRegistryUtil.startWorkflowInstance(companyId, workflowUserId, User.class.getName(), userId, user, workflowServiceContext);
if (serviceContext != null) {
String passwordUnencrypted = (String) serviceContext.getAttribute("passwordUnencrypted");
if (Validator.isNotNull(passwordUnencrypted)) {
user.setPasswordUnencrypted(passwordUnencrypted);
}
}
return user;
}
use of com.liferay.portal.UserPasswordException in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateIncompleteUser.
/**
* Updates a user account that was automatically created when a guest user
* participated in an action (e.g. posting a comment) and only provided his
* name and email address.
*
* @param creatorUserId the primary key of the creator
* @param companyId the primary key of the user's company
* @param autoPassword whether a password should be automatically generated
* for the user
* @param password1 the user's password
* @param password2 the user's password confirmation
* @param autoScreenName whether a screen name should be automatically
* generated for the user
* @param screenName the user's screen name
* @param emailAddress the user's email address
* @param facebookId the user's facebook ID
* @param openId the user's OpenID
* @param locale the user's locale
* @param firstName the user's first name
* @param middleName the user's middle name
* @param lastName the user's last name
* @param prefixId the user's name prefix ID
* @param suffixId the user's name suffix ID
* @param male whether the user is male
* @param birthdayMonth the user's birthday month (0-based, meaning 0 for
* January)
* @param birthdayDay the user's birthday day
* @param birthdayYear the user's birthday year
* @param jobTitle the user's job title
* @param updateUserInformation whether to update the user's information
* @param sendEmail whether to send the user an email notification about
* their new account
* @param serviceContext the service context to be applied (optionally
* <code>null</code>). Can set expando bridge attributes for the
* user.
* @return the user
* @throws PortalException if the user's information was invalid
* @throws SystemException if a system exception occurred
*/
@Override
public User updateIncompleteUser(long creatorUserId, long companyId, boolean autoPassword, String password1, String password2, boolean autoScreenName, String screenName, String emailAddress, long facebookId, String openId, Locale locale, String firstName, String middleName, String lastName, int prefixId, int suffixId, boolean male, int birthdayMonth, int birthdayDay, int birthdayYear, String jobTitle, boolean updateUserInformation, boolean sendEmail, ServiceContext serviceContext) throws PortalException, SystemException {
User user = getUserByEmailAddress(companyId, emailAddress);
if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
throw new PortalException("Invalid user status");
}
User defaultUser = getDefaultUser(companyId);
if (facebookId > 0) {
autoPassword = false;
if ((password1 == null) || (password2 == null)) {
password1 = PwdGenerator.getPassword();
password2 = password1;
}
sendEmail = false;
}
if (updateUserInformation) {
autoScreenName = false;
if (PrefsPropsUtil.getBoolean(companyId, PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE)) {
autoScreenName = true;
}
validate(companyId, user.getUserId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, openId, firstName, middleName, lastName, null);
if (!autoPassword) {
if (Validator.isNull(password1) || Validator.isNull(password2)) {
throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
}
}
if (autoScreenName) {
ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();
try {
screenName = screenNameGenerator.generate(companyId, user.getUserId(), emailAddress);
} catch (Exception e) {
throw new SystemException(e);
}
}
FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();
String fullName = fullNameGenerator.getFullName(firstName, middleName, lastName);
String greeting = LanguageUtil.format(locale, "welcome-x", " " + fullName, false);
if (Validator.isNotNull(password1)) {
user.setPassword(PasswordEncryptorUtil.encrypt(password1));
user.setPasswordUnencrypted(password1);
}
user.setPasswordEncrypted(true);
PasswordPolicy passwordPolicy = defaultUser.getPasswordPolicy();
if ((passwordPolicy != null) && passwordPolicy.isChangeable() && passwordPolicy.isChangeRequired()) {
user.setPasswordReset(true);
} else {
user.setPasswordReset(false);
}
user.setScreenName(screenName);
user.setFacebookId(facebookId);
user.setOpenId(openId);
user.setLanguageId(locale.toString());
user.setTimeZoneId(defaultUser.getTimeZoneId());
user.setGreeting(greeting);
user.setFirstName(firstName);
user.setMiddleName(middleName);
user.setLastName(lastName);
user.setJobTitle(jobTitle);
user.setExpandoBridgeAttributes(serviceContext);
Date birthday = getBirthday(birthdayMonth, birthdayDay, birthdayYear);
Contact contact = user.getContact();
contact.setFirstName(firstName);
contact.setMiddleName(middleName);
contact.setLastName(lastName);
contact.setPrefixId(prefixId);
contact.setSuffixId(suffixId);
contact.setMale(male);
contact.setBirthday(birthday);
contact.setJobTitle(jobTitle);
contactPersistence.update(contact, serviceContext);
// Indexer
Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
indexer.reindex(user);
}
user.setStatus(WorkflowConstants.STATUS_DRAFT);
userPersistence.update(user, serviceContext);
// Workflow
long workflowUserId = creatorUserId;
if (workflowUserId == user.getUserId()) {
workflowUserId = defaultUser.getUserId();
}
ServiceContext workflowServiceContext = serviceContext;
if (workflowServiceContext == null) {
workflowServiceContext = new ServiceContext();
}
workflowServiceContext.setAttribute("autoPassword", autoPassword);
workflowServiceContext.setAttribute("passwordUnencrypted", password1);
workflowServiceContext.setAttribute("sendEmail", sendEmail);
WorkflowHandlerRegistryUtil.startWorkflowInstance(companyId, workflowUserId, User.class.getName(), user.getUserId(), user, workflowServiceContext);
return getUserByEmailAddress(companyId, emailAddress);
}
use of com.liferay.portal.UserPasswordException 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);
}
Aggregations