Search in sources :

Example 1 with IPermissionManager

use of org.apereo.portal.security.IPermissionManager in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method exportPermission.

private boolean exportPermission(IPortletDefinition def, ExternalPermissionDefinition permDef, List<String> groupList, List<String> userList) {
    final AuthorizationService authService = org.apereo.portal.services.AuthorizationService.instance();
    final IPermissionManager pm = authService.newPermissionManager(permDef.getSystem());
    final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);
    final IAuthorizationPrincipal[] principals = pm.getAuthorizedPrincipals(permDef.getActivity(), portletTargetId);
    boolean permAdded = false;
    for (IAuthorizationPrincipal principal : principals) {
        IGroupMember member = authService.getGroupMember(principal);
        if (member.isGroup()) {
            final EntityNameFinderService entityNameFinderService = EntityNameFinderService.instance();
            final IEntityNameFinder nameFinder = entityNameFinderService.getNameFinder(member.getType());
            try {
                groupList.add(nameFinder.getName(member.getKey()));
                permAdded = true;
            } catch (Exception e) {
                throw new RuntimeException("Could not find group name for entity: " + member.getKey(), e);
            }
        } else {
            if (userList != null) {
                userList.add(member.getKey());
                permAdded = true;
            }
        }
    }
    Collections.sort(groupList);
    if (userList != null) {
        Collections.sort(userList);
    }
    return permAdded;
}
Also used : IPermissionManager(org.apereo.portal.security.IPermissionManager) IGroupMember(org.apereo.portal.groups.IGroupMember) IEntityNameFinder(org.apereo.portal.groups.IEntityNameFinder) AuthorizationService(org.apereo.portal.services.AuthorizationService) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityNameFinderService(org.apereo.portal.services.EntityNameFinderService)

Example 2 with IPermissionManager

use of org.apereo.portal.security.IPermissionManager in project uPortal by Jasig.

the class PortletAdministrationHelper method addSubscribePermissionsToForm.

/*
     * Add to the form SUBSCRIBE and BROWSE activity permissions, along with their principals,
     * assigned to the portlet.
     */
private void addSubscribePermissionsToForm(IPortletDefinition def, PortletDefinitionForm form) {
    final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);
    /* We are concerned with PORTAL_SUBSCRIBE system */
    final IPermissionManager pm = authorizationService.newPermissionManager(IPermission.PORTAL_SUBSCRIBE);
    for (String activity : PORTLET_SUBSCRIBE_ACTIVITIES) {
        /* Obtain the principals that have permission for the activity on this portlet */
        final IAuthorizationPrincipal[] principals = pm.getAuthorizedPrincipals(activity, portletTargetId);
        for (IAuthorizationPrincipal principal : principals) {
            JsonEntityBean principalBean;
            // first assume this is a group
            IEntityGroup group = GroupService.findGroup(principal.getKey());
            if (group != null) {
                // principal is a group
                principalBean = new JsonEntityBean(group, EntityEnum.GROUP);
            } else {
                // not a group, so it must be a person
                IGroupMember member = authorizationService.getGroupMember(principal);
                principalBean = new JsonEntityBean(member, EntityEnum.PERSON);
                // set the name
                String name = groupListHelper.lookupEntityName(principalBean);
                principalBean.setName(name);
            }
            /* Make sure we capture the principal just once*/
            if (!form.getPrincipals().contains(principalBean)) {
                form.addPrincipal(principalBean);
            }
            form.addPermission(principalBean.getTypeAndIdHash() + "_" + activity);
        }
    }
}
Also used : IPermissionManager(org.apereo.portal.security.IPermissionManager) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Aggregations

IGroupMember (org.apereo.portal.groups.IGroupMember)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 IPermissionManager (org.apereo.portal.security.IPermissionManager)2 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 IEntityNameFinder (org.apereo.portal.groups.IEntityNameFinder)1 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)1 AuthorizationService (org.apereo.portal.services.AuthorizationService)1 EntityNameFinderService (org.apereo.portal.services.EntityNameFinderService)1