Search in sources :

Example 1 with RuntimeRequestResponse

use of org.danann.cernunnos.runtime.RuntimeRequestResponse in project uPortal by Jasig.

the class CernunnosDataExporter method exportDataElement.

@Override
protected Element exportDataElement(String id) {
    final RuntimeRequestResponse request = new RuntimeRequestResponse();
    request.setAttribute(this.idAttributeName, id);
    final ReturnValueImpl result = new ReturnValueImpl();
    final TaskResponse response = new RuntimeRequestResponse(Collections.<String, Object>singletonMap("Attributes.RETURN_VALUE", result));
    task.perform(request, response);
    return (Element) result.getValue();
}
Also used : RuntimeRequestResponse(org.danann.cernunnos.runtime.RuntimeRequestResponse) ReturnValueImpl(org.danann.cernunnos.ReturnValueImpl) Element(org.dom4j.Element) TaskResponse(org.danann.cernunnos.TaskResponse)

Example 2 with RuntimeRequestResponse

use of org.danann.cernunnos.runtime.RuntimeRequestResponse in project uPortal by Jasig.

the class SmartLdapGroupStore method buildGroupsTree.

private GroupsTree buildGroupsTree() {
    long timestamp = System.currentTimeMillis();
    // Prepare the new local indeces...
    Map<String, IEntityGroup> new_groups = Collections.synchronizedMap(new HashMap<String, IEntityGroup>());
    Map<String, List<String>> new_parents = Collections.synchronizedMap(new HashMap<String, List<String>>());
    Map<String, List<String>> new_children = Collections.synchronizedMap(new HashMap<String, List<String>>());
    Map<String, List<String>> new_keysByUpperCaseName = Collections.synchronizedMap(new HashMap<String, List<String>>());
    // Gather IEntityGroup objects from LDAP...
    RuntimeRequestResponse req = new RuntimeRequestResponse();
    Set<LdapRecord> set = new HashSet<>();
    req.setAttribute("GROUPS", set);
    req.setAttribute("smartLdapGroupStore", this);
    SubQueryCounter queryCounter = new SubQueryCounter();
    req.setAttribute("queryCounter", queryCounter);
    // This one changes iteratively...
    req.setAttribute("filter", filter);
    // while this one stays the same.
    req.setAttribute("baseFilter", filter);
    if (StringUtils.isBlank(baseGroupDn)) {
        throw new IllegalStateException("baseGroupDn property not set");
    }
    req.setAttribute("baseGroupDn", baseGroupDn);
    if (ldapContext == null) {
        throw new IllegalStateException("ldapContext property not set");
    }
    req.setAttribute("ldapContext", ldapContext);
    req.setAttribute("resolveMemberGroups", resolveMemberGroups);
    req.setAttribute("resolveDnList", resolveDnList);
    req.setAttribute("memberOfAttributeName", memberOfAttributeName);
    req.setAttribute("attributesMapper", attributesMapper);
    runner.run(initTask, req);
    log.info("init() found {} records", set.size());
    // Do a first loop to build the main catalog (new_groups)...
    for (LdapRecord r : set) {
        // new_groups (me)...
        IEntityGroup g = r.getGroup();
        new_groups.put(g.getLocalKey(), g);
    }
    // Do a second loop to build local indeces...
    for (LdapRecord r : set) {
        IEntityGroup g = r.getGroup();
        // new_parents (I am a parent for all my children)...
        for (String childKey : r.getKeysOfChildren()) {
            // discard everything else...
            if (!new_groups.containsKey(childKey)) {
                break;
            }
            List<String> parentsList = new_parents.get(childKey);
            if (parentsList == null) {
                // first parent for this child...
                parentsList = Collections.synchronizedList(new LinkedList<String>());
                new_parents.put(childKey, parentsList);
            }
            parentsList.add(g.getLocalKey());
        }
        // new_children...
        List<String> childrenList = Collections.synchronizedList(new LinkedList<String>());
        for (String childKey : r.getKeysOfChildren()) {
            // discard everything else...
            if (new_groups.containsKey(childKey)) {
                childrenList.add(childKey);
            }
        }
        new_children.put(g.getLocalKey(), childrenList);
        // new_keysByUpperCaseName...
        List<String> groupsWithMyName = new_keysByUpperCaseName.get(g.getName().toUpperCase());
        if (groupsWithMyName == null) {
            // I am the first group with my name (pretty likely)...
            groupsWithMyName = Collections.synchronizedList(new LinkedList<String>());
            new_keysByUpperCaseName.put(g.getName().toUpperCase(), groupsWithMyName);
        }
        groupsWithMyName.add(g.getLocalKey());
    }
    /*
         * Now load the ROOT_GROUP into the collections...
         */
    // new_groups (me)...
    final IEntityGroup root = getRootGroup();
    new_groups.put(root.getLocalKey(), root);
    // new_parents (I am a parent for all groups that have no other parent)...
    List<String> childrenOfRoot = // for later...
    Collections.synchronizedList(new LinkedList<String>());
    for (String possibleChildKey : new_groups.keySet()) {
        if (!possibleChildKey.equals(root.getLocalKey()) && !new_parents.containsKey(possibleChildKey)) {
            List<String> p = Collections.synchronizedList(new LinkedList<String>());
            p.add(root.getLocalKey());
            new_parents.put(possibleChildKey, p);
            // for later...
            childrenOfRoot.add(possibleChildKey);
        }
    }
    // new_children...
    new_children.put(root.getLocalKey(), childrenOfRoot);
    // new_keysByUpperCaseName...
    List<String> groupsWithMyName = new_keysByUpperCaseName.get(root.getName().toUpperCase());
    if (groupsWithMyName == null) {
        // I am the first group with my name (pretty likely)...
        groupsWithMyName = Collections.synchronizedList(new LinkedList<String>());
        new_keysByUpperCaseName.put(root.getName().toUpperCase(), groupsWithMyName);
    }
    groupsWithMyName.add(root.getLocalKey());
    final long benchmark = System.currentTimeMillis() - timestamp;
    log.info("Refresh of groups tree completed in {} milliseconds", benchmark);
    log.info("Total number of LDAP queries:  {}", queryCounter.getCount() + 1);
    final String msg = "init() :: final size of each collection is as follows..." + "\n\tgroups={}" + "\n\tparents={}" + "\n\tchildren={}" + "\n\tkeysByUpperCaseName={}";
    log.info(msg, new_groups.size(), new_parents.size(), new_children.size(), new_keysByUpperCaseName.size());
    if (log.isTraceEnabled()) {
        StringBuilder sbuilder = new StringBuilder();
        // new_groups...
        sbuilder.setLength(0);
        sbuilder.append("Here are the keys of the new_groups collection:");
        for (String s : new_groups.keySet()) {
            sbuilder.append("\n\t").append(s);
        }
        log.trace(sbuilder.toString());
        // new_parents...
        sbuilder.setLength(0);
        sbuilder.append("Here are the parents of each child in the new_parents collection:");
        for (Map.Entry<String, List<String>> y : new_parents.entrySet()) {
            sbuilder.append("\n\tchild=").append(y.getKey());
            for (String s : y.getValue()) {
                sbuilder.append("\n\t\tparent=").append(s);
            }
        }
        log.trace(sbuilder.toString());
        // new_children...
        sbuilder.setLength(0);
        sbuilder.append("Here are the children of each parent in the new_children collection:");
        for (Map.Entry<String, List<String>> y : new_children.entrySet()) {
            sbuilder.append("\n\tparent=").append(y.getKey());
            for (String s : y.getValue()) {
                sbuilder.append("\n\t\tchild=").append(s);
            }
        }
        log.trace(sbuilder.toString());
        // new_keysByUpperCaseName...
        sbuilder.append("Here are the groups that have each name in the new_keysByUpperCaseName collection:");
        for (Map.Entry<String, List<String>> y : new_keysByUpperCaseName.entrySet()) {
            sbuilder.append("\n\tname=").append(y.getKey());
            for (String s : y.getValue()) {
                sbuilder.append("\n\t\tgroup=").append(s);
            }
        }
        log.trace(sbuilder.toString());
    }
    return new GroupsTree(new_groups, new_parents, new_children, new_keysByUpperCaseName);
}
Also used : LinkedList(java.util.LinkedList) IEntityGroup(org.apereo.portal.groups.IEntityGroup) RuntimeRequestResponse(org.danann.cernunnos.runtime.RuntimeRequestResponse) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with RuntimeRequestResponse

