Search in sources :

Example 16 with Attr

use of com.iplanet.services.ldap.Attr 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 17 with Attr

use of com.iplanet.services.ldap.Attr 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 18 with Attr

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

the class PCMappingTable method getPCMappingTable.

/**
     * Gets the PCMappingTable associated with the given organization
     * 
     * @param org
     *            organization to be managed
     * @return PCMappingTable associated with the given organization
     * @exception UMSException
     *                Failure
     */
public static PCMappingTable getPCMappingTable(Organization org) throws UMSException {
    PersistentObject po = null;
    SearchResults results = org.getChildren("ou=" + MAPPINGTABLE_ENTRYNAME, null);
    if (results.hasMoreElements()) {
        po = results.next();
    } else {
        // Create an entry to store the mapping table if it is
        // not already existed.
        // Right now, we store the mapping table as an entry right under
        // the organization.
        po = new PersistentObject();
        po.setAttribute(new Attr("objectclass", new String[] { "top", "extensibleobject" }));
        po.setAttribute(new Attr("ou", MAPPINGTABLE_ENTRYNAME));
        // po.save( org.getPrincipal(), "ou", org.getGuid() );
        Guid guid = new Guid("ou=" + MAPPINGTABLE_ENTRYNAME + "," + org.getGuid().getDn());
        po.setGuid(guid);
        org.addChild(po);
    }
    results.abandon();
    PCMappingTable mt = new PCMappingTable(org.getPrincipal(), po.getGuid());
    return mt;
}
Also used : Attr(com.iplanet.services.ldap.Attr)

Example 19 with Attr

use of com.iplanet.services.ldap.Attr 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 Attr

use of com.iplanet.services.ldap.Attr 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

Attr (com.iplanet.services.ldap.Attr)89 AttrSet (com.iplanet.services.ldap.AttrSet)34 Guid (com.iplanet.ums.Guid)16 Iterator (java.util.Iterator)15 UMSException (com.iplanet.ums.UMSException)14 PersistentObject (com.iplanet.ums.PersistentObject)12 HashSet (java.util.HashSet)12 Set (java.util.Set)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 ByteString (org.forgerock.opendj.ldap.ByteString)9 AMException (com.iplanet.am.sdk.AMException)7 SSOException (com.iplanet.sso.SSOException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 Enumeration (java.util.Enumeration)4 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)3 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)3 CreationTemplate (com.iplanet.ums.CreationTemplate)3 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)3