Search in sources :

Example 81 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier 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 82 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class EntityPersonAttributesGroupStore method searchForGroups.

@Override
public EntityIdentifier[] searchForGroups(String query, SearchMethod 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 DISCRETE:
            for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
                IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
                if (g.getName().equals(query)) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case DISCRETE_CI:
            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().startsWith(query)) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case STARTS_WITH_CI:
            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().endsWith(query)) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case ENDS_WITH_CI:
            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().indexOf(query) != -1) {
                    results.add(g.getEntityIdentifier());
                }
            }
            break;
        case CONTAINS_CI:
            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 83 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier 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 84 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class SmartLdapGroupStore method findParentGroups.

/**
 * Returns an <code>Iterator</code> over the <code>Collection</code> of <code>IEntityGroups
 * </code> that the <code>IGroupMember</code> belongs to.
 *
 * @return java.util.Iterator
 * @param gm org.apereo.portal.groups.IEntityGroup
 */
public Iterator findParentGroups(IGroupMember gm) throws GroupsException {
    if (isTreeRefreshRequired()) {
        refreshTree();
    }
    List<IEntityGroup> rslt = new LinkedList<>();
    final IEntityGroup root = getRootGroup();
    if (gm.isGroup()) {
        // Check the local indeces...
        IEntityGroup group = (IEntityGroup) gm;
        List<String> list = groupsTree.getParents().get(group.getLocalKey());
        if (list != null) {
            // should only reach this code if its a SmartLdap managed group...
            for (String s : list) {
                rslt.add(groupsTree.getGroups().get(s));
            }
        }
    } else if (!gm.isGroup() && gm.getLeafType().equals(root.getLeafType())) {
        // Ask the individual...
        EntityIdentifier ei = gm.getUnderlyingEntityIdentifier();
        Map<String, List<Object>> seed = new HashMap<>();
        List<Object> seedValue = new LinkedList<>();
        seedValue.add(ei.getKey());
        seed.put(IPerson.USERNAME, seedValue);
        Map<String, List<Object>> attr = personAttributeDao.getMultivaluedUserAttributes(seed);
        // avoid NPEs and unnecessary IPerson creation
        if (attr != null && !attr.isEmpty()) {
            IPerson p = PersonFactory.createPerson();
            p.setAttributes(attr);
            // Analyze its memberships...
            Object[] groupKeys = p.getAttributeValues(memberOfAttributeName);
            // IPerson returns null if no value is defined for this attribute...
            if (groupKeys != null) {
                List<String> list = new LinkedList<>();
                for (Object o : groupKeys) {
                    list.add((String) o);
                }
                for (String s : list) {
                    if (groupsTree.getGroups().containsKey(s)) {
                        rslt.add(groupsTree.getGroups().get(s));
                    }
                }
            }
        }
    }
    return rslt.iterator();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPerson(org.apereo.portal.security.IPerson) 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 85 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class GetMemberKeyPhrase method getPhrase.

// Internal search, thus case sensitive.
public static String getPhrase(String name, String memberValue) {
    String rslt = null;
    // We can cut & run now if the element is a <literal>...
    if (name.equals("literal")) {
        return memberValue;
    }
    try {
        // Next see if it's a <channel> element...
        if (name.equals("channel")) {
            IPortletDefinition def = PortletDefinitionRegistryLocator.getPortletDefinitionRegistry().getPortletDefinitionByFname(memberValue);
            return String.valueOf(def.getPortletDefinitionId().getStringId());
        }
        // Must be a group...
        Class[] leafTypes = new Class[] { IPerson.class, IPortletDefinition.class };
        for (int i = 0; i < leafTypes.length && rslt == null; i++) {
            EntityIdentifier[] eis = GroupService.searchForGroups(memberValue, IGroupConstants.SearchMethod.DISCRETE, leafTypes[i]);
            if (eis.length == 1) {
                // Match!
                IEntityGroup g = GroupService.findGroup(eis[0].getKey());
                rslt = g.getLocalKey();
                break;
            } else if (eis.length > 1) {
                String msg = "Ambiguous member name:  " + memberValue;
                throw new RuntimeException(msg);
            }
        }
    } catch (Throwable t) {
        String msg = "Error looking up the specified member:  " + memberValue;
        throw new RuntimeException(msg, t);
    }
    if (rslt == null) {
        String msg = "The specified member was not found:  " + memberValue;
        throw new RuntimeException(msg);
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPerson(org.apereo.portal.security.IPerson) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

EntityIdentifier (org.apereo.portal.EntityIdentifier)93 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)31 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)24 IPerson (org.apereo.portal.security.IPerson)17 GroupsException (org.apereo.portal.groups.GroupsException)16 IEntityGroup (org.apereo.portal.groups.IEntityGroup)16 Set (java.util.Set)14 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)13 Iterator (java.util.Iterator)12 IGroupMember (org.apereo.portal.groups.IGroupMember)12 List (java.util.List)6 Element (net.sf.ehcache.Element)6 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)6 HashMap (java.util.HashMap)5 InvalidNameException (javax.naming.InvalidNameException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 GcFindGroups (edu.internet2.middleware.grouperClient.api.GcFindGroups)2