Search in sources :

Example 36 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class EntityService method search.

// External search, thus case insensitive.
public Set<Entity> search(String entityType, String searchTerm) {
    if (StringUtils.isBlank(entityType) && StringUtils.isBlank(searchTerm)) {
        return null;
    }
    Set<Entity> results = new HashSet<Entity>();
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    EntityIdentifier[] identifiers;
    Class<?> identifierType;
    // to locate it
    if (entityEnum.isGroup()) {
        identifiers = GroupService.searchForGroups(searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz());
        identifierType = IEntityGroup.class;
    } else // otherwise use the getGroupMember method
    {
        identifiers = GroupService.searchForEntities(searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz());
        identifierType = entityEnum.getClazz();
    }
    for (EntityIdentifier entityIdentifier : identifiers) {
        if (entityIdentifier.getType().equals(identifierType)) {
            IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
            Entity entity = getEntity(groupMember);
            results.add(entity);
        }
    }
    return results;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 37 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class EntityService method getEntity.

public Entity getEntity(String entityType, String entityId, boolean populateChildren) {
    // get the EntityEnum for the specified entity type
    if (StringUtils.isBlank(entityType) && StringUtils.isBlank(entityId)) {
        return null;
    }
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    // to locate it
    if (entityEnum.isGroup()) {
        // attempt to find the entity
        IEntityGroup entityGroup = GroupService.findGroup(entityId);
        if (entityGroup == null) {
            return null;
        } else {
            Entity entity = EntityFactory.createEntity(entityGroup, entityEnum);
            if (populateChildren) {
                Iterator<IGroupMember> members = entityGroup.getChildren().iterator();
                entity = populateChildren(entity, members);
            }
            IAuthorizationPrincipal authP = getPrincipalForEntity(entity);
            Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());
            entity.setPrincipal(principal);
            return entity;
        }
    } else // otherwise use the getGroupMember method
    {
        IGroupMember groupMember = GroupService.getGroupMember(entityId, entityEnum.getClazz());
        if (groupMember == null || groupMember instanceof IEntityGroup) {
            return null;
        }
        Entity entity = EntityFactory.createEntity(groupMember, entityEnum);
        // the group member interface doesn't include the entity name, so
        // we'll need to look that up manually
        entity.setName(lookupEntityName(entity));
        if (EntityEnum.GROUP.toString().equals(entity.getEntityType()) || EntityEnum.PERSON.toString().equals(entity.getEntityType())) {
            IAuthorizationPrincipal authP = getPrincipalForEntity(entity);
            Principal principal = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());
            entity.setPrincipal(principal);
        }
        return entity;
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) Principal(org.apereo.portal.api.Principal) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PrincipalImpl(org.apereo.portal.api.PrincipalImpl)

Example 38 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class PermissionAssignmentMapController method placeInHierarchy.

