Search in sources :

Example 16 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class UserLocalServiceImpl method addDefaultGroups.

/**
 * Adds the user to the default groups, unless the user is already in these
 * groups. The default groups can be specified in
 * <code>portal.properties</code> with the key
 * <code>admin.default.group.names</code>.
 *
 * @param  userId the primary key of the user
 * @throws PortalException if a user with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public void addDefaultGroups(long userId) throws PortalException, SystemException {
    User user = userPersistence.findByPrimaryKey(userId);
    Set<Long> groupIdsSet = new HashSet<Long>();
    String[] defaultGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_GROUP_NAMES);
    for (String defaultGroupName : defaultGroupNames) {
        Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
        Account account = company.getAccount();
        if (StringUtil.equalsIgnoreCase(defaultGroupName, account.getName())) {
            defaultGroupName = GroupConstants.GUEST;
        }
        Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultGroupName);
        if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
            groupIdsSet.add(group.getGroupId());
        }
    }
    String[] defaultOrganizationGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES);
    for (String defaultOrganizationGroupName : defaultOrganizationGroupNames) {
        defaultOrganizationGroupName += GroupLocalServiceImpl.ORGANIZATION_NAME_SUFFIX;
        Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultOrganizationGroupName);
        if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
            groupIdsSet.add(group.getGroupId());
        }
    }
    long[] groupIds = ArrayUtil.toArray(groupIdsSet.toArray(new Long[groupIdsSet.size()]));
    groupLocalService.addUserGroups(userId, groupIds);
}
Also used : Account(com.liferay.portal.model.Account) Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User) HashSet(java.util.HashSet)

Example 17 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class SearchPermissionCheckerImpl method doGetPermissionQuery.

protected Query doGetPermissionQuery(long companyId, long[] groupIds, long userId, String className, Query query, SearchContext searchContext) throws Exception {
    Indexer indexer = IndexerRegistryUtil.getIndexer(className);
    if (!indexer.isPermissionAware()) {
        return query;
    }
    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
    AdvancedPermissionChecker advancedPermissionChecker = null;
    if ((permissionChecker != null) && (permissionChecker instanceof AdvancedPermissionChecker)) {
        advancedPermissionChecker = (AdvancedPermissionChecker) permissionChecker;
    }
    if (advancedPermissionChecker == null) {
        return query;
    }
    PermissionCheckerBag permissionCheckerBag = getPermissionCheckerBag(advancedPermissionChecker, userId);
    if (permissionCheckerBag == null) {
        return query;
    }
    List<Group> groups = new UniqueList<Group>();
    List<Role> roles = new UniqueList<Role>();
    List<UserGroupRole> userGroupRoles = new UniqueList<UserGroupRole>();
    Map<Long, List<Role>> groupIdsToRoles = new HashMap<Long, List<Role>>();
    roles.addAll(permissionCheckerBag.getRoles());
    if (ArrayUtil.isEmpty(groupIds)) {
        groups.addAll(GroupLocalServiceUtil.getUserGroups(userId, true));
        groups.addAll(permissionCheckerBag.getGroups());
        userGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId);
    } else {
        groups.addAll(permissionCheckerBag.getGroups());
        for (long groupId : groupIds) {
            if (GroupLocalServiceUtil.hasUserGroup(userId, groupId)) {
                Group group = GroupLocalServiceUtil.getGroup(groupId);
                groups.add(group);
            }
            userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId, groupId));
            userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRolesByUserUserGroupAndGroup(userId, groupId));
        }
    }
    if (advancedPermissionChecker.isSignedIn()) {
        roles.add(RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST));
    }
    for (Group group : groups) {
        PermissionCheckerBag userBag = advancedPermissionChecker.getUserBag(userId, group.getGroupId());
        List<Role> groupRoles = userBag.getRoles();
        groupIdsToRoles.put(group.getGroupId(), groupRoles);
        roles.addAll(groupRoles);
    }
    return doGetPermissionQuery_6(companyId, groupIds, userId, className, query, searchContext, advancedPermissionChecker, groups, roles, userGroupRoles, groupIdsToRoles);
}
Also used : UserGroupRole(com.liferay.portal.model.UserGroupRole) Group(com.liferay.portal.model.Group) HashMap(java.util.HashMap) PermissionCheckerBag(com.liferay.portal.security.permission.PermissionCheckerBag) UniqueList(com.liferay.portal.kernel.util.UniqueList) UserGroupRole(com.liferay.portal.model.UserGroupRole) Role(com.liferay.portal.model.Role) Indexer(com.liferay.portal.kernel.search.Indexer) SearchPermissionChecker(com.liferay.portal.kernel.search.SearchPermissionChecker) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) AdvancedPermissionChecker(com.liferay.portal.security.permission.AdvancedPermissionChecker) AdvancedPermissionChecker(com.liferay.portal.security.permission.AdvancedPermissionChecker) ArrayList(java.util.ArrayList) UniqueList(com.liferay.portal.kernel.util.UniqueList) List(java.util.List)

Example 18 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class SearchPermissionCheckerImpl method doAddPermissionFields_6.

protected void doAddPermissionFields_6(long companyId, long groupId, String className, String classPK, Document doc) throws Exception {
    Group group = null;
    if (groupId > 0) {
        group = GroupLocalServiceUtil.getGroup(groupId);
    }
    List<Role> roles = ListUtil.copy(ResourceActionsUtil.getRoles(companyId, group, className, null));
    if (groupId > 0) {
        List<Role> teamRoles = RoleLocalServiceUtil.getTeamRoles(groupId);
        roles.addAll(teamRoles);
    }
    long[] roleIdsArray = new long[roles.size()];
    for (int i = 0; i < roleIdsArray.length; i++) {
        Role role = roles.get(i);
        roleIdsArray[i] = role.getRoleId();
    }
    boolean[] hasResourcePermissions = null;
    if (ResourceBlockLocalServiceUtil.isSupported(className)) {
        ResourceBlockIdsBag resourceBlockIdsBag = ResourceBlockLocalServiceUtil.getResourceBlockIdsBag(companyId, groupId, className, roleIdsArray);
        long actionId = ResourceBlockLocalServiceUtil.getActionId(className, ActionKeys.VIEW);
        List<Long> resourceBlockIds = resourceBlockIdsBag.getResourceBlockIds(actionId);
        hasResourcePermissions = new boolean[roleIdsArray.length];
        for (long resourceBlockId : resourceBlockIds) {
            for (int i = 0; i < roleIdsArray.length; i++) {
                int count = ResourceBlockPermissionLocalServiceUtil.getResourceBlockPermissionsCount(resourceBlockId, roleIdsArray[i]);
                hasResourcePermissions[i] = (count > 0);
            }
        }
    } else {
        hasResourcePermissions = ResourcePermissionLocalServiceUtil.hasResourcePermissions(companyId, className, ResourceConstants.SCOPE_INDIVIDUAL, classPK, roleIdsArray, ActionKeys.VIEW);
    }
    List<Long> roleIds = new ArrayList<Long>();
    List<String> groupRoleIds = new ArrayList<String>();
    for (int i = 0; i < hasResourcePermissions.length; i++) {
        if (!hasResourcePermissions[i]) {
            continue;
        }
        Role role = roles.get(i);
        if ((role.getType() == RoleConstants.TYPE_ORGANIZATION) || (role.getType() == RoleConstants.TYPE_SITE)) {
            groupRoleIds.add(groupId + StringPool.DASH + role.getRoleId());
        } else {
            roleIds.add(role.getRoleId());
        }
    }
    doc.addKeyword(Field.ROLE_ID, roleIds.toArray(new Long[roleIds.size()]));
    doc.addKeyword(Field.GROUP_ROLE_ID, groupRoleIds.toArray(new String[groupRoleIds.size()]));
}
Also used : Group(com.liferay.portal.model.Group) ArrayList(java.util.ArrayList) UserGroupRole(com.liferay.portal.model.UserGroupRole) Role(com.liferay.portal.model.Role) ResourceBlockIdsBag(com.liferay.portal.security.permission.ResourceBlockIdsBag)

Example 19 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class NewPortlet method doView.

@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long groupId = themeDisplay.getLayout().getGroupId();
    try {
        Group group = GroupLocalServiceUtil.getGroup(groupId);
    } catch (PortalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Group(com.liferay.portal.model.Group) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 20 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class UserLocalServiceImpl method updateGroups.

protected void updateGroups(long userId, long[] newGroupIds, ServiceContext serviceContext, boolean indexingEnabled) throws PortalException, SystemException {
    if (newGroupIds == null) {
        return;
    }
    List<Group> oldGroups = userPersistence.getGroups(userId);
    Set<Long> oldGroupIds = new HashSet<Long>(oldGroups.size());
    for (Group oldGroup : oldGroups) {
        long oldGroupId = oldGroup.getGroupId();
        oldGroupIds.add(oldGroupId);
        if (!ArrayUtil.contains(newGroupIds, oldGroupId)) {
            unsetGroupUsers(oldGroupId, new long[] { userId }, serviceContext);
        }
    }
    for (long newGroupId : newGroupIds) {
        if (!oldGroupIds.contains(newGroupId)) {
            addGroupUsers(newGroupId, new long[] { userId });
        }
    }
    if (indexingEnabled) {
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
        indexer.reindex(new long[] { userId });
    }
    PermissionCacheUtil.clearCache();
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) Indexer(com.liferay.portal.kernel.search.Indexer) HashSet(java.util.HashSet)

Aggregations

Group (com.liferay.portal.model.Group)30 User (com.liferay.portal.model.User)15 UserGroup (com.liferay.portal.model.UserGroup)13 ArrayList (java.util.ArrayList)9 UserGroupRole (com.liferay.portal.model.UserGroupRole)6 Role (com.liferay.portal.model.Role)5 Indexer (com.liferay.portal.kernel.search.Indexer)4 Company (com.liferay.portal.model.Company)4 Contact (com.liferay.portal.model.Contact)3 ServiceContext (com.liferay.portal.service.ServiceContext)3 RestfulCollection (org.apache.shindig.protocol.RestfulCollection)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)2 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)2 NoSuchImageException (com.liferay.portal.NoSuchImageException)2 RequiredUserException (com.liferay.portal.RequiredUserException)2 ReservedUserScreenNameException (com.liferay.portal.ReservedUserScreenNameException)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 Organization (com.liferay.portal.model.Organization)2