Search in sources :

Example 16 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum 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;
    }
    final EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    if (entityEnum == null) {
        throw new RuntimeException("EntityEnum instance not found for specified type:  " + 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) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Example 17 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum 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;
    }
    final Set<Entity> results = new HashSet<>();
    final EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    if (entityEnum == null) {
        throw new RuntimeException("EntityEnum instance not found for specified type:  " + entityType);
    }
    // if the entity type is a group, use the group service's findGroup method
    // to locate it
    EntityIdentifier[] identifiers;
    Class<?> identifierType;
    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 18 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImplTest method testGetEntityTypePortlet.

@Test
public void testGetEntityTypePortlet() {
    GroupListHelperImpl helper = new GroupListHelperImpl();
    IGroupMember mocked = manuallyMockGroupMember(IPortletDefinition.class);
    EntityEnum ee = helper.getEntityType(mocked);
    assertEquals("portlet", ee.toString());
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) GroupListHelperImpl(org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl) Test(org.junit.Test)

Example 19 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.

the class GroupListHelperImplTest method testGetEntityTypeCategory.

@Test
public void testGetEntityTypeCategory() {
    GroupListHelperImpl helper = new GroupListHelperImpl();
    MockedGroupMemberEntityGroup mocked = new MockedGroupMemberEntityGroup(IPortletDefinition.class);
    EntityEnum ee = helper.getEntityType(mocked);
    assertEquals("category", ee.toString());
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) GroupListHelperImpl(org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl) Test(org.junit.Test)

Example 20 with EntityEnum

use of org.apereo.portal.portlets.groupselector.EntityEnum 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)

Aggregations

EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)29 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)14 IEntityGroup (org.apereo.portal.groups.IEntityGroup)13 IGroupMember (org.apereo.portal.groups.IGroupMember)13 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 GroupListHelperImpl (org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl)4 ArrayList (java.util.ArrayList)3 EntityIdentifier (org.apereo.portal.EntityIdentifier)3 Principal (org.apereo.portal.api.Principal)2 PrincipalImpl (org.apereo.portal.api.PrincipalImpl)2 IPermission (org.apereo.portal.security.IPermission)2 RuntimeAuthorizationException (org.apereo.portal.security.RuntimeAuthorizationException)2 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 TreeSet (java.util.TreeSet)1 IEntityNameFinder (org.apereo.portal.groups.IEntityNameFinder)1