Search in sources :

Example 16 with IEntityGroup

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

the class FileSystemGroupStore method find.

/**
     * Returns an instance of the <code>IEntityGroup</code> from the data store.
     *
     * @return org.apereo.portal.groups.IEntityGroup
     * @param key java.lang.String
     */
public IEntityGroup find(String key) throws GroupsException {
    if (log.isDebugEnabled()) {
        log.debug(DEBUG_CLASS_NAME + ".find(): group key: " + key);
    }
    String path = getFilePathFromKey(key);
    File f = new File(path);
    GroupHolder groupHolder = cacheGet(key);
    if (groupHolder == null || (groupHolder.getLastModified() != f.lastModified())) {
        if (log.isDebugEnabled()) {
            log.debug(DEBUG_CLASS_NAME + ".find(): retrieving group from file system for " + path);
        }
        if (!f.exists()) {
            if (log.isDebugEnabled()) {
                log.debug(DEBUG_CLASS_NAME + ".find(): file does not exist: " + path);
            }
            return null;
        }
        IEntityGroup group = newInstance(f);
        groupHolder = new GroupHolder(group, f.lastModified());
        cachePut(key, groupHolder);
    }
    return groupHolder.getGroup();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) File(java.io.File)

Example 17 with IEntityGroup

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

the class GrouperEntityGroupStore method createUportalGroupFromGrouperGroup.

/**
     * Construct an IEntityGroup from a Grouper WsGroup.
     *
     * @param wsGroup
     * @return the group
     */
protected IEntityGroup createUportalGroupFromGrouperGroup(WsGroup wsGroup) {
    IEntityGroup iEntityGroup = new EntityGroupImpl(wsGroup.getName(), IPerson.class);
    // need to set the group name and description to the actual
    // display name and description
    iEntityGroup.setName(wsGroup.getDisplayName());
    iEntityGroup.setDescription(wsGroup.getDescription());
    return iEntityGroup;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) EntityGroupImpl(org.apereo.portal.groups.EntityGroupImpl)

Example 18 with IEntityGroup

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

the class GrouperEntityGroupStore method findParentGroups.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#findParentGroups(org.apereo.portal.groups.IGroupMember)
     */
@SuppressWarnings("unchecked")
public Iterator findParentGroups(IGroupMember gm) throws GroupsException {
    final List<IEntityGroup> parents = new LinkedList<IEntityGroup>();
    GcGetGroups getGroups = new GcGetGroups();
    String uportalStem = getStemPrefix();
    // if only searching in a specific stem
    if (!StringUtils.isBlank(uportalStem)) {
        getGroups.assignStemScope(StemScope.ALL_IN_SUBTREE);
        getGroups.assignWsStemLookup(new WsStemLookup(uportalStem, null));
    }
    String key = null;
    String subjectSourceId = null;
    if (gm.isGroup()) {
        key = ((IEntityGroup) gm).getLocalKey();
        if (!validKey(key)) {
            return parents.iterator();
        }
        subjectSourceId = "g:gsa";
    } else {
        // Determine the key to use for this entity. If the entity is a
        // group, we should use the group's local key (excluding the
        // "grouper." portion of the full key. If the entity is not a
        // group type, just use the key.
        key = gm.getKey();
    }
    getGroups.addSubjectLookup(new WsSubjectLookup(null, subjectSourceId, key));
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching Grouper for parent groups of the entity with key: " + key);
    }
    try {
        WsGetGroupsResults results = getGroups.execute();
        if (results == null || results.getResults() == null || results.getResults().length != 1) {
            LOGGER.debug("Grouper service returned no matches for key " + key);
            return parents.iterator();
        }
        WsGetGroupsResult wsg = results.getResults()[0];
        if (wsg.getWsGroups() != null) {
            for (WsGroup g : wsg.getWsGroups()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.trace("Retrieved group: " + g.getName());
                }
                IEntityGroup parent = createUportalGroupFromGrouperGroup(g);
                parents.add(parent);
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Retrieved " + parents.size() + " parent groups of entity with key " + key);
        }
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "parents for entity with key " + key + " from Grouper web services: " + e.getMessage());
        return Collections.<IEntityGroup>emptyList().iterator();
    }
    return parents.iterator();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) WsSubjectLookup(edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) WsStemLookup(edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup) GcGetGroups(edu.internet2.middleware.grouperClient.api.GcGetGroups) WsGetGroupsResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResults) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) LinkedList(java.util.LinkedList) GroupsException(org.apereo.portal.groups.GroupsException)

Example 19 with IEntityGroup

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

the class EntityPersonAttributesGroupStore method searchForGroups.

