Search in sources :

Example 81 with JsonEntityBean

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

the class PrincipalsRESTControllerTest method testGetPrincipalsGroup.

@Test
public void testGetPrincipalsGroup() throws Exception {
    String query = "test";
    Set<JsonEntityBean> beans = new HashSet<JsonEntityBean>();
    beans.add(buildJsonGroupEntityBean());
    Mockito.when(groupListHelper.search(EntityEnum.GROUP.toString(), "test")).thenReturn(beans);
    Mockito.when(groupListHelper.search(EntityEnum.PERSON.toString(), "test")).thenReturn(Collections.emptySet());
    ModelAndView modelAndView = principalsRESTController.getPrincipals(query, req, res);
    List<JsonEntityBean> returnPersonEntities = (List<JsonEntityBean>) modelAndView.getModel().get("people");
    List<JsonEntityBean> returnGroupEntities = (List<JsonEntityBean>) modelAndView.getModel().get("groups");
    Assert.assertTrue(returnPersonEntities.isEmpty());
    Assert.assertFalse(returnGroupEntities.isEmpty());
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 82 with JsonEntityBean

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

the class PrincipalsRESTControllerTest method testGetPrincipalsPerson.

@Test
public void testGetPrincipalsPerson() throws Exception {
    String query = "test";
    Set<JsonEntityBean> beans = new HashSet<JsonEntityBean>();
    beans.add(buildJsonPersonEntityBean());
    Mockito.when(groupListHelper.search(EntityEnum.GROUP.toString(), "test")).thenReturn(Collections.emptySet());
    Mockito.when(groupListHelper.search(EntityEnum.PERSON.toString(), "test")).thenReturn(beans);
    ModelAndView modelAndView = principalsRESTController.getPrincipals(query, req, res);
    List<JsonEntityBean> returnPersonEntities = (List<JsonEntityBean>) modelAndView.getModel().get("people");
    List<JsonEntityBean> returnGroupEntities = (List<JsonEntityBean>) modelAndView.getModel().get("groups");
    Assert.assertFalse(returnPersonEntities.isEmpty());
    Assert.assertTrue(returnGroupEntities.isEmpty());
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 83 with JsonEntityBean

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

the class PrincipalsRESTControllerTest method buildJsonGroupEntityBean.

private JsonEntityBean buildJsonGroupEntityBean() {
    JsonEntityBean groupBean = new JsonEntityBean();
    groupBean.setEntityType(EntityEnum.GROUP.toString());
    groupBean.setId("group101");
    groupBean.setName("test");
    groupBean.setDescription("Testing group bean");
    return groupBean;
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean)

Example 84 with JsonEntityBean

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

the class PrincipalsRESTControllerTest method testGetPrincipals.

@Test
public void testGetPrincipals() throws Exception {
    String query = "test";
    Mockito.when(groupListHelper.search(EntityEnum.GROUP.toString(), "test")).thenReturn(Collections.emptySet());
    Mockito.when(groupListHelper.search(EntityEnum.PERSON.toString(), "test")).thenReturn(Collections.emptySet());
    ModelAndView modelAndView = principalsRESTController.getPrincipals(query, req, res);
    List<JsonEntityBean> returnPersonEntities = (List<JsonEntityBean>) modelAndView.getModel().get("people");
    List<JsonEntityBean> returnGroupEntities = (List<JsonEntityBean>) modelAndView.getModel().get("groups");
    Assert.assertTrue(returnPersonEntities.isEmpty());
    Assert.assertTrue(returnGroupEntities.isEmpty());
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Test(org.junit.Test)

Example 85 with JsonEntityBean

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

the class PortletAdministrationHelper method createPortletDefinitionForm.

/**
 * Construct a new PortletDefinitionForm for the given IPortletDefinition id. If a
 * PortletDefinition matching this ID already exists, the form will be pre-populated with the
 * PortletDefinition's current configuration. If the PortletDefinition does not yet exist, a new
 * default form will be created.
 *
 * @param person user that is required to have related lifecycle permission
 * @param portletId identifier for the portlet definition
 * @return {@PortletDefinitionForm} with set values based on portlet definition or default
 *     category and principal if no definition is found
 */
public PortletDefinitionForm createPortletDefinitionForm(IPerson person, String portletId) {
    IPortletDefinition def = portletDefinitionRegistry.getPortletDefinition(portletId);
    // create the new form
    final PortletDefinitionForm form;
    if (def != null) {
        // if this is a pre-existing portlet, set the category and permissions
        form = new PortletDefinitionForm(def);
        form.setId(def.getPortletDefinitionId().getStringId());
        // create a JsonEntityBean for each current category and add it
        // to our form bean's category list
        Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def);
        for (PortletCategory cat : categories) {
            form.addCategory(new JsonEntityBean(cat));
        }
        addPrincipalPermissionsToForm(def, form);
    } else {
        form = createNewPortletDefinitionForm();
    }
    // hierarchical, so we'll test with the weakest.
    if (!hasLifecyclePermission(person, PortletLifecycleState.CREATED, form.getCategories())) {
        logger.warn("User '" + person.getUserName() + "' attempted to edit the following portlet without MANAGE permission:  " + def);
        throw new SecurityException("Not Authorized");
    }
    return form;
}
Also used : JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

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