Search in sources :

Example 56 with IGroupMember

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

the class ApiGroupsService method getMembersForGroup.

@Override
public Set<Entity> getMembersForGroup(String groupName) {
    Set<Entity> members = new HashSet<Entity>();
    if (StringUtils.isNotEmpty(groupName)) {
        EntityIdentifier[] identifiers = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, EntityEnum.GROUP.getClazz());
        for (EntityIdentifier entityIdentifier : identifiers) {
            if (entityIdentifier.getType().equals(IEntityGroup.class)) {
                IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
                if (groupMember.getLeafType().equals(IPerson.class)) {
                    String groupMemberName = EntityService.instance().lookupEntityName(EntityEnum.GROUP, groupMember.getKey());
                    if (groupName.equalsIgnoreCase(groupMemberName)) {
                        for (IGroupMember gm : groupMember.asGroup().getDescendants()) {
                            if (!gm.isGroup()) {
                                EntityIdentifier ident = gm.getUnderlyingEntityIdentifier();
                                Entity member = findMember(ident.getKey(), true);
                                members.add(member);
                            }
                        }
                        return members;
                    }
                }
            }
        }
    }
    return members;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 57 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 58 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)

Aggregations

IGroupMember (org.apereo.portal.groups.IGroupMember)58 IEntityGroup (org.apereo.portal.groups.IEntityGroup)33 HashSet (java.util.HashSet)20 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)16 ArrayList (java.util.ArrayList)14 EntityIdentifier (org.apereo.portal.EntityIdentifier)13 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)13 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)10 IPermission (org.apereo.portal.security.IPermission)9 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)7 GroupsException (org.apereo.portal.groups.GroupsException)6 IPerson (org.apereo.portal.security.IPerson)6 HashMap (java.util.HashMap)4 IEntity (org.apereo.portal.groups.IEntity)4 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)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