Search in sources :

Example 1 with UniqueList

use of com.liferay.portal.kernel.util.UniqueList 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)

Aggregations

Indexer (com.liferay.portal.kernel.search.Indexer)1 SearchPermissionChecker (com.liferay.portal.kernel.search.SearchPermissionChecker)1 UniqueList (com.liferay.portal.kernel.util.UniqueList)1 Group (com.liferay.portal.model.Group)1 Role (com.liferay.portal.model.Role)1 UserGroupRole (com.liferay.portal.model.UserGroupRole)1 AdvancedPermissionChecker (com.liferay.portal.security.permission.AdvancedPermissionChecker)1 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)1 PermissionCheckerBag (com.liferay.portal.security.permission.PermissionCheckerBag)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1