protected boolean isCacheableRequest(HttpServletRequest request) { String portletId = ParamUtil.getString(request, "p_p_id"); if (Validator.isNotNull(portletId)) { return false; } if ((_pattern == _PATTERN_FRIENDLY) || (_pattern == _PATTERN_LAYOUT)) { long userId = PortalUtil.getUserId(request); String remoteUser = request.getRemoteUser(); if ((userId > 0) || Validator.isNotNull(remoteUser)) { return false; } } if (_pattern == _PATTERN_LAYOUT) { String plid = ParamUtil.getString(request, "p_l_id"); if (Validator.isNull(plid)) { return false; } } return true; }
protected void updateEmailAddress(HttpServletRequest request) throws Exception { long userId = PortalUtil.getUserId(request); String password = AdminUtil.getUpdateUserPassword(request, userId); String emailAddress1 = ParamUtil.getString(request, "emailAddress1"); String emailAddress2 = ParamUtil.getString(request, "emailAddress2"); ServiceContext serviceContext = ServiceContextFactory.getInstance(request); UserServiceUtil.updateEmailAddress( userId, password, emailAddress1, emailAddress2, serviceContext); }
@Override public AnonymousUser getAnonymousUser(HttpServletRequest request, HttpServletResponse response) throws PortalException, SystemException { long companyId = PortalUtil.getCompanyId(request); long userId = PortalUtil.getUserId(request); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); AnonymousUser anonymousUser = null; if (userId > 0) { anonymousUser = getAnonymousUser(request, userId); if (!anonymousUser.getLastIp().equals(request.getRemoteAddr())) { AnonymousUserLocalServiceUtil.updateLastIp( anonymousUser.getAnonymousUserId(), request.getRemoteAddr()); } return anonymousUser; } anonymousUser = getAnonymousUserFromCookie(request); if (anonymousUser == null) { anonymousUser = AnonymousUserLocalServiceUtil.addAnonymousUser( 0, request.getRemoteAddr(), null, serviceContext); _anonymousUsersCookieManager.addCookie(request, response, anonymousUser.getAnonymousUserId()); } else if (!anonymousUser.getLastIp().equals(request.getRemoteAddr())) { AnonymousUserLocalServiceUtil.updateLastIp( anonymousUser.getAnonymousUserId(), request.getRemoteAddr()); } return anonymousUser; }
@Override public PortletPreferencesIds getPortletPreferencesIds( HttpServletRequest request, Layout layout, String portletId) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long siteGroupId = themeDisplay.getSiteGroupId(); long userId = PortalUtil.getUserId(request); LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet(); boolean modeEditGuest = false; String portletMode = ParamUtil.getString(request, "p_p_mode"); if (portletMode.equals(LiferayPortletMode.EDIT_GUEST.toString()) || ((layoutTypePortlet != null) && layoutTypePortlet.hasModeEditGuestPortletId(portletId))) { modeEditGuest = true; } return getPortletPreferencesIds(siteGroupId, userId, layout, portletId, modeEditGuest); }
protected long getUserId(HttpServletRequest request) { return PortalUtil.getUserId(request); }
protected Object[] updateGroup(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long userId = PortalUtil.getUserId(actionRequest); long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId"); long parentGroupId = ParamUtil.getLong( actionRequest, "parentGroupSearchContainerPrimaryKeys", GroupConstants.DEFAULT_PARENT_GROUP_ID); String name = null; String description = null; int type = 0; String friendlyURL = null; boolean active = false; ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest); Group liveGroup = null; String oldFriendlyURL = null; String oldStagingFriendlyURL = null; if (liveGroupId <= 0) { // Add group name = ParamUtil.getString(actionRequest, "name"); description = ParamUtil.getString(actionRequest, "description"); type = ParamUtil.getInteger(actionRequest, "type"); friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL"); active = ParamUtil.getBoolean(actionRequest, "active"); liveGroup = GroupServiceUtil.addGroup( parentGroupId, GroupConstants.DEFAULT_LIVE_GROUP_ID, name, description, type, friendlyURL, true, active, serviceContext); LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId); } else { // Update group liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId); oldFriendlyURL = liveGroup.getFriendlyURL(); name = ParamUtil.getString(actionRequest, "name", liveGroup.getName()); description = ParamUtil.getString(actionRequest, "description", liveGroup.getDescription()); type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType()); friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL()); active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive()); liveGroup = GroupServiceUtil.updateGroup( liveGroupId, parentGroupId, name, description, type, friendlyURL, active, serviceContext); if (type == GroupConstants.TYPE_SITE_OPEN) { List<MembershipRequest> membershipRequests = MembershipRequestLocalServiceUtil.search( liveGroupId, MembershipRequestConstants.STATUS_PENDING, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (MembershipRequest membershipRequest : membershipRequests) { MembershipRequestServiceUtil.updateStatus( membershipRequest.getMembershipRequestId(), themeDisplay.translate("your-membership-has-been-approved"), MembershipRequestConstants.STATUS_APPROVED, serviceContext); LiveUsers.joinGroup( themeDisplay.getCompanyId(), membershipRequest.getGroupId(), new long[] {membershipRequest.getUserId()}); } } } // Settings UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties(); String customJspServletContextName = ParamUtil.getString( actionRequest, "customJspServletContextName", typeSettingsProperties.getProperty("customJspServletContextName")); typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName); typeSettingsProperties.setProperty( "defaultSiteRoleIds", ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA)); typeSettingsProperties.setProperty( "defaultTeamIds", ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA)); String[] analyticsTypes = PrefsPropsUtil.getStringArray( themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE); for (String analyticsType : analyticsTypes) { if (analyticsType.equalsIgnoreCase("google")) { String googleAnalyticsId = ParamUtil.getString( actionRequest, "googleAnalyticsId", typeSettingsProperties.getProperty("googleAnalyticsId")); typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId); } else { String analyticsScript = ParamUtil.getString( actionRequest, SitesUtil.ANALYTICS_PREFIX + analyticsType, typeSettingsProperties.getProperty(analyticsType)); typeSettingsProperties.setProperty( SitesUtil.ANALYTICS_PREFIX + analyticsType, analyticsScript); } } String publicRobots = ParamUtil.getString( actionRequest, "publicRobots", liveGroup.getTypeSettingsProperty("false-robots.txt")); String privateRobots = ParamUtil.getString( actionRequest, "privateRobots", liveGroup.getTypeSettingsProperty("true-robots.txt")); typeSettingsProperties.setProperty("false-robots.txt", publicRobots); typeSettingsProperties.setProperty("true-robots.txt", privateRobots); int trashEnabled = ParamUtil.getInteger( actionRequest, "trashEnabled", GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEnabled"))); typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled)); int trashEntriesMaxAgeCompany = PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE); int defaultTrashEntriesMaxAgeGroup = GetterUtil.getInteger( typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany); int trashEntriesMaxAgeGroup = ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge", defaultTrashEntriesMaxAgeGroup); if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) { typeSettingsProperties.setProperty( "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup)); } else { typeSettingsProperties.remove("trashEntriesMaxAge"); } // Virtual hosts LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet(); String publicVirtualHost = ParamUtil.getString( actionRequest, "publicVirtualHost", publicLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost); LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet(); String privateVirtualHost = ParamUtil.getString( actionRequest, "privateVirtualHost", privateLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost); // Staging if (liveGroup.hasStagingGroup()) { Group stagingGroup = liveGroup.getStagingGroup(); oldStagingFriendlyURL = stagingGroup.getFriendlyURL(); friendlyURL = ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL()); GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL); LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet(); publicVirtualHost = ParamUtil.getString( actionRequest, "stagingPublicVirtualHost", stagingPublicLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost); LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet(); privateVirtualHost = ParamUtil.getString( actionRequest, "stagingPrivateVirtualHost", stagingPrivateLayoutSet.getVirtualHostname()); LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost); } liveGroup = GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString()); // Layout set prototypes if (!liveGroup.isStaged()) { long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId"); long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId"); boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "privateLayoutSetPrototypeLinkEnabled", privateLayoutSet.isLayoutSetPrototypeLinkEnabled()); boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "publicLayoutSetPrototypeLinkEnabled", publicLayoutSet.isLayoutSetPrototypeLinkEnabled()); if ((privateLayoutSetPrototypeId == 0) && (publicLayoutSetPrototypeId == 0) && !privateLayoutSetPrototypeLinkEnabled && !publicLayoutSetPrototypeLinkEnabled) { long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId"); int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility"); boolean layoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "layoutSetPrototypeLinkEnabled", (layoutSetPrototypeId > 0)); if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) { privateLayoutSetPrototypeId = layoutSetPrototypeId; privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled; } else { publicLayoutSetPrototypeId = layoutSetPrototypeId; publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled; } } SitesUtil.updateLayoutSetPrototypesLinks( liveGroup, publicLayoutSetPrototypeId, privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled, privateLayoutSetPrototypeLinkEnabled); } // Staging String redirect = ParamUtil.getString(actionRequest, "redirect"); long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false)); if (!privateLayoutSet.isLayoutSetPrototypeLinkActive() && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) { if ((refererPlid > 0) && liveGroup.hasStagingGroup() && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) { Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout( liveGroup.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); if (firstLayout == null) { firstLayout = LayoutLocalServiceUtil.fetchFirstLayout( liveGroup.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); } if (firstLayout != null) { refererPlid = firstLayout.getPlid(); } else { refererPlid = 0; } } StagingUtil.updateStaging(actionRequest, liveGroup); } return new Object[] {liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid}; }
private boolean isAdmin(HttpServletRequest httpRequest) throws PortalException, SystemException { final long userId = PortalUtil.getUserId(httpRequest); final long companyId = PortalUtil.getDefaultCompanyId(); return UserLocalServiceUtil.hasRoleUser(companyId, RoleConstants.ADMINISTRATOR, userId, true); }
public void setRequest(HttpServletRequest request) { setCompanyId(PortalUtil.getCompanyId(request)); setPathInfo(request.getPathInfo()); setUserId(PortalUtil.getUserId(request)); }
protected void init( HttpServletRequest request, Portlet portlet, InvokerPortlet invokerPortlet, PortletContext portletContext, WindowState windowState, PortletMode portletMode, PortletPreferences preferences, long plid) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); _portlet = portlet; _portletName = portlet.getPortletId(); _publicRenderParameters = PublicRenderParametersPool.get(request, plid); String portletNamespace = PortalUtil.getPortletNamespace(_portletName); boolean portalSessionShared = false; PortletApp portletApp = portlet.getPortletApp(); if (portletApp.isWARFile() && !portlet.isPrivateSessionAttributes()) { portalSessionShared = true; } request = new SharedSessionServletRequest(request, portalSessionShared); DynamicServletRequest dynamicRequest = null; if (portlet.isPrivateRequestAttributes()) { dynamicRequest = new NamespaceServletRequest(request, portletNamespace, portletNamespace, false); } else { dynamicRequest = new DynamicServletRequest(request, false); } boolean portletFocus = false; String ppid = ParamUtil.getString(request, "p_p_id"); boolean windowStateRestoreCurrentView = ParamUtil.getBoolean(request, "p_p_state_rcv"); if (_portletName.equals(ppid) && !(windowStateRestoreCurrentView && portlet.isRestoreCurrentView())) { // Request was targeted to this portlet if (themeDisplay.isLifecycleRender() || themeDisplay.isLifecycleResource()) { // Request was triggered by a render or resource URL portletFocus = true; } else if (themeDisplay.isLifecycleAction()) { _triggeredByActionURL = true; if (getLifecycle().equals(PortletRequest.ACTION_PHASE)) { // Request was triggered by an action URL and is being // processed by com.liferay.portlet.ActionRequestImpl portletFocus = true; } } } Map<String, String[]> renderParameters = RenderParametersPool.get(request, plid, _portletName); if (portletFocus) { renderParameters = new HashMap<String, String[]>(); if (getLifecycle().equals(PortletRequest.RENDER_PHASE) && !LiferayWindowState.isExclusive(request) && !LiferayWindowState.isPopUp(request)) { RenderParametersPool.put(request, plid, _portletName, renderParameters); } Map<String, String[]> parameters = request.getParameterMap(); for (Map.Entry<String, String[]> entry : parameters.entrySet()) { String name = entry.getKey(); if (isInvalidParameter(name)) { continue; } String[] values = entry.getValue(); if (themeDisplay.isLifecycleRender()) { renderParameters.put(name, values); } if (values == null) { continue; } name = removePortletNamespace(invokerPortlet, portletNamespace, name); dynamicRequest.setParameterValues(name, values); } } else { for (Map.Entry<String, String[]> entry : renderParameters.entrySet()) { String name = entry.getKey(); String[] values = entry.getValue(); name = removePortletNamespace(invokerPortlet, portletNamespace, name); dynamicRequest.setParameterValues(name, values); } } mergePublicRenderParameters(dynamicRequest, preferences, plid); _request = dynamicRequest; _originalRequest = request; _wapTheme = BrowserSnifferUtil.isWap(_request); _portlet = portlet; _portalContext = new PortalContextImpl(); _portletContext = portletContext; _windowState = windowState; _portletMode = portletMode; _preferences = preferences; _portalSessionId = _request.getRequestedSessionId(); _session = new PortletSessionImpl(_request, _portletName, _portletContext, _portalSessionId, plid); String remoteUser = request.getRemoteUser(); String userPrincipalStrategy = portlet.getUserPrincipalStrategy(); if (userPrincipalStrategy.equals(PortletConstants.USER_PRINCIPAL_STRATEGY_SCREEN_NAME)) { try { User user = PortalUtil.getUser(request); if (user != null) { _remoteUser = user.getScreenName(); _remoteUserId = user.getUserId(); _userPrincipal = new ProtectedPrincipal(_remoteUser); } } catch (Exception e) { _log.error(e); } } else { long userId = PortalUtil.getUserId(request); if ((userId > 0) && (remoteUser == null)) { _remoteUser = String.valueOf(userId); _remoteUserId = userId; _userPrincipal = new ProtectedPrincipal(_remoteUser); } else { _remoteUser = remoteUser; _remoteUserId = GetterUtil.getLong(remoteUser); _userPrincipal = request.getUserPrincipal(); } } _locale = themeDisplay.getLocale(); _plid = plid; }
public static void getPage(HttpServletRequest request) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long nodeId = ParamUtil.getLong(request, "nodeId"); String title = ParamUtil.getString(request, "title"); double version = ParamUtil.getDouble(request, "version"); WikiNode node = null; try { if (nodeId > 0) { node = WikiNodeServiceUtil.getNode(nodeId); } } catch (NoSuchNodeException nsne) { } if (node == null) { node = (WikiNode) request.getAttribute(WebKeys.WIKI_NODE); if (node != null) { nodeId = node.getNodeId(); } } if (Validator.isNull(title)) { title = WikiPageConstants.FRONT_PAGE; } WikiPage page = null; try { page = WikiPageServiceUtil.getPage(nodeId, title, version); } catch (NoSuchPageException nspe) { if (title.equals(WikiPageConstants.FRONT_PAGE) && (version == 0)) { long userId = PortalUtil.getUserId(request); if (userId == 0) { long companyId = PortalUtil.getCompanyId(request); userId = UserLocalServiceUtil.getDefaultUserId(companyId); } ServiceContext serviceContext = new ServiceContext(); Layout layout = themeDisplay.getLayout(); serviceContext.setAddCommunityPermissions(true); if (layout.isPublicLayout()) { serviceContext.setAddGuestPermissions(true); } else { serviceContext.setAddGuestPermissions(false); } boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try { WorkflowThreadLocal.setEnabled(false); page = WikiPageLocalServiceUtil.addPage( userId, nodeId, title, null, WikiPageConstants.NEW, true, serviceContext); } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } } else { throw nspe; } } request.setAttribute(WebKeys.WIKI_PAGE, page); }
@Override protected void processFilter( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { long companyId = PortalUtil.getCompanyId(request); OpenSSOConfiguration openSSOConfiguration = getOpenSSOConfiguration(companyId); String requestURI = GetterUtil.getString(request.getRequestURI()); if (requestURI.endsWith("/portal/logout")) { HttpSession session = request.getSession(); session.invalidate(); response.sendRedirect(openSSOConfiguration.logoutURL()); return; } boolean authenticated = false; try { // LEP-5943 authenticated = _openSSO.isAuthenticated(request, openSSOConfiguration.serviceURL()); } catch (Exception e) { _log.error(e, e); processFilter(OpenSSOFilter.class, request, response, filterChain); return; } HttpSession session = request.getSession(); if (authenticated) { // LEP-5943 String newSubjectId = _openSSO.getSubjectId(request, openSSOConfiguration.serviceURL()); String oldSubjectId = (String) session.getAttribute(_SUBJECT_ID_KEY); if (oldSubjectId == null) { session.setAttribute(_SUBJECT_ID_KEY, newSubjectId); } else if (!newSubjectId.equals(oldSubjectId)) { session.invalidate(); session = request.getSession(); session.setAttribute(_SUBJECT_ID_KEY, newSubjectId); } processFilter(OpenSSOFilter.class, request, response, filterChain); return; } else if (PortalUtil.getUserId(request) > 0) { session.invalidate(); } if (!PropsValues.AUTH_FORWARD_BY_LAST_PATH || !openSSOConfiguration.loginURL().contains("/portal/login")) { response.sendRedirect(openSSOConfiguration.loginURL()); return; } String currentURL = PortalUtil.getCurrentURL(request); String redirect = currentURL; if (currentURL.contains("/portal/login")) { redirect = ParamUtil.getString(request, "redirect"); if (Validator.isNull(redirect)) { redirect = PortalUtil.getPathMain(); } } redirect = openSSOConfiguration.loginURL() + HttpUtil.encodeURL("?redirect=" + HttpUtil.encodeURL(redirect)); response.sendRedirect(redirect); }