Search in sources :

Example 6 with GroupsException

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

the class GrouperEntityGroupStore method searchForEntities.

/** @see IEntitySearcher#searchForEntities(java.lang.String, int, java.lang.Class) */
@SuppressWarnings("unchecked")
public EntityIdentifier[] searchForEntities(String query, int method, Class type) throws GroupsException {
    // only search for groups
    if (type != IPerson.class) {
        return new EntityIdentifier[] {};
    }
    List<EntityIdentifier> entityIdentifiers = new ArrayList<EntityIdentifier>();
    try {
        GcGetSubjects subjects = new GcGetSubjects();
        subjects.assignIncludeSubjectDetail(true);
        WsGetSubjectsResults results = subjects.assignSearchString(query).execute();
        if (results != null && results.getWsSubjects() != null) {
            for (WsSubject wsSubject : results.getWsSubjects()) {
                entityIdentifiers.add(new EntityIdentifier(wsSubject.getName(), ICompositeGroupService.LEAF_ENTITY_TYPE));
            }
        }
        return entityIdentifiers.toArray(new EntityIdentifier[entityIdentifiers.size()]);
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "search results for query " + query + " and entity type " + type.getCanonicalName() + " : " + e.getMessage());
        return new EntityIdentifier[] {};
    }
}
Also used : WsGetSubjectsResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetSubjectsResults) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject) GcGetSubjects(edu.internet2.middleware.grouperClient.api.GcGetSubjects) GroupsException(org.apereo.portal.groups.GroupsException)

Example 7 with GroupsException

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

the class PortletDefinitionSearcher method searchForEntities.

@Override
public EntityIdentifier[] searchForEntities(String query, int method) throws GroupsException {
    boolean allowPartial = true;
    switch(method) {
        case IS:
            allowPartial = false;
            break;
        case STARTS_WITH:
            query = query + "%";
            break;
        case ENDS_WITH:
            query = "%" + query;
            break;
        case CONTAINS:
            query = "%" + query + "%";
            break;
        default:
            throw new GroupsException("Unknown search type");
    }
    // get the list of matching portlet definitions
    final List<IPortletDefinition> definitions = this.portletDefinitionRegistry.searchForPortlets(query, allowPartial);
    if (log.isDebugEnabled()) {
        log.debug("Found " + definitions.size() + " matching definitions for query " + query);
    }
    // initialize an appropriately-sized array of EntityIdentifiers
    final EntityIdentifier[] identifiers = new EntityIdentifier[definitions.size()];
    // add an identifier for each matching portlet
    for (final ListIterator<IPortletDefinition> defIter = definitions.listIterator(); defIter.hasNext(); ) {
        final IPortletDefinition definition = defIter.next();
        identifiers[defIter.previousIndex()] = new EntityIdentifier(definition.getPortletDefinitionId().getStringId(), this.getType());
    }
    return identifiers;
}
Also used : GroupsException(org.apereo.portal.groups.GroupsException) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 8 with GroupsException

use of org.apereo.portal.groups.GroupsException 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 9 with GroupsException

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

the class SmartLdapGroupStore method searchForGroups.

public EntityIdentifier[] searchForGroups(String query, int method, Class leaftype) throws GroupsException {
    if (isTreeRefreshRequired()) {
        refreshTree();
    }
    log.debug("Invoking searchForGroups():  query={}, method={}, leaftype=", query, method, leaftype.getClass().getName());
    // We only match the IPerson leaf type...
    final IEntityGroup root = getRootGroup();
    if (!leaftype.equals(root.getLeafType())) {
        return new EntityIdentifier[0];
    }
    // We need to escape regex special characters that appear in the query string...
    final String[][] specials = new String[][] { /* backslash must come first! */
    new String[] { "\\", "\\\\" }, new String[] { "[", "\\[" }, /* closing ']' isn't needed b/c it's a normal character w/o a preceding '[' */
    new String[] { "{", "\\{" }, /* closing '}' isn't needed b/c it's a normal character w/o a preceding '{' */
    new String[] { "^", "\\^" }, new String[] { "$", "\\$" }, new String[] { ".", "\\." }, new String[] { "|", "\\|" }, new String[] { "?", "\\?" }, new String[] { "*", "\\*" }, new String[] { "+", "\\+" }, new String[] { "(", "\\(" }, new String[] { ")", "\\)" } };
    for (String[] s : specials) {
        query = query.replace(s[0], s[1]);
    }
    // Establish the regex pattern to match on...
    String regex;
    switch(method) {
        case IGroupConstants.IS:
            regex = query.toUpperCase();
            break;
        case IGroupConstants.STARTS_WITH:
            regex = query.toUpperCase() + ".*";
            break;
        case IGroupConstants.ENDS_WITH:
            regex = ".*" + query.toUpperCase();
            break;
        case IGroupConstants.CONTAINS:
            regex = ".*" + query.toUpperCase() + ".*";
            break;
        default:
            String msg = "Unsupported search method:  " + method;
            throw new GroupsException(msg);
    }
    List<EntityIdentifier> rslt = new LinkedList<>();
    for (Map.Entry<String, List<String>> y : groupsTree.getKeysByUpperCaseName().entrySet()) {
        if (y.getKey().matches(regex)) {
            List<String> keys = y.getValue();
            for (String k : keys) {
                rslt.add(new EntityIdentifier(k, IEntityGroup.class));
            }
        }
    }
    return rslt.toArray(new EntityIdentifier[rslt.size()]);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) GroupsException(org.apereo.portal.groups.GroupsException) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 10 with GroupsException

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

the class GrouperEntityGroupStore method find.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#find(java.lang.String)
     */
public IEntityGroup find(String key) throws GroupsException {
    try {
        // key
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Searching Grouper for a direct match for key: " + key);
        }
        WsGroup wsGroup = findGroupFromKey(key);
        if (wsGroup == null) {
            return null;
        }
        IEntityGroup group = createUportalGroupFromGrouperGroup(wsGroup);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Retrieved group from the Grouper server matching key " + key + ": " + group.toString());
        }
        // return the group
        return group;
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "group with key " + key + " from Grouper web services: " + e.getMessage());
        return null;
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) GroupsException(org.apereo.portal.groups.GroupsException)

Aggregations

GroupsException (org.apereo.portal.groups.GroupsException)17 ArrayList (java.util.ArrayList)10 EntityIdentifier (org.apereo.portal.EntityIdentifier)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)6 IGroupMember (org.apereo.portal.groups.IGroupMember)4 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)3 WsSubject (edu.internet2.middleware.grouperClient.ws.beans.WsSubject)3 File (java.io.File)3 IOException (java.io.IOException)3 Collection (java.util.Collection)3 Iterator (java.util.Iterator)3 List (java.util.List)3 GcGetMembers (edu.internet2.middleware.grouperClient.api.GcGetMembers)2 WsGetMembersResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults)2 LinkedList (java.util.LinkedList)2 AuthorizationException (org.apereo.portal.AuthorizationException)2 CachingException (org.apereo.portal.concurrency.CachingException)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 GcGetGroups (edu.internet2.middleware.grouperClient.api.GcGetGroups)1 GcGetSubjects (edu.internet2.middleware.grouperClient.api.GcGetSubjects)1