Search in sources :

Example 1 with AttributeType

use of org.forgerock.opendj.ldap.schema.AttributeType in project OpenAM by OpenRock.

the class SchemaManager method getObjectClasses.

/**
     * Gets a collection of the names of the object classes for this attribute
     *
     * @param attrName
     *            Name of the attribute
     * @return A collection of the names of the object classes for this
     *         attribute
     * @throws UMSException
     *             failure
     */
public Collection<String> getObjectClasses(String attrName) throws UMSException {
    Collection<String> objClassNames = new ArrayList<>();
    Collection<ObjectClass> objClasses = getLDAPSchema().getObjectClasses();
    for (ObjectClass objClass : objClasses) {
        for (AttributeType attributeType : objClass.getRequiredAttributes()) {
            if (attributeType.getNameOrOID().equalsIgnoreCase(attrName)) {
                objClassNames.add(objClass.getNameOrOID());
            }
        }
        for (AttributeType attributeType : objClass.getOptionalAttributes()) {
            if (attributeType.getNameOrOID().equalsIgnoreCase(attrName)) {
                objClassNames.add(objClass.getNameOrOID());
            }
        }
    }
    return objClassNames;
}
Also used : ObjectClass(org.forgerock.opendj.ldap.schema.ObjectClass) AttributeType(org.forgerock.opendj.ldap.schema.AttributeType) ArrayList(java.util.ArrayList)

Example 2 with AttributeType

use of org.forgerock.opendj.ldap.schema.AttributeType in project OpenAM by OpenRock.

the class DJLDAPv3Repo method unassignService.

/**
     * Unassigns a service from the provided identity.
     * In case of a USER this will traverse through all the existing user attributes and will remove those that are
     * currently present in the entry. This will also remove the objectclass corresponding to the service.
     * In case of a REALM this will remove the service from the locally cached serviceMap, and will notify the
     * registered {@link IdRepoListener}.
     *
     * @param token Not used.
     * @param type The type of the identity, this should be always USER or REALM.
     * @param name The name of the identity. Only used when identity type is USER.
     * @param serviceName The name of the service to remove from the identity.
     * @param attrMap Holds the objectclasses relevant for this service removal.
     * @throws IdRepoException If the identity type was invalid or if there was an error while removing the service.
     */
@Override
@SuppressWarnings("rawtypes")
public void unassignService(SSOToken token, IdType type, String name, String serviceName, Map<String, Set<String>> attrMap) throws IdRepoException {
    if (DEBUG.messageEnabled()) {
        DEBUG.message("unassignService invoked");
    }
    if (type.equals(IdType.USER)) {
        Set<String> removeOCs = attrMap.get(OBJECT_CLASS_ATTR);
        if (removeOCs != null) {
            Schema dirSchema = getSchema();
            Map attrs = new CaseInsensitiveHashMap();
            for (String oc : removeOCs) {
                try {
                    ObjectClass oc2 = dirSchema.getObjectClass(oc);
                    for (AttributeType optional : oc2.getOptionalAttributes()) {
                        attrs.put(optional.getNameOrOID(), Collections.EMPTY_SET);
                    }
                    for (AttributeType required : oc2.getRequiredAttributes()) {
                        attrs.put(required.getNameOrOID(), Collections.EMPTY_SET);
                    }
                } catch (UnknownSchemaElementException usee) {
                    DEBUG.error("Unable to unassign " + serviceName + " service from identity: " + name, usee);
                    throw newIdRepoException(IdRepoErrorCode.UNABLE_GET_SERVICE_SCHEMA, serviceName);
                }
            }
            Set<String> requestedAttrs = new CaseInsensitiveHashSet(attrs.keySet());
            //if the service objectclass is auxiliary (which it should be), then the objectclass attribute may not
            //be present if top is not defined as superior class.
            requestedAttrs.add(OBJECT_CLASS_ATTR);
            Map<String, Set<String>> attributes = new CaseInsensitiveHashMap(getAttributes(token, type, name, requestedAttrs));
            Set<String> OCValues = new CaseInsensitiveHashSet(attributes.get(OBJECT_CLASS_ATTR));
            OCValues.removeAll(removeOCs);
            attrs.put(OBJECT_CLASS_ATTR, OCValues);
            //implementing retainAll here for CaseInsensitiveHashMap's keySet
            for (String string : (Set<String>) attrs.keySet()) {
                if (!attributes.containsKey(string)) {
                    attrs.remove(string);
                }
            }
            setAttributes(token, type, name, attrs, false, true, false);
        }
    } else if (type.equals(IdType.REALM)) {
        if (serviceName != null && !serviceName.isEmpty()) {
            serviceMap.remove(serviceName);
        }
        if (idRepoListener != null) {
            idRepoListener.setServiceAttributes(serviceName, serviceMap);
        }
    } else {
        throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, new Object[] { CLASS_NAME });
    }
}
Also used : ObjectClass(org.forgerock.opendj.ldap.schema.ObjectClass) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) UnknownSchemaElementException(org.forgerock.opendj.ldap.schema.UnknownSchemaElementException) Schema(org.forgerock.opendj.ldap.schema.Schema) ByteString(org.forgerock.opendj.ldap.ByteString) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) IdRepoUnsupportedOpException(com.sun.identity.idm.IdRepoUnsupportedOpException) AttributeType(org.forgerock.opendj.ldap.schema.AttributeType) Map(java.util.Map) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap)

