Search in sources :

Example 16 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class MiscUtils method combineAttrSets.

/**
     * Combines 2 AttrSets and returns the result set. The original sets are not
     * modified.
     * 
     * @param attrSet1
     *            the first AttrSet
     * @param attrSet2
     *            the second AttrSet
     * @return an AttrSet which has combined values of attrSet1 & attrSet2
     */
public static AttrSet combineAttrSets(AttrSet attrSet1, AttrSet attrSet2) {
    AttrSet retAttrSet = new AttrSet();
    if (attrSet1 != null) {
        int count = attrSet1.size();
        for (int i = 0; i < count; i++) {
            Attr attr = attrSet1.elementAt(i);
            retAttrSet.add(attr);
        }
    }
    if (attrSet2 != null) {
        int count = attrSet2.size();
        for (int i = 0; i < count; i++) {
            Attr attr = attrSet2.elementAt(i);
            retAttrSet.add(attr);
        }
    }
    return retAttrSet;
}
Also used : Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 17 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class ComplianceServicesImpl method verifyAndLinkRoleToGroup.

/**
     * Method which verifies if the <code>roleDN</code> corresponds to an
     * admin role. If true the <code>memberOf</code> and
     * <code>adminRole</code> attributes of each member/user are set to the
     * corresponding administration <code>groupDN</code> and administration
     * <code>groupRDN</code> respectively. Each of the members/users are also
     * added to the corresponding admin group.
     * 
     * @param token
     *            single sign on token.
     * @param membersGuid
     *            Guid array of members to be operated on.
     * @param roleDN
     *            distinguished name of the role.
     * 
     * @exception AMException
     *                if unsuccessful in adding the members to the corresponding
     *                admin group. As a result of which the memberOf and
     *                adminRole attributes are also not updated.
     */
protected void verifyAndLinkRoleToGroup(SSOToken token, Guid[] membersGuid, String roleDN) throws AMException {
    // Obtain the group corresponding to roleDN
    DN dn = DN.valueOf(roleDN);
    String groupName = getGroupFromRoleDN(dn);
    if (groupName != null) {
        // roleDN corresponds to an admin role
        String orgDN = dn.parent().toString();
        String groupDN = NamingAttributeManager.getNamingAttribute(AMObject.GROUP) + "=" + groupName + ",ou=Groups," + orgDN;
        String groupRDN = NamingAttributeManager.getNamingAttribute(AMObject.GROUP) + "=" + groupName;
        try {
            // Add the members to corresponding group.
            AssignableDynamicGroup group = (AssignableDynamicGroup) UMSObject.getObject(token, new Guid(groupDN));
            group.addMembers(membersGuid);
            Attr[] attrs = new Attr[1];
            attrs[0] = new Attr("adminrole", groupRDN);
            AttrSet attrSet = new AttrSet(attrs);
            int numMembers = membersGuid.length;
            for (int i = 0; i < numMembers; i++) {
                addAttributesToEntry(token, membersGuid[i].getDn(), attrSet);
            }
        } catch (EntryNotFoundException ex) {
            debug.error("Compliance.verifyAndLinkRoleToGroup: " + "Admin groups are missing");
        } catch (UMSException ue) {
            debug.error("Compliance." + "verifyAndLinkRoleToGroup(): ", ue);
            throw new AMException(AMSDKBundle.getString("771"), "771");
        }
    }
}
Also used : UMSException(com.iplanet.ums.UMSException) EntryNotFoundException(com.iplanet.ums.EntryNotFoundException) AMException(com.iplanet.am.sdk.AMException) DN(org.forgerock.opendj.ldap.DN) Guid(com.iplanet.ums.Guid) AssignableDynamicGroup(com.iplanet.ums.AssignableDynamicGroup) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 18 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class CommonUtils method mapToAttrSet.

/**
     * Method to convert a Map to AttrSet.
     * 
     * @param map
     *            a map contaning attribute names as keys and a Set of attribute
     *            values corresponding to each map key.
     * @param byteValues
     *            if true then values are bytes otherwise strings
     * @return an AttrSet having the contents of the supplied map
     */
