Search in sources :

Example 1 with PrincipalException

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);
}
Also used : NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) KBArticle(com.liferay.knowledgebase.model.KBArticle) PortletException(javax.portlet.PortletException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchArticleException(com.liferay.knowledgebase.NoSuchArticleException) KBTemplate(com.liferay.knowledgebase.model.KBTemplate) NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) KBTemplateContentException(com.liferay.knowledgebase.KBTemplateContentException) NoSuchArticleException(com.liferay.knowledgebase.NoSuchArticleException) NoSuchSubscriptionException(com.liferay.portal.NoSuchSubscriptionException) 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) WindowStateException(javax.portlet.WindowStateException) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) KBTemplateTitleException(com.liferay.knowledgebase.KBTemplateTitleException) KBArticleImportException(com.liferay.knowledgebase.KBArticleImportException) PortletException(javax.portlet.PortletException)

Example 2 with PrincipalException

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;
}
Also used : PrincipalException(com.liferay.portal.security.auth.PrincipalException) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Image(com.liferay.portal.model.Image) RenderedImage(java.awt.image.RenderedImage) Date(java.util.Date) 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 3 with PrincipalException

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);
}
Also used : ArrayList(java.util.ArrayList) 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) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 4 with PrincipalException

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);
    }
}
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 PrincipalException

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

PrincipalException (com.liferay.portal.security.auth.PrincipalException)19 IOException (java.io.IOException)8 SystemException (com.liferay.portal.kernel.exception.SystemException)7 PortalException (com.liferay.portal.kernel.exception.PortalException)6 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)6 ServiceContext (com.liferay.portal.service.ServiceContext)6 InputStream (java.io.InputStream)6 AlbumNameException (org.liferay.jukebox.AlbumNameException)6 ArtistNameException (org.liferay.jukebox.ArtistNameException)6 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)6 SongNameException (org.liferay.jukebox.SongNameException)6 NoSuchArticleException (com.liferay.knowledgebase.NoSuchArticleException)5 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)5 KBArticle (com.liferay.knowledgebase.model.KBArticle)5 NoSuchSubscriptionException (com.liferay.portal.NoSuchSubscriptionException)5 PortletException (javax.portlet.PortletException)5 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)3 ResourceServingConfigurationAction (com.liferay.portal.kernel.portlet.ResourceServingConfigurationAction)3 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)3 Portlet (com.liferay.portal.model.Portlet)3