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;
}
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;
}
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;
}
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);
}
}
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();
}
}
Aggregations