public static List<Group> getGroups(User user) throws Exception { // Guest if (user.isDefaultUser()) { List<Group> groups = new ArrayList<>(); Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), GroupConstants.GUEST); groups.add(group); return groups; } // Communities Set<Group> groups = new HashSet<>(); LinkedHashMap<String, Object> params = new LinkedHashMap<>(); params.put("usersGroups", user.getUserId()); OrderByComparator<Group> orderByComparator = new GroupFriendlyURLComparator(true); groups.addAll( GroupLocalServiceUtil.search( user.getCompanyId(), null, null, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator)); // Organizations groups.addAll( GroupLocalServiceUtil.getUserOrganizationsGroups( user.getUserId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS)); // User if (!user.isDefaultUser()) { groups.add(user.getGroup()); } List<Group> groupsList = new ArrayList<>(groups); Collections.sort(groupsList, orderByComparator); return groupsList; }
protected void addEquityLog( User user, AssetEntry assetEntry, User assetEntryUser, SocialEquitySetting equitySetting) throws PortalException, SystemException { if (!isAddEquityLog(user.getUserId(), assetEntry.getEntryId(), equitySetting)) { return; } int actionDate = getEquityDate(); double k = calculateK(equitySetting.getValue(), equitySetting.getLifespan()); double b = calculateB(actionDate, equitySetting.getValue(), equitySetting.getLifespan()); SocialEquityValue socialEquity = new SocialEquityValue(k, b); if (equitySetting.getType() == SocialEquitySettingConstants.TYPE_INFORMATION) { socialEquityLogLocalService.incrementSocialEquityAssetEntry_IQ( assetEntry.getEntryId(), socialEquity); if ((assetEntryUser != null) && !assetEntryUser.isDefaultUser()) { socialEquityLogLocalService.incrementSocialEquityUser_CQ( assetEntry.getGroupId(), assetEntryUser.getUserId(), socialEquity); } } else if (equitySetting.getType() == SocialEquitySettingConstants.TYPE_PARTICIPATION) { if (!user.isDefaultUser()) { socialEquityLogLocalService.incrementSocialEquityUser_PQ( assetEntry.getGroupId(), user.getUserId(), socialEquity); } } long equityLogId = counterLocalService.increment(); SocialEquityLog equityLog = socialEquityLogPersistence.create(equityLogId); equityLog.setGroupId(assetEntry.getGroupId()); equityLog.setCompanyId(user.getCompanyId()); equityLog.setUserId(user.getUserId()); equityLog.setAssetEntryId(assetEntry.getEntryId()); equityLog.setActionId(equitySetting.getActionId()); equityLog.setActionDate(actionDate); equityLog.setType(equitySetting.getType()); equityLog.setValue(equitySetting.getValue()); equityLog.setExpiration(actionDate + equitySetting.getLifespan()); equityLog.setActive(true); socialEquityLogPersistence.update(equityLog, false); }
@Override protected void doUpgrade() throws Exception { List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (User user : users) { try { if (user.isDefaultUser()) { continue; } Group group = user.getGroup(); LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false); String themeId = layoutSet.getThemeId(); if (!themeId.equals("so_WAR_sotheme")) { return; } Role role = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER); UserLocalServiceUtil.addRoleUsers(role.getRoleId(), new long[] {user.getUserId()}); updateUserGroup(group); updateSocialRelations(user); } catch (Exception e) { } } }
public static boolean isValidUser(User user) { if (user.isDefaultUser()) { return false; } else { return true; } }
@Override public boolean isShow() { User user = themeDisplay.getUser(); if (user.isDefaultUser()) { return false; } return true; }
protected boolean isAddActivityCounter( User user, User assetEntryUser, AssetEntry assetEntry, SocialActivityCounterDefinition activityCounterDefinition) { if ((user.isDefaultUser() || !user.isActive()) && (activityCounterDefinition.getOwnerType() != SocialActivityCounterConstants.TYPE_ASSET)) { return false; } if ((assetEntryUser.isDefaultUser() || !assetEntryUser.isActive()) && (activityCounterDefinition.getOwnerType() != SocialActivityCounterConstants.TYPE_ACTOR)) { return false; } if (!activityCounterDefinition.isEnabled() || (activityCounterDefinition.getIncrement() == 0)) { return false; } String name = activityCounterDefinition.getName(); if ((user.getUserId() == assetEntryUser.getUserId()) && (name.equals(SocialActivityCounterConstants.NAME_CONTRIBUTION) || name.equals(SocialActivityCounterConstants.NAME_POPULARITY))) { return false; } if ((activityCounterDefinition.getOwnerType() == SocialActivityCounterConstants.TYPE_ASSET) && !assetEntry.isVisible()) { return false; } return true; }
/** * Returns <code>true</code> if the users can be in a relation of the given type where the user * with primary key <code>userId1</code> is User1 of the relation and the user with the primary * key <code>userId2</code> is User2 of the relation. * * <p>This method returns <code>false</code> if User1 and User2 are the same, if either user is * the default user, or if a matching relation already exists. * * @param userId1 the user that is the subject of the relation * @param userId2 the user at the other end of the relation * @param type the relation's type * @return <code>true</code> if the two users can be in a new relation of the given type; <code> * false</code> otherwise * @throws SystemException if a system exception occurred */ public boolean isRelatable(long userId1, long userId2, int type) throws SystemException { if (userId1 == userId2) { return false; } User user1 = userPersistence.fetchByPrimaryKey(userId1); if ((user1 == null) || user1.isDefaultUser()) { return false; } User user2 = userPersistence.fetchByPrimaryKey(userId2); if ((user2 == null) || user2.isDefaultUser()) { return false; } return !hasRelation(userId1, userId2, type); }
protected GoogleDriveSession buildGoogleDriveSession() throws IOException, PortalException { long userId = PrincipalThreadLocal.getUserId(); User user = UserLocalServiceUtil.getUser(userId); if (user.isDefaultUser()) { throw new PrincipalException("User is not authenticated"); } GoogleCredential.Builder builder = new GoogleCredential.Builder(); String googleClientId = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-id"); String googleClientSecret = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-secret"); builder.setClientSecrets(googleClientId, googleClientSecret); JacksonFactory jsonFactory = new JacksonFactory(); builder.setJsonFactory(jsonFactory); HttpTransport httpTransport = new NetHttpTransport(); builder.setTransport(httpTransport); GoogleCredential googleCredential = builder.build(); ExpandoBridge expandoBridge = user.getExpandoBridge(); String googleAccessToken = GetterUtil.getString(expandoBridge.getAttribute("googleAccessToken", false)); googleCredential.setAccessToken(googleAccessToken); String googleRefreshToken = GetterUtil.getString(expandoBridge.getAttribute("googleRefreshToken", false)); googleCredential.setRefreshToken(googleRefreshToken); Drive.Builder driveBuilder = new Drive.Builder(httpTransport, jsonFactory, googleCredential); Drive drive = driveBuilder.build(); Drive.About driveAbout = drive.about(); Drive.About.Get driveAboutGet = driveAbout.get(); About about = driveAboutGet.execute(); return new GoogleDriveSession(drive, about.getRootFolderId()); }
protected User importUser( long companyId, Attributes attributes, Properties userMappings, Properties userExpandoMappings, Properties contactMappings, Properties contactExpandoMappings, String password) throws Exception { LDAPUserTransactionThreadLocal.setOriginatesFromLDAP(true); try { AttributesTransformer attributesTransformer = AttributesTransformerFactory.getInstance(); attributes = attributesTransformer.transformUser(attributes); LDAPUser ldapUser = _ldapToPortalConverter.importLDAPUser( companyId, attributes, userMappings, userExpandoMappings, contactMappings, contactExpandoMappings, password); User user = getUser(companyId, ldapUser); if ((user != null) && user.isDefaultUser()) { return user; } if (user == null) { user = addUser(companyId, ldapUser, password); } String modifiedDate = LDAPUtil.getAttributeString(attributes, "modifyTimestamp"); user = updateUser(companyId, ldapUser, user, password, modifiedDate); updateExpandoAttributes(user, ldapUser); return user; } finally { LDAPUserTransactionThreadLocal.setOriginatesFromLDAP(false); } }
protected void processPrincipalException( Throwable t, User user, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (!user.isDefaultUser()) { PortalUtil.sendError(HttpServletResponse.SC_UNAUTHORIZED, (Exception) t, request, response); return; } String redirect = request.getContextPath() + Portal.PATH_MAIN + "/portal/login"; String currentURL = PortalUtil.getCurrentURL(request); redirect = HttpUtil.addParameter(redirect, "redirect", currentURL); response.sendRedirect(redirect); }
public void deactivateEquityLogs(long assetEntryId) throws PortalException, SystemException { if (!PropsValues.SOCIAL_EQUITY_EQUITY_LOG_ENABLED) { return; } SocialEquityAssetEntry equityAssetEntry = null; try { equityAssetEntry = socialEquityAssetEntryPersistence.findByAssetEntryId(assetEntryId); socialEquityAssetEntryPersistence.removeByAssetEntryId(assetEntryId); } catch (NoSuchEquityAssetEntryException nseaee) { return; } User user = null; try { user = userPersistence.findByPrimaryKey(equityAssetEntry.getUserId()); if (!user.isDefaultUser()) { SocialEquityValue socialEquityValue = new SocialEquityValue( -equityAssetEntry.getInformationK(), -equityAssetEntry.getInformationB()); incrementSocialEquityUser_CQ( equityAssetEntry.getGroupId(), user.getUserId(), socialEquityValue); } } catch (NoSuchUserException nsue) { } List<SocialEquityLog> equityLogs = socialEquityLogPersistence.findByAEI_T_A( assetEntryId, SocialEquitySettingConstants.TYPE_INFORMATION, true); for (SocialEquityLog equityLog : equityLogs) { equityLog.setActive(false); socialEquityLogPersistence.update(equityLog, false); } }
protected void addAllUsersToSite(long companyId, long groupId) throws Exception { List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); ArrayList<Long> userIdList = new ArrayList<Long>(); for (User user : users) { if (!user.isDefaultUser()) { userIdList.add(user.getUserId()); } } long[] userIds = new long[userIdList.size()]; for (int i = 0; i < userIds.length; i++) { userIds[i] = userIdList.get(i); } UserLocalServiceUtil.addGroupUsers(groupId, userIds); }
public int doStartTag() throws JspException { try { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); request.setAttribute("liferay-ui:user-display:user-id", String.valueOf(_userId)); request.setAttribute("liferay-ui:user-display:user-name", _userName); User user = null; try { user = UserLocalServiceUtil.getUserById(_userId); if (user.isDefaultUser()) { user = null; } request.setAttribute("liferay-ui:user-display:user", user); pageContext.setAttribute("userDisplay", user); } catch (NoSuchUserException usue) { request.removeAttribute("liferay-ui:user-display:user"); pageContext.removeAttribute("userDisplay"); } request.setAttribute("liferay-ui:user-display:url", _url); request.setAttribute("liferay-ui:user-display:displayStyle", String.valueOf(_displayStyle)); PortalIncludeUtil.include(pageContext, getStartPage()); if (user != null) { return EVAL_BODY_INCLUDE; } else { return SKIP_BODY; } } catch (Exception e) { throw new JspException(e); } }
public AssetEntry incrementViewCounter(long userId, String className, long classPK) throws PortalException, SystemException { User user = userPersistence.findByPrimaryKey(userId); assetEntryLocalService.incrementViewCounter(user.getUserId(), className, classPK, 1); AssetEntry assetEntry = getEntry(className, classPK); if (!user.isDefaultUser()) { socialActivityLocalService.addActivity( user.getUserId(), assetEntry.getGroupId(), className, classPK, SocialActivityConstants.TYPE_VIEW, StringPool.BLANK, 0); } return assetEntry; }
protected JSONArray getJSONArray(HttpServletRequest request) throws PortalException { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); SocialInteractionsConfiguration socialInteractionsConfiguration = SocialInteractionsConfigurationUtil.getSocialInteractionsConfiguration( themeDisplay.getCompanyId(), portletDisplay.getId()); String query = ParamUtil.getString(request, "query"); List<User> users = MentionsUserFinderUtil.getUsers( themeDisplay.getCompanyId(), themeDisplay.getUserId(), query, socialInteractionsConfiguration); for (User user : users) { if (user.isDefaultUser() || (themeDisplay.getUserId() == user.getUserId())) { continue; } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("fullName", user.getFullName()); jsonObject.put("portraitURL", user.getPortraitURL(themeDisplay)); jsonObject.put("profileURL", user.getDisplayURL(themeDisplay)); jsonObject.put("screenName", user.getScreenName()); jsonArray.put(jsonObject); } return jsonArray; }
protected void processPrincipalException( Throwable t, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); User user = permissionChecker.getUser(); if ((user != null) && !user.isDefaultUser()) { PortalUtil.sendError(HttpServletResponse.SC_UNAUTHORIZED, (Exception) t, request, response); return; } String redirect = request.getContextPath() + Portal.PATH_MAIN + "/portal/login"; String currentURL = PortalUtil.getCurrentURL(request); redirect = HttpUtil.addParameter(redirect, "redirect", currentURL); response.sendRedirect(redirect); }
public void init(User user, boolean checkGuest) { this.user = user; if (user.isDefaultUser()) { this.defaultUserId = user.getUserId(); this.signedIn = false; } else { try { this.defaultUserId = UserLocalServiceUtil.getDefaultUserId(user.getCompanyId()); } catch (Exception e) { _log.error(e, e); } this.signedIn = true; } this.checkGuest = checkGuest; try { this.ownerRole = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.OWNER); } catch (Exception e) { _log.error(e, e); } }
@Override protected void processFilter( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { String remoteAddr = request.getRemoteAddr(); if (isAccessAllowed(request)) { if (_log.isDebugEnabled()) { _log.debug("Access allowed for " + remoteAddr); } } else { if (_log.isWarnEnabled()) { _log.warn("Access denied for " + remoteAddr); } response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access denied for " + remoteAddr); return; } if (_log.isDebugEnabled()) { if (_httpsRequired) { _log.debug("https is required"); } else { _log.debug("https is not required"); } } if (_httpsRequired && !request.isSecure()) { if (_log.isDebugEnabled()) { String completeURL = HttpUtil.getCompleteURL(request); _log.debug("Securing " + completeURL); } StringBundler redirectURL = new StringBundler(5); redirectURL.append(Http.HTTPS_WITH_SLASH); redirectURL.append(request.getServerName()); redirectURL.append(request.getServletPath()); String queryString = request.getQueryString(); if (Validator.isNotNull(queryString)) { redirectURL.append(StringPool.QUESTION); redirectURL.append(request.getQueryString()); } if (_log.isDebugEnabled()) { _log.debug("Redirect to " + redirectURL); } response.sendRedirect(redirectURL.toString()); } else { if (_log.isDebugEnabled()) { String completeURL = HttpUtil.getCompleteURL(request); _log.debug("Not securing " + completeURL); } // This authentication should only be run if specified by web.xml // and JAAS is disabled. Make sure to run this once per session and // wrap the request if necessary. if (!PropsValues.PORTAL_JAAS_ENABLE) { User user = PortalUtil.getUser(request); if ((user != null) && !user.isDefaultUser()) { setCredentials(request, request.getSession(), user.getUserId()); } else { if (_digestAuthEnabled) { request = digestAuth(request, response); } else if (_basicAuthEnabled) { request = basicAuth(request, response); } } } if (request != null) { processFilter(getClass(), request, response, filterChain); } } }
public boolean containsWithoutViewableGroup( PermissionChecker permissionChecker, Layout layout, String controlPanelCategory, boolean checkLayoutUpdateable, String actionId) throws PortalException, SystemException { if (checkLayoutUpdateable && !actionId.equals(ActionKeys.CUSTOMIZE) && !actionId.equals(ActionKeys.VIEW) && (layout instanceof VirtualLayout)) { return false; } if (actionId.equals(ActionKeys.CUSTOMIZE) && (layout instanceof VirtualLayout)) { VirtualLayout virtualLayout = (VirtualLayout) layout; layout = virtualLayout.getWrappedModel(); } if (actionId.equals(ActionKeys.DELETE) && !SitesUtil.isLayoutDeleteable(layout)) { return false; } Group group = layout.getGroup(); if (checkLayoutUpdateable && !group.isLayoutSetPrototype() && isAttemptToModifyLockedLayout(layout, actionId)) { return false; } User user = UserLocalServiceUtil.getUserById(permissionChecker.getUserId()); if ((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) && !user.isDefaultUser() && !group.isUser()) { // This is new way of doing an ownership check without having to // have a userId field on the model. When the instance model was // first created, we set the user's userId as the ownerId of the // individual scope ResourcePermission of the Owner Role. // Therefore, ownership can be determined by obtaining the Owner // role ResourcePermission for the current instance model and // testing it with the hasOwnerPermission call. ResourcePermission resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission( layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid()), permissionChecker.getOwnerRoleId()); if (permissionChecker.hasOwnerPermission( layout.getCompanyId(), Layout.class.getName(), String.valueOf(layout.getPlid()), resourcePermission.getOwnerId(), actionId)) { return true; } } if (GroupPermissionUtil.contains( permissionChecker, layout.getGroupId(), ActionKeys.MANAGE_LAYOUTS)) { return true; } else if (actionId.equals(ActionKeys.ADD_LAYOUT) && GroupPermissionUtil.contains( permissionChecker, layout.getGroupId(), ActionKeys.ADD_LAYOUT)) { return true; } if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE && !actionId.equals(ActionKeys.VIEW)) { // Check upward recursively to see if any pages above grant the // action long parentLayoutId = layout.getParentLayoutId(); while (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) { Layout parentLayout = LayoutLocalServiceUtil.getLayout( layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId); if (contains(permissionChecker, parentLayout, controlPanelCategory, actionId)) { return true; } parentLayoutId = parentLayout.getParentLayoutId(); } } try { if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) { if (ResourcePermissionLocalServiceUtil.getResourcePermissionsCount( layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid())) == 0) { throw new NoSuchResourceException(); } } else { ResourceLocalServiceUtil.getResource( layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid())); } } catch (NoSuchResourceException nsre) { boolean addGroupPermission = true; boolean addGuestPermission = true; if (layout.isPrivateLayout()) { addGuestPermission = false; } ResourceLocalServiceUtil.addResources( layout.getCompanyId(), layout.getGroupId(), 0, Layout.class.getName(), layout.getPlid(), false, addGroupPermission, addGuestPermission); } return permissionChecker.hasPermission( layout.getGroupId(), Layout.class.getName(), layout.getPlid(), actionId); }
@Override protected void doReindex(Object obj) throws Exception { if (obj instanceof Long) { long userId = (Long) obj; User user = UserLocalServiceUtil.getUserById(userId); doReindex(user); } else if (obj instanceof long[]) { long[] userIds = (long[]) obj; Map<Long, Collection<Document>> documentsMap = new HashMap<>(); for (long userId : userIds) { User user = UserLocalServiceUtil.getUserById(userId); if (user.isDefaultUser()) { continue; } Document document = getDocument(user); long companyId = user.getCompanyId(); Collection<Document> documents = documentsMap.get(companyId); if (documents == null) { documents = new ArrayList<>(); documentsMap.put(companyId, documents); } documents.add(document); } for (Map.Entry<Long, Collection<Document>> entry : documentsMap.entrySet()) { long companyId = entry.getKey(); Collection<Document> documents = entry.getValue(); SearchEngineUtil.updateDocuments( getSearchEngineId(), companyId, documents, isCommitImmediately()); } } else if (obj instanceof User) { User user = (User) obj; if (user.isDefaultUser()) { return; } Document document = getDocument(user); SearchEngineUtil.updateDocument( getSearchEngineId(), user.getCompanyId(), document, isCommitImmediately()); Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Contact.class); try { indexer.reindex(user.getContact()); } catch (NoSuchContactException nscce) { // This is a temporary workaround for LPS-46825 } } }
@AccessControlled(guestAccessEnabled = true) @Override public SyncContext getSyncContext() throws PortalException { try { User user = getGuestOrUser(); SyncContext syncContext = new SyncContext(); String authType = PrefsPropsUtil.getString( CompanyThreadLocal.getCompanyId(), PropsKeys.COMPANY_SECURITY_AUTH_TYPE, PropsUtil.get(PropsKeys.COMPANY_SECURITY_AUTH_TYPE)); syncContext.setAuthType(authType); boolean oAuthEnabled = PrefsPropsUtil.getBoolean( user.getCompanyId(), PortletPropsKeys.SYNC_OAUTH_ENABLED, PortletPropsValues.SYNC_OAUTH_ENABLED); if (oAuthEnabled) { String oAuthConsumerKey = PrefsPropsUtil.getString(user.getCompanyId(), PortletPropsKeys.SYNC_OAUTH_CONSUMER_KEY); syncContext.setOAuthConsumerKey(oAuthConsumerKey); String oAuthConsumerSecret = PrefsPropsUtil.getString( user.getCompanyId(), PortletPropsKeys.SYNC_OAUTH_CONSUMER_SECRET); syncContext.setOAuthConsumerSecret(oAuthConsumerSecret); } syncContext.setOAuthEnabled(oAuthEnabled); PluginPackage syncWebPluginPackage = DeployManagerUtil.getInstalledPluginPackage("sync-web"); syncContext.setPluginVersion(syncWebPluginPackage.getVersion()); if (!user.isDefaultUser()) { syncContext.setPortalBuildNumber(ReleaseInfo.getBuildNumber()); PluginPackage soPortletPluginPackage = DeployManagerUtil.getInstalledPluginPackage("so-portlet"); syncContext.setPortletPreferencesMap(getPortletPreferencesMap()); if (soPortletPluginPackage != null) { syncContext.setSocialOfficeInstalled(true); } else { syncContext.setSocialOfficeInstalled(false); } syncContext.setUser(user); syncContext.setUserSitesGroups(getUserSitesGroups()); } return syncContext; } catch (PortalException pe) { throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe); } }
/** * Returns the user's groups "sites" associated with the group entity class names, * including the Control Panel group if the user is permitted to view the Control Panel. * * <ul> * <li>Class name "User" includes the user's layout set group. * <li>Class name "Organization" includes the user's immediate organization groups and * inherited organization groups. * <li>Class name "Group" includes the user's immediate organization groups and site * groups. * <li>A <code>classNames</code> value of <code>null</code> includes the user's layout set * group, organization groups, inherited organization groups, and site groups. * </ul> * * @param userId the primary key of the user * @param classNames the group entity class names (optionally <code>null</code>). For more * information see {@link #getUserSitesGroups(long, String[], int)}. * @param max the maximum number of groups to return * @return the user's groups "sites" * @throws PortalException if a portal exception occurred */ @Override public List<Group> getUserSitesGroups(long userId, String[] classNames, int max) throws PortalException { User user = userPersistence.findByPrimaryKey(userId); if (user.isDefaultUser()) { return Collections.emptyList(); } Set<Group> userSiteGroups = new LinkedHashSet<>(); if (classNames == null) { classNames = new String[] { Company.class.getName(), Group.class.getName(), Organization.class.getName(), User.class.getName() }; } if (ArrayUtil.contains(classNames, User.class.getName())) { if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) { userSiteGroups.add(user.getGroup()); if (userSiteGroups.size() == max) { return new ArrayList<>(userSiteGroups); } } } if (ArrayUtil.contains(classNames, Company.class.getName())) { Group companyGroup = groupLocalService.getCompanyGroup(user.getCompanyId()); if (GroupPermissionUtil.contains( getPermissionChecker(), companyGroup, ActionKeys.VIEW_SITE_ADMINISTRATION)) { userSiteGroups.add(companyGroup); if (userSiteGroups.size() == max) { return new ArrayList<>(userSiteGroups); } } } if (ArrayUtil.contains(classNames, Group.class.getName()) || ArrayUtil.contains(classNames, Organization.class.getName())) { UserBag userBag = UserBagFactoryUtil.create(userId); if (ArrayUtil.contains(classNames, Group.class.getName())) { for (Group group : userBag.getUserGroups()) { if (group.isActive() && group.isSite()) { if (userSiteGroups.add(group) && (userSiteGroups.size() == max)) { return new ArrayList<>(userSiteGroups); } } } } if (ArrayUtil.contains(classNames, Organization.class.getName())) { for (Group group : userBag.getUserOrgGroups()) { if (group.isActive() && group.isSite()) { if (userSiteGroups.add(group) && (userSiteGroups.size() == max)) { return new ArrayList<>(userSiteGroups); } } } } } return new ArrayList<>(userSiteGroups); }
@Override protected void processFilter( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { String remoteAddr = request.getRemoteAddr(); if (AccessControlUtil.isAccessAllowed(request, _hostsAllowed)) { if (_log.isDebugEnabled()) { _log.debug("Access allowed for " + remoteAddr); } } else { if (_log.isWarnEnabled()) { _log.warn("Access denied for " + remoteAddr); } response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access denied for " + remoteAddr); return; } if (_log.isDebugEnabled()) { if (_httpsRequired) { _log.debug("https is required"); } else { _log.debug("https is not required"); } } if (_httpsRequired && !request.isSecure()) { if (_log.isDebugEnabled()) { String completeURL = HttpUtil.getCompleteURL(request); _log.debug("Securing " + completeURL); } StringBundler redirectURL = new StringBundler(5); redirectURL.append(Http.HTTPS_WITH_SLASH); redirectURL.append(request.getServerName()); redirectURL.append(request.getServletPath()); String queryString = request.getQueryString(); if (Validator.isNotNull(queryString)) { redirectURL.append(StringPool.QUESTION); redirectURL.append(request.getQueryString()); } if (_log.isDebugEnabled()) { _log.debug("Redirect to " + redirectURL); } response.sendRedirect(redirectURL.toString()); } else { if (_log.isDebugEnabled()) { String completeURL = HttpUtil.getCompleteURL(request); _log.debug("Not securing " + completeURL); } User user = PortalUtil.getUser(request); if (user == null) { user = PortalUtil.initUser(request); } initThreadLocals(user); if (!user.isDefaultUser()) { request = setCredentials(request, request.getSession(), user.getUserId(), null); } else { if (_digestAuthEnabled) { request = digestAuth(request, response); } else if (_basicAuthEnabled) { request = basicAuth(request, response); } } if (request != null) { processFilter(getClass(), request, response, filterChain); } } }
/** * Adds or increments activity counters related to an activity. This method is called * asynchronously from the social activity service when the user performs an activity defined in * </code>liferay-social.xml</code>. * * <p>This method first calls the activity processor class, if there is one defined for the * activity, checks for limits and increments all the counters that belong to the activity. * Afterwards, it processes the activity with respect to achievement classes, if any. Lastly it * increments the built-in <code>user.activities</code> and <code>asset.activities</code> * counters. * * @param activity the social activity * @throws PortalException if an expected group or expected previous activity counters could not * be found */ @Override public void addActivityCounters(SocialActivity activity) throws PortalException { if (!socialActivitySettingLocalService.isEnabled( activity.getGroupId(), activity.getClassNameId())) { return; } if (!socialActivitySettingLocalService.isEnabled( activity.getGroupId(), activity.getClassNameId(), activity.getClassPK())) { return; } if ((activity.getType() == SocialActivityConstants.TYPE_MOVE_ATTACHMENT_TO_TRASH) || (activity.getType() == SocialActivityConstants.TYPE_MOVE_TO_TRASH)) { disableActivityCounters(activity.getClassNameId(), activity.getClassPK()); return; } if ((activity.getType() == SocialActivityConstants.TYPE_RESTORE_ATTACHMENT_FROM_TRASH) || (activity.getType() == SocialActivityConstants.TYPE_RESTORE_FROM_TRASH)) { enableActivityCounters(activity.getClassNameId(), activity.getClassPK()); return; } User user = userPersistence.findByPrimaryKey(activity.getUserId()); SocialActivityDefinition activityDefinition = socialActivitySettingLocalService.getActivityDefinition( activity.getGroupId(), activity.getClassName(), activity.getType()); if ((activityDefinition == null) || !activityDefinition.isCountersEnabled()) { return; } SocialActivityProcessor activityProcessor = activityDefinition.getActivityProcessor(); if (activityProcessor != null) { activityProcessor.processActivity(activity); } AssetEntry assetEntry = activity.getAssetEntry(); User assetEntryUser = userPersistence.findByPrimaryKey(assetEntry.getUserId()); List<SocialActivityCounter> activityCounters = new ArrayList<>(); for (SocialActivityCounterDefinition activityCounterDefinition : activityDefinition.getActivityCounterDefinitions()) { if (isAddActivityCounter(user, assetEntryUser, assetEntry, activityCounterDefinition)) { SocialActivityCounter activityCounter = addActivityCounter(activity.getGroupId(), user, activity, activityCounterDefinition); activityCounters.add(activityCounter); } } SocialActivityCounter assetActivitiesCounter = null; if (!assetEntryUser.isDefaultUser() && assetEntryUser.isActive() && assetEntry.isVisible()) { assetActivitiesCounter = addAssetActivitiesCounter(activity); } SocialActivityCounter userActivitiesCounter = null; if (!user.isDefaultUser() && user.isActive()) { userActivitiesCounter = addUserActivitiesCounter(activity); } for (SocialActivityCounter activityCounter : activityCounters) { SocialActivityCounterDefinition activityCounterDefinition = activityDefinition.getActivityCounterDefinition(activityCounter.getName()); if (checkActivityLimit(user, activity, activityCounterDefinition)) { incrementActivityCounter(activityCounter, activityCounterDefinition); } } if (assetActivitiesCounter != null) { incrementActivityCounter(assetActivitiesCounter, _assetActivitiesActivityCounterDefinition); } if (userActivitiesCounter != null) { incrementActivityCounter(userActivitiesCounter, _userActivitiesActivityCounterDefinition); } for (SocialAchievement achievement : activityDefinition.getAchievements()) { achievement.processActivity(activity); } }