Search in sources :

Example 21 with GroupsException

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

the class PortletDefinitionSearcher method searchForEntities.

// Internal search, so shouldn't be called as case insensitive.
@Override
public EntityIdentifier[] searchForEntities(String query, SearchMethod method) throws GroupsException {
    boolean allowPartial = true;
    switch(method) {
        case DISCRETE:
            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 22 with GroupsException

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

the class SmartLdapGroupStore method searchForGroups.

// Treats case sensitive and case insensitive searching the same.
public EntityIdentifier[] searchForGroups(String query, SearchMethod method, Class leaftype) throws GroupsException {
    if (isTreeRefreshRequired()) {
        refreshTree();
    }
    log.debug("Invoking searchForGroups():  query={}, method={}, leaftype=", query, method, leaftype.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 DISCRETE:
        case DISCRETE_CI:
            regex = query.toUpperCase();
            break;
        case STARTS_WITH:
        case STARTS_WITH_CI:
            regex = query.toUpperCase() + ".*";
            break;
        case ENDS_WITH:
        case ENDS_WITH_CI:
            regex = ".*" + query.toUpperCase();
            break;
        case CONTAINS:
        case CONTAINS_CI:
            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 23 with GroupsException

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

the class AuthorizationImpl method getInheritedPrincipals.

/**
 * Hook into the Groups system, find all containing groups, and convert the them to <code>
 * IAuthorizationPrincipals</code>.
 *
 * @param principal - org.apereo.portal.security.IAuthorizationPrincipal
 * @return java.util.Iterator over Collection of IEntityGroups
 */
private Iterator getInheritedPrincipals(IAuthorizationPrincipal principal) throws AuthorizationException {
    Iterator i = null;
    ArrayList<IAuthorizationPrincipal> al = new ArrayList<>(5);
    try {
        i = getGroupsForPrincipal(principal);
    } catch (GroupsException ge) {
        throw new AuthorizationException("Could not retrieve Groups for " + principal, ge);
    }
    while (i.hasNext()) {
        IEntityGroup group = (IEntityGroup) i.next();
        IAuthorizationPrincipal p = getPrincipalForGroup(group);
        al.add(p);
    }
    return al.iterator();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) AuthorizationException(org.apereo.portal.AuthorizationException) GroupsException(org.apereo.portal.groups.GroupsException) Iterator(java.util.Iterator) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ArrayList(java.util.ArrayList)

Aggregations

GroupsException (org.apereo.portal.groups.GroupsException)23 ArrayList (java.util.ArrayList)15 EntityIdentifier (org.apereo.portal.EntityIdentifier)13 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 List (java.util.List)5 WsSubject (edu.internet2.middleware.grouperClient.ws.beans.WsSubject)4 File (java.io.File)4 Iterator (java.util.Iterator)4 IGroupMember (org.apereo.portal.groups.IGroupMember)4 WsGroup (edu.internet2.middleware.grouperClient.ws.beans.WsGroup)3 IOException (java.io.IOException)3 Collection (java.util.Collection)3 LinkedList (java.util.LinkedList)3 GcGetMembers (edu.internet2.middleware.grouperClient.api.GcGetMembers)2 GcGetSubjects (edu.internet2.middleware.grouperClient.api.GcGetSubjects)2 WsGetMembersResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults)2 WsGetSubjectsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetSubjectsResults)2 FilenameFilter (java.io.FilenameFilter)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2