Search in sources :

Example 21 with EntityEnum

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;
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IPermission(org.apereo.portal.security.IPermission) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with EntityEnum

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));
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

Example 23 with EntityEnum

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;
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 24 with EntityEnum

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));
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

Example 25 with EntityEnum

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();
}
Also used : EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

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