Search in sources :

Example 1 with IPermissionActivity

use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.

the class PermissionsRESTController method getActivities.

/**
 * Provide a list of all registered IPermissionActivities. If an optional search string is
 * provided, the returned list will be restricted to activities matching the query.
 *
 * @param query optional search query
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@PreAuthorize("hasPermission('ALL', 'java.lang.String', new org.apereo.portal.spring.security.evaluator.AuthorizableActivity('UP_PERMISSIONS', 'VIEW_PERMISSIONS'))")
@RequestMapping(value = "/permissions/activities.json", method = RequestMethod.GET)
public ModelAndView getActivities(@RequestParam(value = "q", required = false) String query, HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (StringUtils.isNotBlank(query)) {
        query = query.toLowerCase();
    }
    List<IPermissionActivity> activities = new ArrayList<IPermissionActivity>();
    Collection<IPermissionOwner> owners = permissionOwnerDao.getAllPermissionOwners();
    for (IPermissionOwner owner : owners) {
        for (IPermissionActivity activity : owner.getActivities()) {
            if (StringUtils.isBlank(query) || activity.getName().toLowerCase().contains(query)) {
                activities.add(activity);
            }
        }
    }
    Collections.sort(activities);
    ModelAndView mv = new ModelAndView();
    mv.addObject("activities", activities);
    mv.setViewName("json");
    return mv;
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IPermissionActivity

use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.

the class PermissionsRESTController method getTargets.

/**
 * Return a list of targets defined for a particular IPermissionActivity matching the specified
 * search query.
 *
 * @param activityId
 * @param query
 * @param req
 * @param response
 * @return
 * @throws Exception
 */
@PreAuthorize("hasPermission('ALL', 'java.lang.String', new org.apereo.portal.spring.security.evaluator.AuthorizableActivity('UP_PERMISSIONS', 'VIEW_PERMISSIONS'))")
@RequestMapping(value = "/permissions/{activity}/targets.json", method = RequestMethod.GET)
public ModelAndView getTargets(@PathVariable("activity") Long activityId, @RequestParam("q") String query, HttpServletRequest req, HttpServletResponse response) throws Exception {
    IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(activityId);
    Collection<IPermissionTarget> targets = Collections.EMPTY_LIST;
    if (activity != null) {
        IPermissionTargetProvider provider = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey());
        SortedSet<IPermissionTarget> matchingTargets = new TreeSet<IPermissionTarget>();
        // add matching results for this identifier provider to the set
        targets = provider.searchTargets(query);
        for (IPermissionTarget target : targets) {
            if ((StringUtils.isNotBlank(target.getName()) && target.getName().toLowerCase().contains(query)) || target.getKey().toLowerCase().contains(query)) {
                matchingTargets.addAll(targets);
            }
        }
    }
    ModelAndView mv = new ModelAndView();
    mv.addObject("targets", targets);
    mv.setViewName("json");
    return mv;
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) IPermissionTarget(org.apereo.portal.permission.target.IPermissionTarget) TreeSet(java.util.TreeSet) IPermissionTargetProvider(org.apereo.portal.permission.target.IPermissionTargetProvider) ModelAndView(org.springframework.web.servlet.ModelAndView) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IPermissionActivity

use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.

the class ApiPermissionsService method createAssignment.

/*
     * Implementation
     */
