Search in sources :

Example 31 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 32 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 33 with Attr

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

the class DCTreeServicesImpl method splitAttrSet.

protected AttrSet[] splitAttrSet(String orgDN, AttrSet attrSet) throws AMException, SSOException {
    AttrSet[] attrArray = new AttrSet[2];
    attrArray[0] = (attrSet != null) ? (AttrSet) attrSet.clone() : new AttrSet();
    attrArray[1] = new AttrSet();
    if (attrSet == null) {
        return (attrArray);
    }
    Set dcNodeAttrs = dcNodeAttributes();
    Iterator it = dcNodeAttrs.iterator();
    while (it.hasNext()) {
        String aName = (String) it.next();
        if (aName.indexOf("objectclass=") > -1) {
            Attr attr0 = attrSet.getAttribute("objectclass");
            Attr attr = (attr0 != null) ? (Attr) attr0.clone() : null;
            String oc = aName.substring("objectclass=".length());
            Attr dcAttr = new Attr("objectclass");
            if (attr != null && attr.contains(oc)) {
                attr.removeValue(oc);
                dcAttr.addValue(oc);
                attrArray[0].replace(attr);
                attrArray[1].add(dcAttr);
            }
        } else {
            Attr attr = attrSet.getAttribute(aName);
            if (attr != null) {
                attrArray[1].add(attr);
                attrArray[0].remove(aName);
            }
        }
    }
    if (debug.messageEnabled()) {
        debug.message("DCTreeServicesImpl.splitAttrSet: " + "domain attrset = " + attrArray[1].toString());
        debug.message("DCTreeServicesImpl.splitAttrSet: " + "non-domain attrset = " + attrArray[0].toString());
    }
    return attrArray;
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) Iterator(java.util.Iterator) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 34 with Attr

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

the class DCTreeServicesImpl method setDomainAttributes.

protected void setDomainAttributes(SSOToken token, String orgDN, AttrSet attrSet) throws AMException {
    String domainName = null;
    try {
        domainName = getCanonicalDomain(token, orgDN);
        DomainComponentTree dcTree = new DomainComponentTree(token, new Guid(DCTREE_START_DN));
        if (domainName == null) {
            if (debug.messageEnabled()) {
                debug.message("DCTree.setDomainAttrs: " + "No domain found for org : " + orgDN);
            }
            return;
        }
        DomainComponent dcNode = dcTree.getDomainComponent(domainName);
        if (attrSet != null) {
            if (debug.messageEnabled()) {
                debug.message("DCTree.setDomainAttrs: " + " setting attributes on domain " + domainName + ": " + attrSet.toString());
            }
            Attr ocAttr = attrSet.getAttribute("objectclass");
            if (ocAttr != null) {
                Attr oldOCAttr = dcNode.getAttribute("objectclass");
                if (oldOCAttr != null) {
                    ocAttr.addValues(oldOCAttr.getStringValues());
                }
                if (debug.messageEnabled()) {
                    debug.message("DCTree.setDomainAttrs-> " + "objectclasses to be set " + ocAttr.toString());
                }
                if (ocAttr.size() == 0)
                    dcNode.modify(ocAttr, ModificationType.DELETE);
                else
                    dcNode.modify(ocAttr, ModificationType.REPLACE);
                dcNode.save();
                attrSet.remove("objectclass");
            }
            int size = attrSet.size();
            for (int i = 0; i < size; i++) {
                Attr attr = attrSet.elementAt(i);
                if (attr.size() == 0) {
                    // remove attribute
                    dcNode.modify(attr, ModificationType.DELETE);
                } else {
                    // replace attribute
                    dcNode.modify(attr, ModificationType.REPLACE);
                }
            }
            dcNode.save();
        }
    } catch (UMSException umse) {
        debug.error("DCTree.setDomainAttributes: " + " error setting " + " attribute for domain " + domainName, umse);
    }
}
Also used : DomainComponent(com.iplanet.ums.dctree.DomainComponent) UMSException(com.iplanet.ums.UMSException) DomainComponentTree(com.iplanet.ums.dctree.DomainComponentTree) Guid(com.iplanet.ums.Guid) Attr(com.iplanet.services.ldap.Attr)

Example 35 with Attr

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

the class ComplianceServicesImpl method addAttributesToEntry.

/**
     * Method to addAttributes to an entry
     */
private void addAttributesToEntry(SSOToken token, String dn, AttrSet attrSet) throws UMSException {
    PersistentObject po = UMSObject.getObjectHandle(token, new Guid(dn));
    int size = attrSet.size();
    for (int i = 0; i < size; i++) {
        Attr attr = attrSet.elementAt(i);
        po.modify(attr, ModificationType.ADD);
    }
    po.save();
}
Also used : PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) Attr(com.iplanet.services.ldap.Attr)

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