Search in sources :

Example 46 with JsonEntityBean

use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.

the class PortletAdministrationHelper method addSubscribePermissionsToForm.

/*
     * Add to the form SUBSCRIBE and BROWSE activity permissions, along with their principals,
     * assigned to the portlet.
     */
private void addSubscribePermissionsToForm(IPortletDefinition def, PortletDefinitionForm form) {
    final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);
    /* We are concerned with PORTAL_SUBSCRIBE system */
    final IPermissionManager pm = authorizationService.newPermissionManager(IPermission.PORTAL_SUBSCRIBE);
    for (String activity : PORTLET_SUBSCRIBE_ACTIVITIES) {
        /* Obtain the principals that have permission for the activity on this portlet */
        final IAuthorizationPrincipal[] principals = pm.getAuthorizedPrincipals(activity, portletTargetId);
        for (IAuthorizationPrincipal principal : principals) {
            JsonEntityBean principalBean;
            // first assume this is a group
            IEntityGroup group = GroupService.findGroup(principal.getKey());
            if (group != null) {
                // principal is a group
                principalBean = new JsonEntityBean(group, EntityEnum.GROUP);
            } else {
                // not a group, so it must be a person
                IGroupMember member = authorizationService.getGroupMember(principal);
                principalBean = new JsonEntityBean(member, EntityEnum.PERSON);
                // set the name
                String name = groupListHelper.lookupEntityName(principalBean);
                principalBean.setName(name);
            }
            /* Make sure we capture the principal just once*/
            if (!form.getPrincipals().contains(principalBean)) {
                form.addPrincipal(principalBean);
            }
            form.addPermission(principalBean.getTypeAndIdHash() + "_" + activity);
        }
    }
}
Also used : IPermissionManager(org.apereo.portal.security.IPermissionManager) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Example 47 with JsonEntityBean

use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.

the class GroupAdministrationHelper method getGroupForm.

/**
 * Construct a group form for the group with the specified key.
 *
 * @param key
 * @param entityEnum
 * @return
 */
public GroupForm getGroupForm(String key) {
    log.debug("Initializing group form for group key " + key);
    // find the current version of this group entity
    IEntityGroup group = GroupService.findGroup(key);
    // update the group form with the existing group's main information
    GroupForm form = new GroupForm();
    form.setKey(key);
    form.setName(group.getName());
    form.setDescription(group.getDescription());
    form.setCreatorId(group.getCreatorID());
    form.setType(groupListHelper.getEntityType(group).toString());
    // add child groups to our group form bean
    for (IGroupMember child : group.getChildren()) {
        JsonEntityBean childBean = groupListHelper.getEntity(child);
        form.addMember(childBean);
    }
    return form;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 48 with JsonEntityBean

use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.

the class GroupAdministrationHelper method createGroup.

/**
 * Create a new group under the specified parent. The new group will automatically be added to
 * the parent group.
 *
 * @param groupForm form object representing the new group
 * @param parent parent group for this new group
 * @param creator the uPortal user creating the new group
 */
public void createGroup(GroupForm groupForm, JsonEntityBean parent, IPerson creator) {
    if (!canCreateMemberGroup(creator, parent.getId())) {
        throw new RuntimeAuthorizationException(creator, IPermission.CREATE_GROUP_ACTIVITY, groupForm.getKey());
    }
    if (log.isDebugEnabled()) {
        log.debug("Creating new group for group form [" + groupForm.toString() + "] and parent [" + parent.toString() + "]");
    }
    // get the entity type of the parent group
    EntityEnum type = EntityEnum.getEntityEnum(groupForm.getType());
    // create a new group with the parent's entity type
    IEntityGroup group = GroupService.newGroup(type.getClazz());
    // find the current version of this group entity
    group.setCreatorID(creator.getUserName());
    group.setName(groupForm.getName());
    group.setDescription(groupForm.getDescription());
    // to the group
    for (JsonEntityBean child : groupForm.getMembers()) {
        EntityEnum childType = EntityEnum.getEntityEnum(child.getEntityTypeAsString());
        if (childType.isGroup()) {
            IEntityGroup member = GroupService.findGroup(child.getId());
            group.addChild(member);
        } else {
            IGroupMember member = GroupService.getGroupMember(child.getId(), type.getClazz());
            group.addChild(member);
        }
    }
    // save the group, updating both its basic information and group membership
    group.update();
    // add this group to the membership list for the specified parent
    IEntityGroup parentGroup = GroupService.findGroup(parent.getId());
    parentGroup.addChild(group);
    parentGroup.updateMembers();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 49 with JsonEntityBean

use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.

the class JsonEntityBeanTest method testConstructFromGroupMemberWithPortlet.

@Test
public void testConstructFromGroupMemberWithPortlet() {
    String key = "test-key";
    Mockito.when(groupMember.getKey()).thenReturn(key);
    JsonEntityBean jeb = new JsonEntityBean(groupMember, EntityEnum.PORTLET);
    assertEquals(EntityEnum.PORTLET, jeb.getEntityType());
    assertEquals(key, jeb.getId());
    assertEquals(IPermission.PORTLET_PREFIX + key, jeb.getTargetString());
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

Example 50 with JsonEntityBean

use of org.apereo.portal.layout.dlm.remoting.JsonEntityBean in project uPortal by Jasig.

the class JsonEntityBeanTest method testEqualsDiffChildrenInit.

@Test
public void testEqualsDiffChildrenInit() {
    JsonEntityBean jeb1 = buildNullBean();
    jeb1.setChildrenInitialized(true);
    JsonEntityBean jeb2 = buildNullBean();
    jeb2.setChildrenInitialized(false);
    assertFalse(jeb1.equals(jeb2));
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) Test(org.junit.Test)

Aggregations

JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)86 Test (org.junit.Test)53 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)13 ModelAndView (org.springframework.web.servlet.ModelAndView)10 IEntityGroup (org.apereo.portal.groups.IEntityGroup)9 IGroupMember (org.apereo.portal.groups.IGroupMember)9 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)9 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IPermission (org.apereo.portal.security.IPermission)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 List (java.util.List)3 IPermissionTarget (org.apereo.portal.permission.target.IPermissionTarget)3 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)3 IPerson (org.apereo.portal.security.IPerson)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 GroupListHelperImpl (org.apereo.portal.layout.dlm.remoting.GroupListHelperImpl)2 IPermissionActivity (org.apereo.portal.permission.IPermissionActivity)2