Search in sources :

Example 11 with EntityEnum

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

the class JsonEntityBeanTest method testEqualsEntityTypeNullTarget.

@Test
public void testEqualsEntityTypeNullTarget() {
    EntityEnum ee = null;
    JsonEntityBean jeb1 = buildNullBean();
    jeb1.setChildrenInitialized(true);
    jeb1.setCreatorId("");
    jeb1.setDescription("");
    jeb1.setEntityType(EntityEnum.PORTLET);
    JsonEntityBean jeb2 = buildNullBean();
    jeb2.setChildrenInitialized(true);
    jeb2.setCreatorId("");
    jeb2.setDescription("");
    jeb2.setEntityType(ee);
    assertFalse(jeb1.equals(jeb2));
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

Example 12 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;
    }
    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 13 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;
    }
    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 14 with EntityEnum

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

the class EntityService method getEntity.

public Entity getEntity(IGroupMember member) {
    if (member == null) {
        return null;
    }
    // get the type of this member entity
    EntityEnum entityEnum = getEntityType(member);
    // construct a new entity bean for this entity
    Entity entity;
    if (entityEnum.isGroup()) {
        entity = EntityFactory.createEntity((IEntityGroup) member, entityEnum);
    } else {
        entity = EntityFactory.createEntity(member, entityEnum);
    }
    // if the name hasn't been set yet, look up the entity name
    if (entity.getName() == null) {
        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) 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 15 with EntityEnum

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

the class EntityService method getEntity.

public Entity getEntity(IGroupMember member) {
    if (member == null) {
        return null;
    }
    // get the type of this member entity
    EntityEnum entityEnum = getEntityType(member);
    // construct a new entity bean for this entity
    Entity entity;
    if (entityEnum.isGroup()) {
        entity = EntityFactory.createEntity((IEntityGroup) member, entityEnum);
    } else {
        entity = EntityFactory.createEntity(member, entityEnum);
    }
    // if the name hasn't been set yet, look up the entity name
    if (entity.getName() == null) {
        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) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) 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