Search in sources :

Example 6 with IPermissionOwner

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;
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) IPermissionTarget(org.apereo.portal.permission.target.IPermissionTarget) IPermissionTargetProvider(org.apereo.portal.permission.target.IPermissionTargetProvider) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner)

Example 7 with IPermissionOwner

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;
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IPermission(org.apereo.portal.security.IPermission) IPermissionTarget(org.apereo.portal.permission.target.IPermissionTarget) IPermissionTargetProvider(org.apereo.portal.permission.target.IPermissionTargetProvider) HashMap(java.util.HashMap) Map(java.util.Map) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner)

Example 8 with IPermissionOwner

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;
}
Also used : 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 9 with IPermissionOwner

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;
    }
}
Also used : 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 10 with IPermissionOwner

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);
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IPermissionOwner (org.apereo.portal.permission.IPermissionOwner)12 IPermissionActivity (org.apereo.portal.permission.IPermissionActivity)9 IPermissionTarget (org.apereo.portal.permission.target.IPermissionTarget)5 IPermissionTargetProvider (org.apereo.portal.permission.target.IPermissionTargetProvider)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)2 Serializable (java.io.Serializable)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Element (net.sf.ehcache.Element)1 AuthorizationException (org.apereo.portal.AuthorizationException)1 Principal (org.apereo.portal.api.Principal)1 PrincipalImpl (org.apereo.portal.api.PrincipalImpl)1