private void placeInHierarchy(Assignment a, List<Assignment> hierarchy, String owner, String activity, String target) {
    // Assertions.
    if (a == null) {
        String msg = "Argument 'a' [Assignment] cannot be null";
        throw new IllegalArgumentException(msg);
    }
    if (hierarchy == null) {
        String msg = "Argument 'hierarchy' cannot be null";
        throw new IllegalArgumentException(msg);
    }
    // is already in the hierarchy somewhere...
    for (Assignment root : hierarchy) {
        Assignment duplicate = root.findDecendentOrSelfIfExists(a.getPrincipal());
        if (duplicate != null) {
            return;
        }
    }
    // To proceed, we need to know about the containing
    // groups (if any) for this principal...
    IGroupMember member = null;
    EntityEnum entityEnum = a.getPrincipal().getEntityType();
    if (entityEnum.isGroup()) {
        member = GroupService.findGroup(a.getPrincipal().getId());
    } else {
        member = GroupService.getGroupMember(a.getPrincipal().getId(), entityEnum.getClazz());
    }
    AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
    Iterator<?> it = GroupService.getCompositeGroupService().findParentGroups(member);
    if (it.hasNext()) {
        // This member must be nested within its parent(s)...
        while (it.hasNext()) {
            IEntityGroup group = (IEntityGroup) it.next();
            EntityEnum beanType = EntityEnum.getEntityEnum(group.getLeafType(), true);
            JsonEntityBean bean = new JsonEntityBean(group, beanType);
            Assignment parent = null;
            for (Assignment root : hierarchy) {
                parent = root.findDecendentOrSelfIfExists(bean);
                if (parent != null) {
                    // We found one...
                    parent.addChild(a);
                    break;
                }
            }
            if (parent == null) {
                // We weren't able to integrate this node into the existing
                // hierarchy;  we have to dig deeper, until we either (1)
                // find a match, or (2) reach a root;  type is INHERIT,
                // unless (by chance) there's something specified in an
                // entry on grantOrDenyMap.
                IAuthorizationPrincipal principal = authService.newPrincipal(group);
                Assignment.Type assignmentType = getAssignmentType(principal, owner, activity, target);
                parent = new Assignment(principal.getPrincipalString(), bean, assignmentType);
                parent.addChild(a);
                placeInHierarchy(parent, hierarchy, owner, activity, target);
            }
        }
    } else {
        // This member is a root...
        hierarchy.add(a);
    }
}
Also used : Assignment(org.apereo.portal.portlets.permissionsadmin.Assignment) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) AuthorizationServiceFacade(org.apereo.portal.services.AuthorizationServiceFacade) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Example 39 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class GroupService method ifinishedSession.

/**
 * Receives notice that the UserInstance has been unbound from the HttpSession. In response, we
 * remove the corresponding group member from the cache. We use the roundabout route of creating
 * a group member and then getting its EntityIdentifier because we need the EntityIdentifier for
 * the group member, which is cached, not the EntityIdentifier for the IPerson, which is not.
 *
 * @param person org.apereo.portal.security.IPerson
 */
private void ifinishedSession(IPerson person) throws GroupsException {
    IGroupMember gm = getGroupMember(person.getEntityIdentifier());
    try {
        final EntityIdentifier entityIdentifier = gm.getEntityIdentifier();
        EntityCachingService.getEntityCachingService().remove(entityIdentifier.getType(), entityIdentifier.getKey());
    } catch (CachingException ce) {
        throw new GroupsException("Problem removing group member " + gm.getKey() + " from cache", ce);
    }
}
Also used : CachingException(org.apereo.portal.concurrency.CachingException) IGroupMember(org.apereo.portal.groups.IGroupMember) GroupsException(org.apereo.portal.groups.GroupsException) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 40 with IGroupMember

use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.

the class GrouperEntityGroupStore method updateMembers.

/**
 * @see IEntityGroupStore#updateMembers(IEntityGroup)
 */
public void updateMembers(IEntityGroup group) throws GroupsException {
    // assume key is fully qualified group name
    String groupName = group.getLocalKey();
    GcAddMember gcAddMember = new GcAddMember().assignGroupName(groupName);
    for (IGroupMember iGroupMember : group.getChildren()) {
        EntityIdentifier entityIdentifier = iGroupMember.getEntityIdentifier();
        String identifier = entityIdentifier.getKey();
        gcAddMember.addSubjectIdentifier(identifier);
    }
    gcAddMember.execute();
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityIdentifier(org.apereo.portal.EntityIdentifier) GcAddMember(edu.internet2.middleware.grouperClient.api.GcAddMember)

Aggregations

IGroupMember (org.apereo.portal.groups.IGroupMember)52 IEntityGroup (org.apereo.portal.groups.IEntityGroup)29 HashSet (java.util.HashSet)17 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)14 ArrayList (java.util.ArrayList)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)12 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)10 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 IPermission (org.apereo.portal.security.IPermission)8 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)7 GroupsException (org.apereo.portal.groups.GroupsException)6 HashMap (java.util.HashMap)4 IEntity (org.apereo.portal.groups.IEntity)4 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)4 IPerson (org.apereo.portal.security.IPerson)4 Element (net.sf.ehcache.Element)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)3 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)3 GcGetMembers (edu.internet2.middleware.grouperClient.api.GcGetMembers)2 WsGetMembersResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults)2