Search in sources :

Example 1 with IEntity

use of org.apereo.portal.groups.IEntity in project uPortal by Jasig.

the class PortletCategoryRegistryImpl method getParentCategories.

/* (non-Javadoc)
     * @see org.apereo.portal.portlet.registry.IPortletCategoryRegistry#getParentCategories(org.apereo.portal.portlet.om.IPortletDefinition)
     */
@Override
public Set<PortletCategory> getParentCategories(IPortletDefinition child) {
    String childKey = child.getPortletDefinitionId().getStringId();
    IEntity childEntity = GroupService.getEntity(childKey, IPortletDefinition.class);
    Set<PortletCategory> parents = new HashSet<PortletCategory>();
    for (IGroupMember gm : childEntity.getParentGroups()) {
        if (gm.isGroup()) {
            String categoryId = gm.getKey();
            parents.add(getPortletCategory(categoryId));
        }
    }
    return parents;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) IEntity(org.apereo.portal.groups.IEntity) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 2 with IEntity

use of org.apereo.portal.groups.IEntity in project uPortal by Jasig.

the class XalanGroupMembershipHelperBean method isChannelDeepMemberOf.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isChannelDeepMemberOf(java.lang.String, java.lang.String)
     */
@Override
public boolean isChannelDeepMemberOf(String fname, String groupKey) {
    final IEntityGroup distinguishedGroup = GroupService.findGroup(groupKey);
    if (distinguishedGroup == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No group found for key '" + groupKey + "'");
        }
        return false;
    }
    final IPortletDefinition portletDefinition;
    try {
        portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fname);
    } catch (Exception e) {
        this.logger.warn("Caught exception while retrieving portlet definition for fname '" + fname + "'", e);
        return false;
    }
    if (portletDefinition == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No portlet found for key '" + fname + "'");
        }
        return false;
    }
    final String portletId = portletDefinition.getPortletDefinitionId().getStringId();
    final IEntity entity = GroupService.getEntity(portletId, IPortletDefinition.class);
    if (entity == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No portlet found for id '" + portletId + "'");
        }
        return false;
    }
    return distinguishedGroup.deepContains(entity);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IEntity(org.apereo.portal.groups.IEntity) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 3 with IEntity

use of org.apereo.portal.groups.IEntity in project uPortal by Jasig.

the class EntityPersonAttributesGroupStore method findParentGroups.