protected static AttrSet mapToAttrSet(Map map, boolean byteValues) {
    AttrSet attrSet = new AttrSet();
    if (map == null) {
        return attrSet;
    }
    if (!byteValues) {
        Iterator itr = map.keySet().iterator();
        while (itr.hasNext()) {
            String attrName = (itr.next()).toString();
            Set set = (Set) (map.get(attrName));
            String[] attrValues = (set == null) ? null : (String[]) set.toArray(new String[set.size()]);
            if (attrValues != null) {
                attrSet.replace(new Attr(attrName, attrValues));
            }
        }
    } else {
        Iterator itr = map.keySet().iterator();
        while (itr.hasNext()) {
            String attrName = (itr.next()).toString();
            byte[][] attrValues = (byte[][]) (map.get(attrName));
            if (attrValues != null) {
                attrSet.replace(new Attr(attrName, attrValues));
            }
        }
    }
    return attrSet;
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 19 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class PCMappingTable method getAttrSetFromFilter.

/**
     * Gets the attribute set correspondent to the filter string. Only accepts
     * filter string with the following format:
     * 
     * <PRE>
     * 
     * &ltfilter&gt ::= &ltand&gt | &ltitem&gt &ltand&gt ::= '(' '&'
     * &ltitemlist&gt ')' &ltitemlist&gt ::= &ltitem&gt | &ltitem&gt
     * &ltitemlist&gt &ltitem&gt ::= '(' &ltattr&gt '=' &ltvalue&gt ')'
     * 
     * </PRE>
     * 
     * @param filter
     *            filter string to parse
     * @return the attribute set correspondent to the filter string
     */
private AttrSet getAttrSetFromFilter(String filter) {
    AttrSet attrSet = new AttrSet();
    String f = filter;
    f.trim();
    if (f.startsWith("(") && f.endsWith(")")) {
        f = f.substring(1, f.length() - 1);
    }
    if (f.startsWith("|") || f.startsWith("!")) {
        // TODO: should throw an exception: invalid pc filter
        return null;
    }
    if (f.startsWith("&")) {
        int level = 0;
        int start = 0;
        int end = 0;
        for (int i = 0; i < f.length(); i++) {
            if (f.charAt(i) == '(') {
                if (level == 0) {
                    start = i;
                }
                level++;
            }
            if (f.charAt(i) == ')') {
                level--;
                if (level == 0) {
                    end = i;
                    String subf = f.substring(start, end + 1);
                    if (subf.startsWith("(") && subf.endsWith(")")) {
                        subf = subf.substring(1, subf.length() - 1);
                    }
                    int idx = subf.indexOf('=');
                    if (idx == -1) {
                        return null;
                    }
                    String type = subf.substring(0, idx).trim();
                    String value = subf.substring(idx + 1).trim();
                    attrSet.add(new Attr(type, value));
                }
            }
        }
    } else {
        int idx = f.indexOf('=');
        if (idx == -1) {
            return null;
        }
        String type = f.substring(0, idx).trim();
        String value = f.substring(idx + 1).trim();
        attrSet.add(new Attr(type, value));
    }
    return attrSet;
}
Also used : Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 20 with AttrSet

use of com.iplanet.services.ldap.AttrSet in project OpenAM by OpenRock.

the class PCMappingTable method getPeopleContainer.

/**
     * Gets People Container associated with the user
     * 
     * @param user
     *            user object to look up
     * @return guid identifying People Container associated with the user, null
     *         if no match found and default has not been set
     * @exception UMSException
     *                Failure
     */
public String getPeopleContainer(User user) throws UMSException {
    PersistentObject po = UMSObject.getObject(_principal, _mappingGuid);
    AttrSet attrSet = po.getAttrSet();
    String defaultPC = getDefault(attrSet);
    for (int j = 0; j < ATTRNAMESTOSKIP.length; j++) {
        attrSet.remove(ATTRNAMESTOSKIP[j]);
    }
    Enumeration e1 = attrSet.getAttributes();
    while (e1.hasMoreElements()) {
        Attr attr = (Attr) e1.nextElement();
        String guid = attr.getName();
        String[] filters = attr.getStringValues();
        for (int j = 0; j < filters.length; j++) {
            AttrSet filterAttrSet = getAttrSetFromFilter(filters[j]);
            // loop through filterAttrSet and compare each one to the
            // user's AttrSet
            Enumeration e2 = filterAttrSet.getAttributes();
            while (e2.hasMoreElements()) {
                Attr filterAttr = (Attr) e2.nextElement();
                Attr userAttr = user.getAttribute(filterAttr.getName());
                if (userAttr != null) {
                    String[] filterAttrValues = filterAttr.getStringValues();
                    for (int i = 0; i < filterAttrValues.length; i++) {
                        if (userAttr.contains(filterAttrValues[i])) {
                            return guid;
                        }
                    }
                }
            }
        }
    }
    return defaultPC;
}
Also used : Enumeration(java.util.Enumeration) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Aggregations

AttrSet (com.iplanet.services.ldap.AttrSet)61 Attr (com.iplanet.services.ldap.Attr)33 Guid (com.iplanet.ums.Guid)19 Iterator (java.util.Iterator)16 Set (java.util.Set)14 UMSException (com.iplanet.ums.UMSException)13 AMException (com.iplanet.am.sdk.AMException)12 CreationTemplate (com.iplanet.ums.CreationTemplate)12 TemplateManager (com.iplanet.ums.TemplateManager)12 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 PersistentObject (com.iplanet.ums.PersistentObject)6 SSOException (com.iplanet.sso.SSOException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)4 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)3 AccessRightsException (com.iplanet.ums.AccessRightsException)3 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)3