Search in sources :

Example 6 with User

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

the class UserLocalServiceImpl method deleteUser.

/**
 * Deletes the user.
 *
 * @param  user the user
 * @return the deleted user
 * @throws PortalException if a portal exception occurred
 * @throws SystemException if a system exception occurred
 */
@Override
public User deleteUser(User user) throws PortalException, SystemException {
    if (!PropsValues.USERS_DELETE) {
        throw new RequiredUserException();
    }
    // Browser tracker
    browserTrackerLocalService.deleteUserBrowserTracker(user.getUserId());
    // Group
    Group group = null;
    if (!user.isDefaultUser()) {
        group = user.getGroup();
    }
    if (group != null) {
        groupLocalService.deleteGroup(group);
    }
    try {
        imageLocalService.deleteImage(user.getPortraitId());
    } catch (NoSuchImageException nsie) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to delete image " + user.getPortraitId());
        }
    }
    // Password policy relation
    passwordPolicyRelLocalService.deletePasswordPolicyRel(User.class.getName(), user.getUserId());
    // Old passwords
    passwordTrackerLocalService.deletePasswordTrackers(user.getUserId());
    // Subscriptions
    subscriptionLocalService.deleteSubscriptions(user.getUserId());
    // External user ids
    userIdMapperLocalService.deleteUserIdMappers(user.getUserId());
    // Announcements
    announcementsDeliveryLocalService.deleteDeliveries(user.getUserId());
    // Asset
    assetEntryLocalService.deleteEntry(User.class.getName(), user.getUserId());
    // Blogs
    blogsStatsUserLocalService.deleteStatsUserByUserId(user.getUserId());
    // Document library
    dlFileRankLocalService.deleteFileRanksByUserId(user.getUserId());
    // Expando
    expandoRowLocalService.deleteRows(user.getUserId());
    // Message boards
    mbBanLocalService.deleteBansByBanUserId(user.getUserId());
    mbStatsUserLocalService.deleteStatsUsersByUserId(user.getUserId());
    mbThreadFlagLocalService.deleteThreadFlagsByUserId(user.getUserId());
    // Membership requests
    membershipRequestLocalService.deleteMembershipRequestsByUserId(user.getUserId());
    // Shopping cart
    shoppingCartLocalService.deleteUserCarts(user.getUserId());
    // Social
    socialActivityLocalService.deleteUserActivities(user.getUserId());
    socialRequestLocalService.deleteReceiverUserRequests(user.getUserId());
    socialRequestLocalService.deleteUserRequests(user.getUserId());
    // Mail
    mailService.deleteUser(user.getCompanyId(), user.getUserId());
    // Contact
    Contact contact = contactLocalService.fetchContact(user.getContactId());
    if (contact != null) {
        contactLocalService.deleteContact(contact);
    }
    // Group roles
    userGroupRoleLocalService.deleteUserGroupRolesByUserId(user.getUserId());
    // Resources
    resourceLocalService.deleteResource(user.getCompanyId(), User.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, user.getUserId());
    // User
    userPersistence.remove(user);
    // Permission cache
    PermissionCacheUtil.clearCache();
    // Workflow
    workflowInstanceLinkLocalService.deleteWorkflowInstanceLinks(user.getCompanyId(), 0, User.class.getName(), user.getUserId());
    return user;
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) User(com.liferay.portal.model.User) RequiredUserException(com.liferay.portal.RequiredUserException) NoSuchImageException(com.liferay.portal.NoSuchImageException) Contact(com.liferay.portal.model.Contact)

Example 7 with User

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

the class UserLocalServiceImpl method authenticateForDigest.

/**
 * Attempts to authenticate the user using HTTP digest access
 * authentication, without using the AuthPipeline. Primarily used for
 * authenticating users of <code>tunnel-web</code>.
 *
 * @param  companyId the primary key of the user's company
 * @param  username either the user's email address, screen name, or primary
 *         key
 * @param  realm unused
 * @param  nonce the number used once
 * @param  method the request method
 * @param  uri the request URI
 * @param  response the authentication response hash
 * @return the user's primary key if authentication is succesful;
 *         <code>0</code> otherwise
 * @throws PortalException if a portal exception occurred
 * @throws SystemException if a system exception occurred
 */
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public long authenticateForDigest(long companyId, String username, String realm, String nonce, String method, String uri, String response) throws PortalException, SystemException {
    if (PropsValues.AUTH_LOGIN_DISABLED) {
        return 0;
    }
    // Get User
    User user = fetchUserByEmailAddress(companyId, username);
    if (user == null) {
        user = fetchUserByScreenName(companyId, username);
    }
    if (user == null) {
        user = userPersistence.fetchByPrimaryKey(GetterUtil.getLong(username));
    }
    if (user == null) {
        return 0;
    }
    if (user.isDefaultUser()) {
        if (_log.isInfoEnabled()) {
            _log.info("Digest authentication is disabled for the default user");
        }
        return 0;
    } else if (!user.isActive()) {
        if (_log.isInfoEnabled()) {
            _log.info("Digest authentication is disabled for inactive user " + user.getUserId());
        }
        return 0;
    }
    // Verify digest
    String digest = user.getDigest();
    if (Validator.isNull(digest)) {
        _log.error("User must first login through the portal " + user.getUserId());
        return 0;
    }
    String[] digestArray = StringUtil.split(user.getDigest());
    for (String ha1 : digestArray) {
        String ha2 = DigesterUtil.digestHex(Digester.MD5, method, uri);
        String curResponse = DigesterUtil.digestHex(Digester.MD5, ha1, nonce, ha2);
        if (response.equals(curResponse)) {
            return user.getUserId();
        }
    }
    return 0;
}
Also used : User(com.liferay.portal.model.User) Transactional(com.liferay.portal.kernel.transaction.Transactional)

