use of com.liferay.portal.security.auth.PrincipalException in project liferay-ide by liferay.
the class AdminPortlet method render.
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
try {
int status = WorkflowConstants.STATUS_ANY;
renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);
KBArticle kbArticle = null;
long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());
long resourceClassNameId = ParamUtil.getLong(renderRequest, "resourceClassNameId", kbArticleClassNameId);
long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey");
if ((resourcePrimKey > 0) && (resourceClassNameId == kbArticleClassNameId)) {
kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
}
renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
KBTemplate kbTemplate = null;
long kbTemplateId = ParamUtil.getLong(renderRequest, "kbTemplateId");
if (kbTemplateId > 0) {
kbTemplate = KBTemplateServiceUtil.getKBTemplate(kbTemplateId);
}
renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_TEMPLATE, kbTemplate);
} catch (Exception e) {
if (e instanceof NoSuchArticleException || e instanceof NoSuchTemplateException || e instanceof PrincipalException) {
SessionErrors.add(renderRequest, e.getClass());
} else {
throw new PortletException(e);
}
}
super.render(renderRequest, renderResponse);
}
use of com.liferay.portal.security.auth.PrincipalException in project liferay-ide by liferay.
the class WebServerServlet method getLastModified.
@Override
protected long getLastModified(HttpServletRequest request) {
try {
Date modifiedDate = null;
Image image = getImage(request, true);
if (image != null) {
modifiedDate = image.getModifiedDate();
} else {
String path = HttpUtil.fixPath(request.getPathInfo());
String[] pathArray = StringUtil.split(path, CharPool.SLASH);
if (pathArray.length == 0) {
return -1;
}
if (pathArray[0].equals("language")) {
return -1;
}
FileEntry fileEntry = null;
try {
fileEntry = getFileEntry(pathArray);
} catch (Exception e) {
}
if (fileEntry == null) {
return -1;
} else {
String version = ParamUtil.getString(request, "version");
if (Validator.isNotNull(version)) {
FileVersion fileVersion = fileEntry.getFileVersion(version);
modifiedDate = fileVersion.getModifiedDate();
} else {
modifiedDate = fileEntry.getModifiedDate();
}
}
}
if (modifiedDate == null) {
modifiedDate = PortalUtil.getUptime();
}
return (modifiedDate.getTime() / 1000) * 1000;
} catch (PrincipalException pe) {
if (_log.isWarnEnabled()) {
_log.warn(pe, pe);
}
} catch (Exception e) {
_log.error(e, e);
}
return -1;
}
use of com.liferay.portal.security.auth.PrincipalException in project liferay-ide by liferay.
the class WebServerServlet method sendDocumentLibrary.
protected void sendDocumentLibrary(HttpServletRequest request, HttpServletResponse response, User user, String path, String[] pathArray) throws Exception {
if (!PropsValues.WEB_SERVER_SERVLET_DIRECTORY_INDEXING_ENABLED) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
for (int i = 1; i < pathArray.length; i++) {
String name = pathArray[i];
try {
Folder folder = DLAppServiceUtil.getFolder(groupId, folderId, name);
folderId = folder.getFolderId();
} catch (NoSuchFolderException nsfe) {
if (i != pathArray.length - 1) {
throw nsfe;
}
String title = name;
sendFile(response, user, groupId, folderId, title);
return;
}
}
try {
sendFile(response, user, groupId, folderId, "index.html");
return;
} catch (Exception e) {
if ((e instanceof NoSuchFileEntryException) || (e instanceof PrincipalException)) {
try {
sendFile(response, user, groupId, folderId, "index.htm");
return;
} catch (NoSuchFileEntryException nsfee) {
} catch (PrincipalException pe) {
}
} else {
throw e;
}
}
List<WebServerEntry> webServerEntries = new ArrayList<WebServerEntry>();
webServerEntries.add(new WebServerEntry(path, "../"));
List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folderId);
for (Folder folder : folders) {
WebServerEntry webServerEntry = new WebServerEntry(path, folder.getName() + StringPool.SLASH, folder.getCreateDate(), folder.getModifiedDate(), folder.getDescription(), 0);
webServerEntries.add(webServerEntry);
}
List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupId, folderId);
for (FileEntry fileEntry : fileEntries) {
WebServerEntry webServerEntry = new WebServerEntry(path, fileEntry.getTitle(), fileEntry.getCreateDate(), fileEntry.getModifiedDate(), fileEntry.getDescription(), fileEntry.getSize());
webServerEntries.add(webServerEntry);
}
sendHTML(response, path, webServerEntries);
}
use of com.liferay.portal.security.auth.PrincipalException 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.security.auth.PrincipalException 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