Search in sources :

Example 1 with User

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

the class WebServerServlet method getImageId.

protected long getImageId(HttpServletRequest request) {
    // The image id may be passed in as image_id, img_id, or i_id
    long imageId = ParamUtil.getLong(request, "image_id");
    if (imageId <= 0) {
        imageId = ParamUtil.getLong(request, "img_id");
    }
    if (imageId <= 0) {
        imageId = ParamUtil.getLong(request, "i_id");
    }
    if (imageId <= 0) {
        long companyId = ParamUtil.getLong(request, "companyId");
        String screenName = ParamUtil.getString(request, "screenName");
        try {
            if ((companyId > 0) && Validator.isNotNull(screenName)) {
                User user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName);
                imageId = user.getPortraitId();
            }
        } catch (Exception e) {
        }
    }
    return imageId;
}
Also used : User(com.liferay.portal.model.User) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 2 with User

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

the class WebServerServlet method getUserPortraitImageResized.

protected Image getUserPortraitImageResized(Image image, long imageId) throws PortalException, SystemException {
    if (image == null) {
        return null;
    }
    if ((image.getHeight() > PropsValues.USERS_IMAGE_MAX_HEIGHT) || (image.getWidth() > PropsValues.USERS_IMAGE_MAX_WIDTH)) {
        User user = UserLocalServiceUtil.getUserByPortraitId(imageId);
        UserLocalServiceUtil.updatePortrait(user.getUserId(), image.getTextObj());
        return ImageLocalServiceUtil.getImage(imageId);
    }
    return image;
}
Also used : User(com.liferay.portal.model.User)

Example 3 with User

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

the class WebServerServlet method hasFiles.

/**
 * @see com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter
 */
public static boolean hasFiles(HttpServletRequest request) {
    try {
        // Do not use permission checking since this may be called from
        // other contexts that are also managing the principal
        User user = _getUser(request);
        String path = HttpUtil.fixPath(request.getPathInfo());
        String[] pathArray = StringUtil.split(path, CharPool.SLASH);
        if (pathArray.length == 0) {
            return true;
        } else if (_PATH_DDL.equals(pathArray[0])) {
            _checkDDLRecord(pathArray);
        } else if (Validator.isNumber(pathArray[0])) {
            _checkFileEntry(pathArray);
        } else {
            long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
            long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
            for (int i = 1; i < pathArray.length; i++) {
                try {
                    Folder folder = DLAppLocalServiceUtil.getFolder(groupId, folderId, pathArray[i]);
                    folderId = folder.getFolderId();
                } catch (NoSuchFolderException nsfe) {
                    if (i != pathArray.length - 1) {
                        return false;
                    }
                    pathArray = new String[] { String.valueOf(groupId), String.valueOf(folderId), pathArray[i] };
                    _checkFileEntry(pathArray);
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) User(com.liferay.portal.model.User) Folder(com.liferay.portal.kernel.repository.model.Folder) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 4 with User

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

the class WebServerServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    User user = null;
    try {
        user = _getUser(request);
        PrincipalThreadLocal.setName(user.getUserId());
        PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(request));
        PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, true);
        PermissionThreadLocal.setPermissionChecker(permissionChecker);
        if (_lastModified) {
            long lastModified = getLastModified(request);
            if (lastModified > 0) {
                long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
                if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) {
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
            }
            if (lastModified > 0) {
                response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified);
            }
        }
        String path = HttpUtil.fixPath(request.getPathInfo());
        String[] pathArray = StringUtil.split(path, CharPool.SLASH);
        if (pathArray.length == 0) {
            sendGroups(response, user, request.getServletPath() + StringPool.SLASH + path);
        } else {
            if (_PATH_DDL.equals(pathArray[0])) {
                sendDDLRecordFile(request, response, pathArray);
            } else if (Validator.isNumber(pathArray[0])) {
                sendFile(request, response, user, pathArray);
            } else {
                if (isLegacyImageGalleryImageId(request, response)) {
                    return;
                }
                Image image = getImage(request, true);
                if (image != null) {
                    writeImage(image, request, response);
                } else {
                    sendDocumentLibrary(request, response, user, request.getServletPath() + StringPool.SLASH + path, pathArray);
                }
            }
        }
    } catch (NoSuchFileEntryException nsfee) {
        PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response);
    } catch (PrincipalException pe) {
        processPrincipalException(pe, user, request, response);
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);
    }
}
Also used : User(com.liferay.portal.model.User) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) Image(com.liferay.portal.model.Image) RenderedImage(java.awt.image.RenderedImage) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 5 with User

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

the class UserLocalServiceImpl method decryptUserId.

/**
 * Decrypts the user's primary key and password from their encrypted forms.
 * Used for decrypting a user's credentials from the values stored in an
 * automatic login cookie.
 *
 * @param  companyId the primary key of the user's company
 * @param  name the encrypted primary key of the user
 * @param  password the encrypted password of the user
 * @return the user's primary key and password
 * @throws PortalException if a user with the primary key could not be found
 *         or if the user's password was incorrect
 * @throws SystemException if a system exception occurred
 */
@Override
public KeyValuePair decryptUserId(long companyId, String name, String password) throws PortalException, SystemException {
    Company company = companyPersistence.findByPrimaryKey(companyId);
    try {
        name = Encryptor.decrypt(company.getKeyObj(), name);
    } catch (EncryptorException ee) {
        throw new SystemException(ee);
    }
    long userId = GetterUtil.getLong(name);
    User user = userPersistence.findByPrimaryKey(userId);
    try {
        password = Encryptor.decrypt(company.getKeyObj(), password);
    } catch (EncryptorException ee) {
        throw new SystemException(ee);
    }
    String userPassword = user.getPassword();
    String encPassword = PasswordEncryptorUtil.encrypt(password, userPassword);
    if (userPassword.equals(encPassword)) {
        if (isPasswordExpired(user)) {
            user.setPasswordReset(true);
            userPersistence.update(user);
        }
        return new KeyValuePair(name, password);
    } else {
        throw new PrincipalException();
    }
}
Also used : Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) EncryptorException(com.liferay.util.EncryptorException) SystemException(com.liferay.portal.kernel.exception.SystemException) KeyValuePair(com.liferay.portal.kernel.util.KeyValuePair) PrincipalException(com.liferay.portal.security.auth.PrincipalException)

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