Example 3 with AttributeType

use of org.forgerock.opendj.ldap.schema.AttributeType in project OpenAM by OpenRock.

the class SchemaManager method getOptionalAttributes.

/**
     * Returns a collection of the names of the optional attributes for this
     * object class.
     * 
     * @param objClassName Name of the object class.
     * @return a collection of the names of the optional attributes for this
     *         object class.
     * @throws UMSException if failed to get attribute names.
     */
private Collection<String> getOptionalAttributes(String objClassName) throws UMSException {
    Collection<String> attributeNames = new ArrayList<>();
    ObjectClass objClass = getLDAPSchema().getObjectClass(objClassName);
    if (objClass != null) {
        for (AttributeType attributeType : objClass.getOptionalAttributes()) {
            attributeNames.add(attributeType.getNameOrOID());
        }
    }
    return attributeNames;
}
Also used : ObjectClass(org.forgerock.opendj.ldap.schema.ObjectClass) AttributeType(org.forgerock.opendj.ldap.schema.AttributeType) ArrayList(java.util.ArrayList)

Example 4 with AttributeType

use of org.forgerock.opendj.ldap.schema.AttributeType in project OpenAM by OpenRock.

the class SchemaManager method getRequiredAttributes.

/**
     * Returns a collection of the names of the required attributes for this
     * object class.
     * 
     * @param objClassName Name of the object class.
     * @return a collection of the names of the required attributes for this
     *         object class.
     * @throws UMSException if failed to get attribute names.
     */
private Collection<String> getRequiredAttributes(String objClassName) throws UMSException {
    Collection<String> attributeNames = new ArrayList<>();
    ObjectClass objClass = getLDAPSchema().getObjectClass(objClassName);
    if (objClass != null) {
        for (AttributeType attributeType : objClass.getRequiredAttributes()) {
            attributeNames.add(attributeType.getNameOrOID());
        }
    }
    return attributeNames;
}
Also used : ObjectClass(org.forgerock.opendj.ldap.schema.ObjectClass) AttributeType(org.forgerock.opendj.ldap.schema.AttributeType) ArrayList(java.util.ArrayList)

Aggregations

AttributeType (org.forgerock.opendj.ldap.schema.AttributeType)4 ObjectClass (org.forgerock.opendj.ldap.schema.ObjectClass)4 ArrayList (java.util.ArrayList)3 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 IdRepoUnsupportedOpException (com.sun.identity.idm.IdRepoUnsupportedOpException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CollectionUtils.asSet (org.forgerock.openam.utils.CollectionUtils.asSet)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 Schema (org.forgerock.opendj.ldap.schema.Schema)1 UnknownSchemaElementException (org.forgerock.opendj.ldap.schema.UnknownSchemaElementException)1