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;
}
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;
}
}
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);
}
}
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);
}
}
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();
}
Aggregations