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) {
Set<UniquePermission> directAssignments = new HashSet<>();
// 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<>();
List<JsonPermission> permissions = new ArrayList<>();
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 JsonEntityBeanTest method testEqualsEntityTypeDiff.
@Test
public void testEqualsEntityTypeDiff() {
EntityEnum val1 = EntityEnum.PORTLET;
EntityEnum val2 = EntityEnum.CATEGORY;
JsonEntityBean jeb1 = buildNullBean();
jeb1.setChildrenInitialized(true);
jeb1.setCreatorId("");
jeb1.setDescription("");
jeb1.setEntityType(val1);
JsonEntityBean jeb2 = buildNullBean();
jeb2.setChildrenInitialized(true);
jeb2.setCreatorId("");
jeb2.setDescription("");
jeb2.setEntityType(val2);
assertEquals(val1.equals(val2), jeb1.equals(jeb2));
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class JsonEntityBeanTest method buildNullBean.
private JsonEntityBean buildNullBean() {
JsonEntityBean jeb = new JsonEntityBean(groupMember, EntityEnum.PORTLET);
EntityEnum ee = null;
jeb.setEntityType(ee);
jeb.setChildrenInitialized(false);
jeb.setCreatorId(null);
jeb.setDescription(null);
jeb.setId(null);
jeb.setName(null);
return jeb;
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class JsonEntityBeanTest method testCompareToDiffEntityType.
@Test
public void testCompareToDiffEntityType() {
EntityEnum val1 = EntityEnum.GROUP;
EntityEnum val2 = EntityEnum.CATEGORY;
JsonEntityBean jeb1 = buildBeanFromEntityGroup();
jeb1.setEntityType(val1);
JsonEntityBean jeb2 = buildBeanFromEntityGroup();
jeb2.setEntityType(val2);
assertEquals(val1.compareTo(val2), jeb1.compareTo(jeb2));
}
use of org.apereo.portal.portlets.groupselector.EntityEnum in project uPortal by Jasig.
the class JsonEntityBeanTest method testGetTypeAndIdHashEntityEnumNull.
@Test(expected = java.lang.AssertionError.class)
public void testGetTypeAndIdHashEntityEnumNull() {
EntityEnum ee = null;
JsonEntityBean jeb = buildBeanFromEntityGroup();
jeb.setEntityType(ee);
jeb.getTypeAndIdHash();
}
Aggregations