Search in sources :

Example 61 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, 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 62 with IEntityGroup

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

the class AdHocGroupTester method test.

/*
     * At some point, a person is being tested for group membership. During that test, the thread hits an ad hoc group
     * tester. When that tester calls isDeepMemberOf, a test for group membership is triggered. During this call stack,
     * the second call to the ad hoc group tester returns false. Assuming the group hierarchy is not itself recursive
     * for the group containing the ad hoc group test, the test returns a usable value.
     *
     * If there is no caching and the second person object only exists for the recursive call, then the implementation
     * works.
     *
     * Also, if the person object is cached and used twice, then the group key with the ad hoc tester is not added to
     * the containing group keys during the recursion but is added (or not) after the test call returns positive.
     */
@Override
public boolean test(IPerson person) {
    String personHash = person.getEntityIdentifier().getKey() + groupHash + Thread.currentThread().getId();
    logger.debug("Entering test() for {}", personHash);
    IEntityGroup entityGroup = findGroupByName(groupName);
    if (entityGroup == null) {
        logger.error("Group named '{}' in ad hoc group tester definition not found!!", groupName);
        return false;
    }
    IGroupMember gmPerson = findPersonAsGroupMember(person);
    if (currentTests.getQuiet(personHash) != null) {
        logger.debug("Returning from test() for {} due to recursion for person = {}", personHash, person.toString());
        // stop recursing
        return false;
    }
    Element cacheEl = new Element(personHash, personHash);
    currentTests.put(cacheEl);
    // method that potentially recurs
    boolean isPersonGroupMember = gmPerson.isDeepMemberOf(entityGroup);
    currentTests.remove(personHash);
    final boolean rslt = isPersonGroupMember ^ isNotTest;
    logger.debug("Returning '{}' from test() for '{}' {} a (deep) member of '{}'", rslt, person.getUserName(), isNotTest ? "is not" : "is", entityGroup.getName());
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) Element(net.sf.ehcache.Element)

Example 63 with IEntityGroup

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

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

use of org.apereo.portal.groups.IEntityGroup 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

IEntityGroup (org.apereo.portal.groups.IEntityGroup)77 IGroupMember (org.apereo.portal.groups.IGroupMember)29 ArrayList (java.util.ArrayList)21 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)16 EntityIdentifier (org.apereo.portal.EntityIdentifier)14 HashSet (java.util.HashSet)11 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)9 GroupsException (org.apereo.portal.groups.GroupsException)9 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)9 IPermission (org.apereo.portal.security.IPermission)9 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)8 List (java.util.List)7 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