use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.
the class PermissionsRESTControllerTest method testGetActivitiesEmpty.
@Test
public void testGetActivitiesEmpty() {
String query = "activity1";
Mockito.when(permissionOwnerDao.getAllPermissionOwners()).thenReturn(Collections.EMPTY_LIST);
ModelAndView modelAndView = permissionsRESTController.getActivities(query);
List<IPermissionActivity> activities = (List<IPermissionActivity>) modelAndView.getModel().get("activities");
Assert.assertTrue(activities.isEmpty());
Assert.assertEquals(200, res.getStatus());
}
use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.
the class PermissionsRESTController method getPermissionForPrincipal.
private JsonPermission getPermissionForPrincipal(UniquePermission permission, JsonEntityBean entity) {
JsonPermission perm = new JsonPermission();
perm.setOwnerKey(permission.getOwner());
perm.setActivityKey(permission.getActivity());
perm.setTargetKey(permission.getIdentifier());
perm.setPrincipalKey(entity.getId());
perm.setPrincipalName(entity.getName());
perm.setInherited(permission.isInherited());
try {
IPermissionOwner owner = permissionOwnerDao.getPermissionOwner(permission.getOwner());
if (owner != null) {
perm.setOwnerName(owner.getName());
}
IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(permission.getOwner(), permission.getActivity());
if (activity != null) {
perm.setActivityName(activity.getName());
IPermissionTargetProvider targetProvider = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey());
if (targetProvider != null) {
IPermissionTarget target = targetProvider.getTarget(permission.getIdentifier());
if (target != null) {
perm.setTargetName(target.getName());
}
}
}
} catch (RuntimeException e) {
log.warn("Exception while adding permission", e);
}
return perm;
}
use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.
the class PermissionsRESTController method getPermissionOnTarget.
private JsonPermission getPermissionOnTarget(UniquePermission permission, JsonEntityBean entity) {
JsonPermission perm = new JsonPermission();
perm.setOwnerKey(permission.getOwner());
perm.setActivityKey(permission.getActivity());
perm.setTargetKey(entity.getId());
perm.setTargetName(entity.getName());
perm.setInherited(permission.isInherited());
try {
IPermissionOwner owner = permissionOwnerDao.getPermissionOwner(permission.getOwner());
if (owner != null) {
perm.setOwnerName(owner.getName());
} else {
perm.setOwnerName(permission.getOwner());
}
IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(permission.getOwner(), permission.getActivity());
if (activity != null) {
perm.setActivityName(activity.getName());
} else {
perm.setActivityName(permission.getActivity());
}
JsonEntityBean principal = groupListHelper.getEntityForPrincipal(permission.getIdentifier());
if (principal != null) {
perm.setPrincipalKey(principal.getId());
perm.setPrincipalName(principal.getName());
}
} catch (RuntimeException e) {
log.warn("Exception while adding permission", e);
}
return perm;
}
use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.
the class AnyUnblockedGrantPermissionPolicy method doesPrincipalHavePermission.
@Override
public boolean doesPrincipalHavePermission(IAuthorizationService service, IAuthorizationPrincipal principal, IPermissionOwner owner, IPermissionActivity activity, IPermissionTarget target) throws AuthorizationException {
/*
* The API states that the service, owner, and activity arguments must
* not be null. If for some reason they are null, log and fail closed.
* In our case, the principal and target must also be non-null.
*/
if (service == null || principal == null || owner == null || activity == null || target == null) {
log.error("Null argument to AnyUnblockedGrantPermissionPolicy doesPrincipalHavePermission() method " + "should not be possible. This is indicative of a potentially serious bug in the permissions " + "and authorization infrastructure; service='{}', principal='{}', owner='{}', activity='{}', " + "target='{}'", service, principal, owner, activity, target, new AuthorizationException("Null argument"));
// fail closed
return false;
}
// Is this user a super-user? (Should this logic be moved to AuthorizationImpl?)
final IPermissionActivity allPermissionsActivity = permissionOwnerDao.getPermissionActivity(IPermission.PORTAL_SYSTEM, IPermission.ALL_PERMISSIONS_ACTIVITY);
if (!activity.equals(allPermissionsActivity)) {
// NOTE: Must check to avoid infinite recursion
final IPermissionOwner allPermissionsOwner = permissionOwnerDao.getPermissionOwner(IPermission.PORTAL_SYSTEM);
final IPermissionTarget allPermissionsTarget = targetProviderRegistry.getTargetProvider(allPermissionsActivity.getTargetProviderKey()).getTarget(IPermission.ALL_TARGET);
if (doesPrincipalHavePermission(service, principal, allPermissionsOwner, allPermissionsActivity, allPermissionsTarget)) {
// Stop checking; just return true
return true;
}
}
/*
* uPortal uses a few "special" targets that signal permission to
* perform the specified activity over an entire class of targets;
* see if one of those applies in this case.
*/
IPermissionTarget collectiveTarget = // The "collective noun" representing a class of thing
null;
switch(target.getTargetType()) {
case PORTLET:
collectiveTarget = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey()).getTarget(IPermission.ALL_PORTLETS_TARGET);
break;
case CATEGORY:
collectiveTarget = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey()).getTarget(IPermission.ALL_CATEGORIES_TARGET);
break;
case GROUP:
collectiveTarget = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey()).getTarget(IPermission.ALL_GROUPS_TARGET);
break;
default:
}
/*
* NOTE: Cannot generalize to a collective target if we are already on
* the collective target, else StackOverflowError.
*/
if (collectiveTarget != null && !collectiveTarget.equals(target)) {
if (doesPrincipalHavePermission(service, principal, owner, activity, collectiveTarget)) {
/*
* There is a collective for this class of target,
* and the user DOES have this special permission
*/
return true;
}
}
// Search ourselves and all ancestors for an unblocked GRANT.
boolean rslt;
try {
// Track groups we've already explored to avoid infinite loop
final Set<IGroupMember> seenGroups = new HashSet<>();
rslt = hasUnblockedPathToGrantWithCache(service, principal, owner, activity, target, seenGroups);
} catch (Exception e) {
log.error("Error searching for unblocked path to grant for principal [" + principal + "]", e);
// fail closed
return false;
}
if (log.isTraceEnabled()) {
if (rslt) {
log.trace("Principal '{}' is granted permission to perform activity " + "'{}' on target '{}' under permission owning system '{}' " + "because this principal has an unblocked path to a GRANT.", principal, activity.getFname(), target.getKey(), owner.getFname());
} else {
log.trace("Principal '{}' is denied permission to perform activity '{}' " + "on target '{}' under permission owning system '{}' because this " + "principal does not have an unblocked path to a GRANT.", principal, activity.getFname(), target.getKey(), owner.getFname());
}
}
return rslt;
}
use of org.apereo.portal.permission.IPermissionActivity in project uPortal by Jasig.
the class JpaPermissionOwnerDao method getOrCreatePermissionActivity.
@Override
@PortalTransactional
public IPermissionActivity getOrCreatePermissionActivity(IPermissionOwner owner, String name, String fname, String targetProviderKey) {
IPermissionActivity activity = getPermissionActivity(owner.getId(), fname);
if (activity == null) {
activity = new PermissionActivityImpl(name, fname, targetProviderKey);
owner.getActivities().add(activity);
}
return activity;
}
Aggregations