Search in sources :

Example 6 with IEntity

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

the class XalanGroupMembershipHelperBean method isUserDeepMemberOf.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isUserDeepMemberOf(java.lang.String, java.lang.String)
     */
@Override
public boolean isUserDeepMemberOf(String userName, 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 IEntity entity = GroupService.getEntity(userName, IPerson.class);
    if (entity == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No user found for key '" + userName + "'");
        }
        return false;
    }
    return distinguishedGroup.deepContains(entity);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IEntity(org.apereo.portal.groups.IEntity)

Example 7 with IEntity

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

the class UpdatePreferencesServlet method getUserPrincipal.

private IAuthorizationPrincipal getUserPrincipal(final String userName) {
    final IEntity user = GroupService.getEntity(userName, IPerson.class);
    if (user == null) {
        return null;
    }
    final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
    return authService.newPrincipal(user);
}
Also used : AuthorizationServiceFacade(org.apereo.portal.services.AuthorizationServiceFacade) IEntity(org.apereo.portal.groups.IEntity)

Example 8 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 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, 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 AuthorizationServiceFacade authService = AuthorizationServiceFacade.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);
                }
            }
            // 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) AuthorizationServiceFacade(org.apereo.portal.services.AuthorizationServiceFacade) 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 9 with IEntity

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

the class XalanAuthorizationHelperBean method getUserPrincipal.

protected IAuthorizationPrincipal getUserPrincipal(final String userName) {
    final IEntity user = GroupService.getEntity(userName, IPerson.class);
    if (user == null) {
        return null;
    }
    final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
    return authService.newPrincipal(user);
}
Also used : AuthorizationServiceFacade(org.apereo.portal.services.AuthorizationServiceFacade) IEntity(org.apereo.portal.groups.IEntity)

Example 10 with IEntity

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

the class XalanGroupMembershipHelperBean method isUserDeepMemberOfGroupName.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isUserDeepMemberOfGroupName(java.lang.String, java.lang.String)
     *
     * groupName is case sensitive.
     */
@Override
public boolean isUserDeepMemberOfGroupName(String userName, String groupName) {
    final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
    if (results == null || results.length == 0) {
        return false;
    }
    if (results.length > 1) {
        this.logger.warn(results.length + " groups were found for '" + groupName + "'. The first result will be used.");
    }
    final IGroupMember group = GroupService.getGroupMember(results[0]);
    final IEntity entity = GroupService.getEntity(userName, IPerson.class);
    if (entity == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No user found for key '" + userName + "'");
        }
        return false;
    }
    return group.asGroup().deepContains(entity);
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) IEntity(org.apereo.portal.groups.IEntity) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Aggregations

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