private Assignment createAssignment(IPermission permission, IAuthorizationPrincipal authP, boolean inherited) {
    Assignment rslt = null;
    try {
        // Owner
        IPermissionOwner owner = permissionOwnerDao.getPermissionOwner(permission.getOwner());
        Owner ownerImpl = new OwnerImpl(permission.getOwner(), owner.getName());
        // Activity
        IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(permission.getOwner(), permission.getActivity());
        Activity activityImpl = new ActivityImpl(permission.getActivity(), activity.getName());
        // Principal
        Principal principalImpl = new PrincipalImpl(authP.getKey(), authP.getPrincipalString());
        // Target
        // default
        Target targetImpl = null;
        IPermissionTargetProvider targetProvider = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey());
        IPermissionTarget target = targetProvider.getTarget(permission.getTarget());
        if (target != null) {
            targetImpl = new TargetImpl(permission.getTarget(), target.getName());
        }
        rslt = new AssignmentImpl(ownerImpl, activityImpl, principalImpl, targetImpl, inherited);
    } catch (Exception e) {
        log.warn("Exception while adding permission", e);
    }
    return rslt;
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner) IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) IPermissionTarget(org.apereo.portal.permission.target.IPermissionTarget) IPermissionTarget(org.apereo.portal.permission.target.IPermissionTarget) IPermissionTargetProvider(org.apereo.portal.permission.target.IPermissionTargetProvider) Principal(org.apereo.portal.api.Principal) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PrincipalImpl(org.apereo.portal.api.PrincipalImpl) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner)

Example 4 with IPermissionActivity

use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.

the class PermissionsRESTControllerTest method testGetTargetsNullActivity.

@Test
public void testGetTargetsNullActivity() {
    Long activityId = 2L;
    String query = "activity1";
    IPermissionActivity activity = Mockito.mock(IPermissionActivity.class);
    activity.setDescription("Course Activity");
    activity.setFname("john");
    activity.setName("activity1");
    IPermissionTargetProvider provider = Mockito.mock(IPermissionTargetProvider.class);
    activity.setTargetProviderKey("providerKey");
    Mockito.when(permissionOwnerDao.getPermissionActivity(activityId)).thenReturn(null);
    Mockito.when(targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey())).thenReturn(null);
    ModelAndView modelAndView = permissionsRESTController.getTargets(activityId, query);
    Collection<IPermissionTarget> targets = (Collection<IPermissionTarget>) modelAndView.getModel().get("targets");
    Assert.assertTrue(targets.isEmpty());
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) IPermissionTarget(org.apereo.portal.permission.target.IPermissionTarget) IPermissionTargetProvider(org.apereo.portal.permission.target.IPermissionTargetProvider) ModelAndView(org.springframework.web.servlet.ModelAndView) Collection(java.util.Collection) Test(org.junit.Test)

Example 5 with IPermissionActivity

use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.

the class PermissionsRESTControllerTest method testGetActivities.

@Test
public void testGetActivities() {
    String query = "activity1";
    IPermissionOwner owner = Mockito.mock(IPermissionOwner.class);
    owner.setFname("john");
    owner.setDescription("testing description");
    owner.setName("john doe");
    IPermissionActivity activity = Mockito.mock(IPermissionActivity.class);
    activity.setDescription("Course Activity");
    activity.setFname("john");
    activity.setName("activity1");
    owner.getActivities().add(activity);
    List<IPermissionOwner> owners = new ArrayList<>();
    owners.add(owner);
    Mockito.when(permissionOwnerDao.getAllPermissionOwners()).thenReturn(owners);
    ModelAndView modelAndView = permissionsRESTController.getActivities(query);
    List<IPermissionActivity> activities = (List<IPermissionActivity>) modelAndView.getModel().get("activities");
    Assert.assertEquals(200, res.getStatus());
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) List(java.util.List) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner) Test(org.junit.Test)

Aggregations

IPermissionActivity (org.apereo.portal.permission.IPermissionActivity)19 IPermissionOwner (org.apereo.portal.permission.IPermissionOwner)11 IPermissionTarget (org.apereo.portal.permission.target.IPermissionTarget)9 IPermissionTargetProvider (org.apereo.portal.permission.target.IPermissionTargetProvider)9 ModelAndView (org.springframework.web.servlet.ModelAndView)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 Element (net.sf.ehcache.Element)2 IEntityGroup (org.apereo.portal.groups.IEntityGroup)2 IGroupMember (org.apereo.portal.groups.IGroupMember)2 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)2 IPermission (org.apereo.portal.security.IPermission)2