@Override
public EntityIdentifier[] searchForGroups(String query, int method, Class leaftype) throws GroupsException {
    if (leaftype != IPERSON_CLASS) {
        return EMPTY_SEARCH_RESULTS;
    }
    Set<IPersonAttributesGroupDefinition> pagsGroups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitions();
    List<EntityIdentifier> results = new ArrayList<EntityIdentifier>();
    switch(method) {
        case IS:
            for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
                IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
                if (g.getName().equalsIgnoreCase(query)) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case STARTS_WITH:
            for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
                IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
                if (g.getName().toUpperCase().startsWith(query.toUpperCase())) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case ENDS_WITH:
            for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
                IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
                if (g.getName().toUpperCase().endsWith(query.toUpperCase())) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case CONTAINS:
            for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
                IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
                if (g.getName().toUpperCase().indexOf(query.toUpperCase()) != -1) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
    }
    return results.toArray(new EntityIdentifier[] {});
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 20 with IEntityGroup

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

the class PagsService method createPagsDefinition.

/** Verifies permissions and that the group doesn't already exist */
public IPersonAttributesGroupDefinition createPagsDefinition(IPerson person, IEntityGroup parent, String groupName, String description) {
    // What's the target of the upcoming permissions check?
    String target = parent != null ? parent.getEntityIdentifier().getKey() : IPermission.ALL_GROUPS_TARGET;
    // Verify permission
    if (!hasPermission(person, IPermission.CREATE_GROUP_ACTIVITY, target)) {
        throw new RuntimeAuthorizationException(person, IPermission.CREATE_GROUP_ACTIVITY, target);
    }
    // VALIDATION STEP:  The group name & description are allowable
    if (StringUtils.isBlank(groupName)) {
        throw new IllegalArgumentException("Specified groupName is blank:  " + groupName);
    }
    if (!GROUP_NAME_VALIDATOR_PATTERN.matcher(groupName).matches()) {
        throw new IllegalArgumentException("Specified groupName is too long, too short, or contains invalid characters:  " + groupName);
    }
    if (!StringUtils.isBlank(description)) {
        // Blank description is allowable
        if (!GROUP_DESC_VALIDATOR_PATTERN.matcher(description).matches()) {
            throw new IllegalArgumentException("Specified description is too long or contains invalid characters:  " + description);
        }
    }
    // VALIDATION STEP:  We don't have a group by that name already
    EntityIdentifier[] people = GroupService.searchForGroups(groupName, IGroupConstants.IS, IPerson.class);
    EntityIdentifier[] portlets = GroupService.searchForGroups(groupName, IGroupConstants.IS, IPortletDefinition.class);
    if (people.length != 0 || portlets.length != 0) {
        throw new IllegalArgumentException("Specified groupName already in use:  " + groupName);
    }
    IPersonAttributesGroupDefinition rslt = pagsGroupDefDao.createPersonAttributesGroupDefinition(groupName, description);
    if (parent != null) {
        // Should refactor this switch to instead choose a service and invoke a method on it
        switch(parent.getServiceName().toString()) {
            case SERVICE_NAME_LOCAL:
                IEntityGroup member = GroupService.findGroup(rslt.getCompositeEntityIdentifierForGroup().getKey());
                if (member == null) {
                    String msg = "The specified group was created, but is not present in the store:  " + rslt.getName();
                    throw new RuntimeException(msg);
                }
                parent.addChild(member);
                parent.updateMembers();
                break;
            case SERVICE_NAME_PAGS:
                IPersonAttributesGroupDefinition parentDef = getPagsGroupDefByName(parent.getName());
                Set<IPersonAttributesGroupDefinition> members = new HashSet<>(parentDef.getMembers());
                members.add(rslt);
                parentDef.setMembers(members);
                pagsGroupDefDao.updatePersonAttributesGroupDefinition(parentDef);
                break;
            default:
                String msg = "The specified group service does not support adding members:  " + parent.getServiceName();
                throw new UnsupportedOperationException(msg);
        }
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Aggregations

IEntityGroup (org.apereo.portal.groups.IEntityGroup)74 IGroupMember (org.apereo.portal.groups.IGroupMember)27 ArrayList (java.util.ArrayList)18 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)14 EntityIdentifier (org.apereo.portal.EntityIdentifier)12 HashSet (java.util.HashSet)10 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)9 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)8 GroupsException (org.apereo.portal.groups.GroupsException)8 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)8 IPermission (org.apereo.portal.security.IPermission)8 CompositeName (javax.naming.CompositeName)7 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPerson (org.apereo.portal.security.IPerson)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 DateTime (org.joda.time.DateTime)7 Test (org.junit.Test)7