Search in sources :

Example 31 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.

the class ServicePreAction method doRun.

protected void doRun(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    if (!_PORTLET_ADD_DEFAULT_RESOURCE_CHECK_ENABLED) {
        return;
    }
    if (!themeDisplay.isLifecycleRender()) {
        return;
    }
    String portletId = ParamUtil.getString(request, "p_p_id");
    if (Validator.isNull(portletId)) {
        return;
    }
    if (!portletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE_DEFAULT_INSTANCE)) {
        return;
    }
    String request_p_p_auth = ParamUtil.getString(request, "p_p_auth");
    if (Validator.isNull(request_p_p_auth)) {
        return;
    }
    String actual_p_p_auth = AuthTokenUtil.getToken(request, themeDisplay.getPlid(), portletId);
    if (request_p_p_auth.equals(actual_p_p_auth)) {
        return;
    }
    // A guest user that signs in will cause the original portlet
    // authentication token to become stale. See SessionAuthToken.
    String redirect = HttpUtil.setParameter(themeDisplay.getURLCurrent(), "p_p_auth", actual_p_p_auth);
    response.sendRedirect(redirect);
}
Also used : ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 32 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class UserCacheHolder method getCurrentUserEmail.

protected Optional<String> getCurrentUserEmail(ServletRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    com.liferay.portal.model.User liferayUser = themeDisplay.getUser();
    return Optional.ofNullable(liferayUser).map(com.liferay.portal.model.User::getEmailAddress);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 33 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class UserPortletUtils method addLiferayUser.

public static User addLiferayUser(PortletRequest request, String firstName, String lastName, String emailAddress, String organizationName, String roleName, boolean male, String externalId, String password, boolean passwordEncrypted, boolean activateImmediately) throws SystemException, PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long companyId = themeDisplay.getCompanyId();
    long organizationId = OrganizationLocalServiceUtil.getOrganizationId(companyId, organizationName);
    final Role role = RoleLocalServiceUtil.getRole(companyId, roleName);
    long roleId = role.getRoleId();
    return addLiferayUser(request, firstName, lastName, emailAddress, organizationId, roleId, male, externalId, password, passwordEncrypted, activateImmediately);
}
Also used : Role(com.liferay.portal.model.Role) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 34 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class UserPortletUtils method addLiferayUser.

private static User addLiferayUser(PortletRequest request, String firstName, String lastName, String emailAddress, long organizationId, long roleId, boolean isMale, String externalId, String password, boolean passwordEncrypted, boolean activateImmediately) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    String screenName = firstName + lastName;
    long companyId = themeDisplay.getCompanyId();
    try {
        if (userAlreadyExists(request, emailAddress, externalId, screenName, companyId)) {
            return null;
        }
    } catch (PortalException | SystemException e) {
        log.error(e);
        // won't try to create user if even checking for existing user failed
        return null;
    }
    try {
        ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
        long[] roleIds = roleId == 0 ? new long[] {} : new long[] { roleId };
        long[] organizationIds = organizationId == 0 ? new long[] {} : new long[] { organizationId };
        long[] userGroupIds = null;
        long currentUserId = themeDisplay.getUserId();
        User user = UserLocalServiceUtil.addUser(currentUserId, /*creator*/
        companyId, false, /*autoPassword*/
        password, password, false, /*autoScreenName*/
        screenName, emailAddress, 0, /*facebookId*/
        externalId, /*openId*/
        themeDisplay.getLocale(), firstName, "", /*middleName*/
        lastName, 0, /*prefixId*/
        0, /*suffixId*/
        isMale, 4, /*birthdayMonth*/
        12, /*birthdayDay*/
        1959, /*birthdayYear*/
        "", /*jobTitle*/
        null, /*groupIds*/
        organizationIds, roleIds, userGroupIds, false, /*sendEmail*/
        serviceContext);
        user.setPasswordReset(false);
        if (passwordEncrypted) {
            user.setPassword(password);
            user.setPasswordEncrypted(true);
        }
        Role role = RoleLocalServiceUtil.getRole(roleId);
        RoleUtil.addUser(role.getRoleId(), user.getUserId());
        UserLocalServiceUtil.updateUser(user);
        RoleLocalServiceUtil.updateRole(role);
        UserLocalServiceUtil.updateStatus(user.getUserId(), activateImmediately ? WorkflowConstants.STATUS_APPROVED : WorkflowConstants.STATUS_INACTIVE);
        Indexer indexer = IndexerRegistryUtil.getIndexer(User.class);
        indexer.reindex(user);
        return user;
    } catch (PortalException | SystemException e) {
        log.error(e);
        return null;
    }
}
Also used : Role(com.liferay.portal.model.Role) User(com.liferay.portal.model.User) Indexer(com.liferay.portal.kernel.search.Indexer) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 35 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class UserPortlet method getCurrentUser.

private User getCurrentUser(PortletRequest request) throws SW360Exception {
    User user;
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    if (themeDisplay.isSignedIn())
        user = themeDisplay.getUser();
    else {
        throw new SW360Exception("Broken portlet!");
    }
    return user;
}
Also used : User(com.liferay.portal.model.User) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Aggregations

ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)63 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)10 ServiceContext (com.liferay.portal.service.ServiceContext)7 JSONObject (com.liferay.portal.kernel.json.JSONObject)6 PortletURL (javax.portlet.PortletURL)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 User (com.liferay.portal.model.User)5 Gadget (com.liferay.opensocial.model.Gadget)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)4 PortletConfig (javax.portlet.PortletConfig)4 KBArticle (com.liferay.knowledgebase.model.KBArticle)3 KBFolder (com.liferay.knowledgebase.model.KBFolder)3 Role (com.liferay.portal.model.Role)3 HashMap (java.util.HashMap)3 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 Layout (com.liferay.portal.model.Layout)2 SocialActivity (com.liferay.portlet.social.model.SocialActivity)2