Example 8 with User

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

the class UserLocalServiceImpl method authenticateForBasic.

/**
 * Attempts to authenticate the user using HTTP basic access authentication,
 * without using the AuthPipeline. Primarily used for authenticating users
 * of <code>tunnel-web</code>.
 *
 * <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  authType the type of authentication to perform
 * @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
 * @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 a portal exception occurred
 * @throws SystemException if a system exception occurred
 */
@Override
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public long authenticateForBasic(long companyId, String authType, String login, String password) throws PortalException, SystemException {
    if (PropsValues.AUTH_LOGIN_DISABLED) {
        return 0;
    }
    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 0;
    }
    if (user.isDefaultUser()) {
        if (_log.isInfoEnabled()) {
            _log.info("Basic authentication is disabled for the default " + "user");
        }
        return 0;
    } else if (!user.isActive()) {
        if (_log.isInfoEnabled()) {
            _log.info("Basic authentication is disabled for inactive user " + user.getUserId());
        }
        return 0;
    }
    if (!PropsValues.BASIC_AUTH_PASSWORD_REQUIRED) {
        return user.getUserId();
    }
    String userPassword = user.getPassword();
    if (!user.isPasswordEncrypted()) {
        userPassword = PasswordEncryptorUtil.encrypt(userPassword);
    }
    String encPassword = PasswordEncryptorUtil.encrypt(password, userPassword);
    if (userPassword.equals(password) || userPassword.equals(encPassword)) {
        return user.getUserId();
    }
    return 0;
}
Also used : User(com.liferay.portal.model.User) Transactional(com.liferay.portal.kernel.transaction.Transactional)

Example 9 with User

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

the class UserLocalServiceImpl method updateEmailAddress.

/**
 * Updates the user's email address or sends verification email.
 *
 * @param  userId the primary key of the user
 * @param  password the user's password
 * @param  emailAddress1 the user's new email address
 * @param  emailAddress2 the user's new email address confirmation
 * @param  serviceContext the service context to be applied. Must set the
 *         portal URL, main path, primary key of the layout, remote address,
 *         remote host, and agent for the user.
 * @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 updateEmailAddress(long userId, String password, String emailAddress1, String emailAddress2, ServiceContext serviceContext) throws PortalException, SystemException {
    emailAddress1 = StringUtil.toLowerCase(emailAddress1.trim());
    emailAddress2 = StringUtil.toLowerCase(emailAddress2.trim());
    User user = userPersistence.findByPrimaryKey(userId);
    validateEmailAddress(user, emailAddress1, emailAddress2);
    Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
    if (!company.isStrangersVerify()) {
        setEmailAddress(user, password, user.getFirstName(), user.getMiddleName(), user.getLastName(), emailAddress1);
        userPersistence.update(user);
        Contact contact = user.getContact();
        contact.setEmailAddress(user.getEmailAddress());
        contactPersistence.update(contact);
    } else {
        sendEmailAddressVerification(user, emailAddress1, serviceContext);
    }
    return user;
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) Contact(com.liferay.portal.model.Contact)

Example 10 with User

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

the class UserLocalServiceImpl method getUserIds.

protected long[] getUserIds(List<User> users) {
    long[] userIds = new long[users.size()];
    for (int i = 0; i < users.size(); i++) {
        User user = users.get(i);
        userIds[i] = user.getUserId();
    }
    return userIds;
}
Also used : User(com.liferay.portal.model.User)

Aggregations

User (com.liferay.portal.model.User)97 Date (java.util.Date)22 SystemException (com.liferay.portal.kernel.exception.SystemException)17 Group (com.liferay.portal.model.Group)15 PortalException (com.liferay.portal.kernel.exception.PortalException)13 Company (com.liferay.portal.model.Company)11 ServiceContext (com.liferay.portal.service.ServiceContext)11 Indexable (com.liferay.portal.kernel.search.Indexable)10 UserGroup (com.liferay.portal.model.UserGroup)10 IOException (java.io.IOException)9 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)8 EncryptorException (com.liferay.util.EncryptorException)7 Song (org.liferay.jukebox.model.Song)7 Contact (com.liferay.portal.model.Contact)6 PrincipalException (com.liferay.portal.security.auth.PrincipalException)6 Album (org.liferay.jukebox.model.Album)6 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)5 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)5 NoSuchImageException (com.liferay.portal.NoSuchImageException)5 NoSuchOrganizationException (com.liferay.portal.NoSuchOrganizationException)5