use of org.apereo.portal.permission.IPermissionOwner in project uPortal by Jasig.
the class PermissionsRESTController method getPermissionForPrincipal.
protected 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.IPermissionOwner in project uPortal by Jasig.
the class PermissionsListController method marshall.
/*
* Private Stuff.
*/
private List<Map<String, String>> marshall(IPermission[] data) {
// Assertions.
if (data == null) {
String msg = "Argument 'data' cannot be null";
throw new IllegalArgumentException(msg);
}
List<Map<String, String>> rslt = new ArrayList<Map<String, String>>(data.length);
for (IPermission p : data) {
JsonEntityBean bean = getEntityBean(p.getPrincipal());
Map<String, String> entry = new HashMap<String, String>();
entry.put("owner", p.getOwner());
entry.put("principalType", bean.getEntityTypeAsString());
entry.put("principalName", bean.getName());
entry.put("principalKey", p.getPrincipal());
entry.put("activity", p.getActivity());
entry.put("target", p.getTarget());
entry.put("permissionType", p.getType());
/*
* Attempt to find a name for this target through the permission
* target provider registry. If none can be found, just use
* the target key.
*/
String targetName = null;
try {
// attempt to get the target provider for this activity
IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(p.getOwner(), p.getActivity());
entry.put("activityName", activity.getName());
IPermissionOwner owner = permissionOwnerDao.getPermissionOwner(p.getOwner());
entry.put("ownerName", owner.getName());
String providerKey = activity.getTargetProviderKey();
IPermissionTargetProvider provider = targetProviderRegistry.getTargetProvider(providerKey);
// get the target from the provider
IPermissionTarget target = provider.getTarget(p.getTarget());
targetName = target.getName();
} catch (RuntimeException e) {
// likely a result of a null activity or provider
log.trace("Failed to resolve target name", e);
}
if (targetName == null) {
targetName = p.getTarget();
}
entry.put("targetName", targetName);
rslt.add(entry);
}
return rslt;
}
use of org.apereo.portal.permission.IPermissionOwner in project uPortal by Jasig.
the class PermissionsRESTController method getOwners.
/**
* Provide a JSON view of all known permission owners registered with uPortal.
*
* @param req
* @param response
* @return
* @throws Exception
*/
@PreAuthorize("hasPermission('string', 'ALL', new org.apereo.portal.spring.security.evaluator.AuthorizableActivity('UP_PERMISSIONS', 'VIEW_PERMISSIONS'))")
@RequestMapping(value = "/permissions/owners.json", method = RequestMethod.GET)
public ModelAndView getOwners(HttpServletRequest req, HttpServletResponse response) throws Exception {
// get a list of all currently defined permission owners
List<IPermissionOwner> owners = permissionOwnerDao.getAllPermissionOwners();
ModelAndView mv = new ModelAndView();
mv.addObject("owners", owners);
mv.setViewName("json");
return mv;
}
use of org.apereo.portal.permission.IPermissionOwner in project uPortal by Jasig.
the class PermissionsRESTController method getOwners.
/**
* Provide a detailed view of the specified IPermissionOwner. This view should contain a list of
* the owner's defined activities.
*
* @param ownerParam
* @param req
* @param response
* @return
* @throws Exception
*/
@PreAuthorize("hasPermission('string', 'ALL', new org.apereo.portal.spring.security.evaluator.AuthorizableActivity('UP_PERMISSIONS', 'VIEW_PERMISSIONS'))")
@RequestMapping(value = "/permissions/owners/{owner}.json", method = RequestMethod.GET)
public ModelAndView getOwners(@PathVariable("owner") String ownerParam, HttpServletRequest req, HttpServletResponse response) throws Exception {
IPermissionOwner owner = null;
if (StringUtils.isNumeric(ownerParam)) {
Long id = Long.valueOf(ownerParam);
owner = permissionOwnerDao.getPermissionOwner(id);
} else {
owner = permissionOwnerDao.getPermissionOwner(ownerParam);
}
// if the IPermissionOwner was found, add it to the JSON model
if (owner != null) {
ModelAndView mv = new ModelAndView();
mv.addObject("owner", owner);
mv.setViewName("json");
return mv;
} else // otherwise return a 404 not found error code
{
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return null;
}
}
use of org.apereo.portal.permission.IPermissionOwner in project uPortal by Jasig.
the class PermissionOwnerImporterExporter method importData.
/* (non-Javadoc)
* @see org.apereo.portal.io.xml.IDataImporter#importData(java.lang.Object)
*/
@Override
@Transactional
public void importData(ExternalPermissionOwner externalPermissionOwner) {
final String name = externalPermissionOwner.getName();
final String fname = externalPermissionOwner.getFname();
final IPermissionOwner permissionOwner = this.permissionOwnerDao.getOrCreatePermissionOwner(name, fname);
final String desc = externalPermissionOwner.getDesc();
permissionOwner.setDescription(desc);
for (final ExternalActivity externalActivity : externalPermissionOwner.getActivities()) {
final String activityName = externalActivity.getName();
final String activityFname = externalActivity.getFname();
final String targetProvider = externalActivity.getTargetProvider();
final IPermissionActivity permissionActivity = this.permissionOwnerDao.getOrCreatePermissionActivity(permissionOwner, activityName, activityFname, targetProvider);
final String activityDesc = externalActivity.getDesc();
permissionActivity.setDescription(activityDesc);
}
this.permissionOwnerDao.saveOwner(permissionOwner);
}
Aggregations