use of org.danann.cernunnos.runtime.RuntimeRequestResponse in project uPortal by Jasig.

the class CernunnosDataImporter method importDataElement.

/* (non-Javadoc)
     * @see org.apereo.portal.io.xml.crn.AbstractDom4jImporter#importDataNode(org.apereo.portal.utils.Tuple)
     */
@Override
protected void importDataElement(Tuple<String, Element> data) {
    final RuntimeRequestResponse request = new RuntimeRequestResponse();
    request.setAttribute(Attributes.NODE, data.second);
    request.setAttribute(Attributes.LOCATION, StringUtils.trimToEmpty(data.first));
    final ReturnValueImpl result = new ReturnValueImpl();
    final TaskResponse response = new RuntimeRequestResponse(Collections.<String, Object>singletonMap("Attributes.RETURN_VALUE", result));
    this.task.perform(request, response);
}
Also used : RuntimeRequestResponse(org.danann.cernunnos.runtime.RuntimeRequestResponse) ReturnValueImpl(org.danann.cernunnos.ReturnValueImpl) TaskResponse(org.danann.cernunnos.TaskResponse)

Aggregations

RuntimeRequestResponse (org.danann.cernunnos.runtime.RuntimeRequestResponse)3 ReturnValueImpl (org.danann.cernunnos.ReturnValueImpl)2 TaskResponse (org.danann.cernunnos.TaskResponse)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 Element (org.dom4j.Element)1