use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class PermissionsRESTController method getAssignmentsOnTarget.
@PreAuthorize("hasPermission('ALL', 'java.lang.String', new org.apereo.portal.spring.security.evaluator.AuthorizableActivity('UP_PERMISSIONS', 'VIEW_PERMISSIONS'))")
@RequestMapping("/assignments/target/{target}.json")
public ModelAndView getAssignmentsOnTarget(@PathVariable("target") String target, @RequestParam(value = "includeInherited", required = false) boolean includeInherited, HttpServletRequest request, HttpServletResponse response) {
Set<UniquePermission> directAssignments = new HashSet<UniquePermission>();
// first get the permissions explicitly set for this principal
IPermission[] directPermissions = permissionStore.select(null, null, null, target, null);
for (IPermission permission : directPermissions) {
directAssignments.add(new UniquePermission(permission.getOwner(), permission.getActivity(), permission.getPrincipal(), false));
}
JsonEntityBean entity = groupListHelper.getEntityForPrincipal(target);
Set<UniquePermission> inheritedAssignments = new HashSet<UniquePermission>();
List<JsonPermission> permissions = new ArrayList<JsonPermission>();
if (entity != null) {
IAuthorizationPrincipal p = this.authorizationService.newPrincipal(entity.getId(), entity.getEntityType().getClazz());
if (includeInherited) {
IGroupMember member = GroupService.getGroupMember(p.getKey(), p.getType());
for (IEntityGroup parent : member.getAncestorGroups()) {
IAuthorizationPrincipal parentPrincipal = this.authorizationService.newPrincipal(parent);
IPermission[] parentPermissions = permissionStore.select(null, null, null, parentPrincipal.getKey(), null);
for (IPermission permission : parentPermissions) {
inheritedAssignments.add(new UniquePermission(permission.getOwner(), permission.getActivity(), permission.getPrincipal(), true));
}
}
}
for (UniquePermission permission : directAssignments) {
JsonEntityBean e = groupListHelper.getEntityForPrincipal(permission.getIdentifier());
Class<?> clazz;
EntityEnum entityType = EntityEnum.getEntityEnum(e.getEntityTypeAsString());
if (entityType.isGroup()) {
clazz = IEntityGroup.class;
} else {
clazz = entityType.getClazz();
}
IAuthorizationPrincipal principal = this.authorizationService.newPrincipal(e.getId(), clazz);
if (principal.hasPermission(permission.getOwner(), permission.getActivity(), p.getKey())) {
permissions.add(getPermissionOnTarget(permission, entity));
}
}
for (UniquePermission permission : inheritedAssignments) {
JsonEntityBean e = groupListHelper.getEntityForPrincipal(permission.getIdentifier());
Class<?> clazz;
EntityEnum entityType = EntityEnum.getEntityEnum(e.getEntityTypeAsString());
if (entityType.isGroup()) {
clazz = IEntityGroup.class;
} else {
clazz = entityType.getClazz();
}
IAuthorizationPrincipal principal = this.authorizationService.newPrincipal(e.getId(), clazz);
if (principal.hasPermission(permission.getOwner(), permission.getActivity(), p.getKey())) {
permissions.add(getPermissionOnTarget(permission, entity));
}
}
Collections.sort(permissions);
}
ModelAndView mv = new ModelAndView();
mv.addObject("assignments", permissions);
mv.setViewName("json");
return mv;
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImpl method lookupEntityName.
/**
* Convenience method that looks up the name of the given group member. Used for person types.
*
* @param groupMember Entity to look up
* @return groupMember's name or null if there's an error
*/
@Override
public String lookupEntityName(JsonEntityBean entity) {
if (entity == null) {
throw new IllegalArgumentException("Parameter cannot be null.");
}
EntityEnum entityEnum = entity.getEntityType();
if (entityEnum == null) {
throw new IllegalArgumentException(String.format("Parameter's entityType has an unknown value of [%s]", entity.getEntityType()));
}
IEntityNameFinder finder;
if (entityEnum.isGroup()) {
finder = EntityNameFinderService.instance().getNameFinder(IEntityGroup.class);
} else {
finder = EntityNameFinderService.instance().getNameFinder(entityEnum.getClazz());
}
try {
return finder.getName(entity.getId());
} catch (Exception e) {
/* An exception here isn't the end of the world. Just log it
and return null. */
log.warn("Couldn't find name for entity " + entity.getId(), e);
return null;
}
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImpl method search.
/*
* (non-Javadoc)
* @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#search(java.lang.String, java.lang.String)
*
* External search, thus case insensitive.
*
*/
@SuppressWarnings("unchecked")
@Override
public Set<JsonEntityBean> search(String entityType, String searchTerm) {
Set<JsonEntityBean> results = new HashSet<>();
EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
if (entityEnum == null) {
throw new IllegalArgumentException(String.format("Parameter entityType has an unknown value of [%s]", 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 (int i = 0; i < identifiers.length; i++) {
if (identifiers[i].getType().equals(identifierType)) {
IGroupMember entity = GroupService.getGroupMember(identifiers[i]);
if (entity != null) {
JsonEntityBean jsonBean = getEntity(entity);
results.add(jsonBean);
} else {
log.warn("Grouper member entity of " + identifiers[i].getKey() + " is null.");
}
}
}
return results;
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImpl method getRootEntity.
/*
* (non-Javadoc)
* @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getRootEntity(java.lang.String)
*/
@Override
public JsonEntityBean getRootEntity(String groupType) {
EntityEnum type = EntityEnum.getEntityEnum(groupType);
String rootKey;
if (EntityEnum.GROUP.equals(type)) {
rootKey = "local.0";
} else if (EntityEnum.CATEGORY.equals(type)) {
IEntityGroup categoryGroup = GroupService.getDistinguishedGroup(IPortletDefinition.DISTINGUISHED_GROUP);
return new JsonEntityBean(categoryGroup, EntityEnum.CATEGORY);
} else {
throw new IllegalArgumentException("Unable to determine a root entity for group type '" + groupType + "'");
}
JsonEntityBean bean = getEntity(groupType, rootKey, false);
return bean;
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class GroupListHelperImpl method getPrincipalForEntity.
@Override
public IAuthorizationPrincipal getPrincipalForEntity(JsonEntityBean entity) {
if (entity == null) {
throw new IllegalArgumentException("Parameter cannot be null.");
}
// attempt to determine the entity type class for this principal
Class entityType;
EntityEnum jsonType = entity.getEntityType();
if (jsonType == null) {
throw new IllegalArgumentException("Parameter's entityType cannot be null.");
}
if (jsonType.isGroup()) {
entityType = IEntityGroup.class;
} else {
entityType = jsonType.getClazz();
}
// construct an authorization principal for this JsonEntityBean
AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
IAuthorizationPrincipal p = authService.newPrincipal(entity.getId(), entityType);
return p;
}
Aggregations