@Override
public Iterator<IEntityGroup> findParentGroups(IGroupMember member) throws GroupsException {
    if (!IPERSON_CLASS.equals(member.getLeafType())) {
        // knowing that PAGS only supports groups of IPerson (we are).
        return Collections.emptyIterator();
    }
    logger.debug("finding containing groups for member key {}", member.getKey());
    final Set<IEntityGroup> set = Collections.emptySet();
    // default
    Iterator<IEntityGroup> rslt = set.iterator();
    if (member.isGroup()) {
        // PAGS groups may only contain other PAGS groups (and people, of course)
        final IEntityGroup ieg = (IEntityGroup) member;
        if (PagsService.SERVICE_NAME_PAGS.equals(ieg.getServiceName().toString())) {
            rslt = findParentGroupsForGroup((IEntityGroup) member);
        }
    } else {
        rslt = findParentGroupsForEntity((IEntity) member);
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IEntity(org.apereo.portal.groups.IEntity)

Example 4 with IEntity

use of org.apereo.portal.groups.IEntity in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method savePortletDefinition.

/**
     * Save a portlet definition.
     *
     * @param definition the portlet definition
     * @param publisher the person publishing the portlet
     * @param categories the list of categories for the portlet
     * @param permissionMap a map of permission name -> list of groups who are granted that
     *     permission (Note: for now, only grant is supported and only for the FRAMEWORK_OWNER perm
     *     manager)
     */
private IPortletDefinition savePortletDefinition(IPortletDefinition definition, IPerson publisher, List<PortletCategory> categories, Map<ExternalPermissionDefinition, Set<IGroupMember>> permissionMap) {
    boolean newChannel = (definition.getPortletDefinitionId() == null);
    // save the channel
    definition = portletDefinitionDao.savePortletDefinition(definition);
    definition = portletDefinitionDao.getPortletDefinitionByFname(definition.getFName());
    final String defId = definition.getPortletDefinitionId().getStringId();
    final IEntity portletDefEntity = GroupService.getEntity(defId, IPortletDefinition.class);
    //The groups service needs to deal with concurrent modification better.
    synchronized (this.groupUpdateLock) {
        // Delete existing category memberships for this channel
        if (!newChannel) {
            for (IEntityGroup group : portletDefEntity.getAncestorGroups()) {
                group.removeChild(portletDefEntity);
                group.update();
            }
        }
        // For each category ID, add channel to category
        for (PortletCategory category : categories) {
            final IEntityGroup categoryGroup = GroupService.findGroup(category.getId());
            categoryGroup.addChild(portletDefEntity);
            categoryGroup.updateMembers();
        }
        // Set groups
        final AuthorizationService authService = AuthorizationService.instance();
        final String target = PermissionHelper.permissionTargetIdForPortletDefinition(definition);
        // Loop over the affected permission managers...
        Map<String, Collection<ExternalPermissionDefinition>> permissionsBySystem = getPermissionsBySystem(permissionMap.keySet());
        for (String system : permissionsBySystem.keySet()) {
            Collection<ExternalPermissionDefinition> systemPerms = permissionsBySystem.get(system);
            // get the permission manager for this system...
            final IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(system);
            final List<IPermission> permissions = new ArrayList<>();
            // add activity grants for each permission..
            for (ExternalPermissionDefinition permissionDef : systemPerms) {
                Set<IGroupMember> members = permissionMap.get(permissionDef);
                for (final IGroupMember member : members) {
                    final IAuthorizationPrincipal authPrincipal = authService.newPrincipal(member);
                    final IPermission permEntity = upm.newPermission(authPrincipal);
                    permEntity.setType(IPermission.PERMISSION_TYPE_GRANT);
                    permEntity.setActivity(permissionDef.getActivity());
                    permEntity.setTarget(target);
                    permissions.add(permEntity);
                }
            }
            // If modifying the channel, remove the existing permissions before adding the new ones
            if (!newChannel) {
                for (ExternalPermissionDefinition permissionName : permissionMap.keySet()) {
                    IPermission[] oldPermissions = upm.getPermissions(permissionName.getActivity(), target);
                    upm.removePermissions(oldPermissions);
                }
            }
            upm.addPermissions(permissions.toArray(new IPermission[permissions.size()]));
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Portlet " + defId + " has been " + (newChannel ? "published" : "modified") + ".");
    }
    return definition;
}
Also used : IEntity(org.apereo.portal.groups.IEntity) ArrayList(java.util.ArrayList) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) AuthorizationService(org.apereo.portal.services.AuthorizationService) IPermission(org.apereo.portal.security.IPermission) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) Collection(java.util.Collection) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) IUpdatingPermissionManager(org.apereo.portal.security.IUpdatingPermissionManager)

Example 5 with IEntity

use of org.apereo.portal.groups.IEntity in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method removePortletDefinition.

@Transactional
@Override
public void removePortletDefinition(IPortletDefinition portletDefinition, IPerson person) {
    IPortletDefinition portletDef = portletDefinitionDao.getPortletDefinition(portletDefinition.getPortletDefinitionId());
    // Delete existing category memberships for this portlet
    String portletDefinitionId = portletDefinition.getPortletDefinitionId().getStringId();
    IEntity channelDefEntity = GroupService.getEntity(portletDefinitionId, IPortletDefinition.class);
    for (IEntityGroup group : channelDefEntity.getAncestorGroups()) {
        group.removeChild(channelDefEntity);
        group.update();
    }
    // Delete permissions records that refer to this portlet
    AuthorizationService authService = AuthorizationService.instance();
    String target = PermissionHelper.permissionTargetIdForPortletDefinition(portletDefinition);
    IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(IPermission.PORTAL_SUBSCRIBE);
    IPermission[] oldPermissions = upm.getPermissionsForTarget(target);
    upm.removePermissions(oldPermissions);
    // Delete any ratings (incl. reviews) associated with the portlet
    marketplaceRatingDao.clearRatingsForPortlet(portletDef);
    //Delete the portlet itself.
    portletDefinitionDao.deletePortletDefinition(portletDef);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IEntity(org.apereo.portal.groups.IEntity) AuthorizationService(org.apereo.portal.services.AuthorizationService) IPermission(org.apereo.portal.security.IPermission) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IUpdatingPermissionManager(org.apereo.portal.security.IUpdatingPermissionManager) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IEntity (org.apereo.portal.groups.IEntity)9 IEntityGroup (org.apereo.portal.groups.IEntityGroup)5 AuthorizationService (org.apereo.portal.services.AuthorizationService)4 IGroupMember (org.apereo.portal.groups.IGroupMember)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)2 IPermission (org.apereo.portal.security.IPermission)2 IUpdatingPermissionManager (org.apereo.portal.security.IUpdatingPermissionManager)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)1 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)1 Transactional (org.springframework.transaction.annotation.Transactional)1