Package org.ldaptive.ad.schema
Class SchemaFactory
- java.lang.Object
-
- org.ldaptive.ad.schema.SchemaFactory
-
public final class SchemaFactory extends Object
Factory to createSchema
from an active directory schema search result. Active Directory does not adhere to RFC 4512 to represent its schema. Each schema element is represented with a separate LDAP entry. The factory parses and sets the object classes and attribute types for the schema. The other properties on the schema object are not available.
-
-
Field Summary
Fields Modifier and Type Field Description private static String
ADMIN_DESCRIPTION_ATTR_NAME
Admin description attribute name on the entry.private static String
ADMIN_DISPLAY_NAME_ATTR_NAME
Admin display name attribute name on the entry.private static String
ATTRIBUTE_ID_ATTR_NAME
Attribute ID attribute name on the entry.private static String
ATTRIBUTE_SCHEMA_ATTR_NAME
Attribute schema attribute name on the entry.private static String
ATTRIBUTE_SYNTAX_ATTR_NAME
Attribute syntax attribute name on the entry.private static String
CLASS_SCHEMA_ATTR_NAME
Class schema attribute name on the entry.private static String
GOVERNS_ID_ATTR_NAME
Governs ID attribute name on the entry.private static String
IS_SINGLE_VALUED_ATTR_NAME
Is single valued attribute name on the entry.private static String
LDAP_DISPLAY_NAME_ATTR_NAME
LDAP display name attribute name on the entry.private static String
MAY_CONTAIN_ATTR_NAME
May contain attribute name on the entry.private static String
MUST_CONTAIN_ATTR_NAME
Must contain attribute name on the entry.private static String
NAME_ATTR_NAME
Name attribute name on the entry.private static String
OBJECT_CLASS_ATTR_NAME
Object class attribute name on the entry.private static String
OBJECT_CLASS_CATEGORY_ATTR_NAME
Object class category attribute name on the entry.private static String
SCHEMA_FILTER
Filter for schema entries.private static String
SCHEMA_NAMING_CONTEXT_ATTR_NAME
Attribute on the root DSE indicating the location of the schema entries.private static String
SUB_CLASS_OF_ATTR_NAME
Sub class of attribute name on the entry.private static String
SYSTEM_MAY_CONTAIN_ATTR_NAME
System may contain attribute name on the entry.private static String
SYSTEM_MUST_CONTAIN_ATTR_NAME
System must contain attribute name on the entry.private static String
SYSTEM_ONLY_ATTR_NAME
System only attribute name on the entry.
-
Constructor Summary
Constructors Modifier Constructor Description private
SchemaFactory()
Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static AttributeType
createAttributeType(LdapEntry entry)
Creates an attribute type from the supplied ldap entry.private static ObjectClass
createObjectClass(LdapEntry entry)
Creates an object class from the supplied ldap entry.static Schema
createSchema(InputStream is)
Creates a new schema.static Schema
createSchema(ConnectionFactory factory)
Creates a new schema.static Schema
createSchema(ConnectionFactory factory, String entryDn)
Creates a new schema.private static Schema
createSchema(ConnectionFactory factory, String dn, String filter, String... retAttrs)
Searches for the supplied dn and returns its ldap entry.static Schema
createSchema(SearchResponse schemaResult)
Creates a new schema.private static String[]
getAllAttributeValues(LdapEntry entry, String... names)
Returns the values for all attributes with the supplied names found in the supplied entry.private static String[]
getFirstAttributeValues(LdapEntry entry, String... names)
Returns the values for the first attribute name found in the supplied entry.
-
-
-
Field Detail
-
SCHEMA_NAMING_CONTEXT_ATTR_NAME
private static final String SCHEMA_NAMING_CONTEXT_ATTR_NAME
Attribute on the root DSE indicating the location of the schema entries.- See Also:
- Constant Field Values
-
SCHEMA_FILTER
private static final String SCHEMA_FILTER
Filter for schema entries.- See Also:
- Constant Field Values
-
OBJECT_CLASS_ATTR_NAME
private static final String OBJECT_CLASS_ATTR_NAME
Object class attribute name on the entry.- See Also:
- Constant Field Values
-
OBJECT_CLASS_CATEGORY_ATTR_NAME
private static final String OBJECT_CLASS_CATEGORY_ATTR_NAME
Object class category attribute name on the entry.- See Also:
- Constant Field Values
-
ATTRIBUTE_SCHEMA_ATTR_NAME
private static final String ATTRIBUTE_SCHEMA_ATTR_NAME
Attribute schema attribute name on the entry.- See Also:
- Constant Field Values
-
CLASS_SCHEMA_ATTR_NAME
private static final String CLASS_SCHEMA_ATTR_NAME
Class schema attribute name on the entry.- See Also:
- Constant Field Values
-
ATTRIBUTE_ID_ATTR_NAME
private static final String ATTRIBUTE_ID_ATTR_NAME
Attribute ID attribute name on the entry.- See Also:
- Constant Field Values
-
LDAP_DISPLAY_NAME_ATTR_NAME
private static final String LDAP_DISPLAY_NAME_ATTR_NAME
LDAP display name attribute name on the entry.- See Also:
- Constant Field Values
-
ADMIN_DISPLAY_NAME_ATTR_NAME
private static final String ADMIN_DISPLAY_NAME_ATTR_NAME
Admin display name attribute name on the entry.- See Also:
- Constant Field Values
-
NAME_ATTR_NAME
private static final String NAME_ATTR_NAME
Name attribute name on the entry.- See Also:
- Constant Field Values
-
ADMIN_DESCRIPTION_ATTR_NAME
private static final String ADMIN_DESCRIPTION_ATTR_NAME
Admin description attribute name on the entry.- See Also:
- Constant Field Values
-
ATTRIBUTE_SYNTAX_ATTR_NAME
private static final String ATTRIBUTE_SYNTAX_ATTR_NAME
Attribute syntax attribute name on the entry.- See Also:
- Constant Field Values
-
IS_SINGLE_VALUED_ATTR_NAME
private static final String IS_SINGLE_VALUED_ATTR_NAME
Is single valued attribute name on the entry.- See Also:
- Constant Field Values
-
SYSTEM_ONLY_ATTR_NAME
private static final String SYSTEM_ONLY_ATTR_NAME
System only attribute name on the entry.- See Also:
- Constant Field Values
-
GOVERNS_ID_ATTR_NAME
private static final String GOVERNS_ID_ATTR_NAME
Governs ID attribute name on the entry.- See Also:
- Constant Field Values
-
SUB_CLASS_OF_ATTR_NAME
private static final String SUB_CLASS_OF_ATTR_NAME
Sub class of attribute name on the entry.- See Also:
- Constant Field Values
-
MUST_CONTAIN_ATTR_NAME
private static final String MUST_CONTAIN_ATTR_NAME
Must contain attribute name on the entry.- See Also:
- Constant Field Values
-
SYSTEM_MUST_CONTAIN_ATTR_NAME
private static final String SYSTEM_MUST_CONTAIN_ATTR_NAME
System must contain attribute name on the entry.- See Also:
- Constant Field Values
-
MAY_CONTAIN_ATTR_NAME
private static final String MAY_CONTAIN_ATTR_NAME
May contain attribute name on the entry.- See Also:
- Constant Field Values
-
SYSTEM_MAY_CONTAIN_ATTR_NAME
private static final String SYSTEM_MAY_CONTAIN_ATTR_NAME
System may contain attribute name on the entry.- See Also:
- Constant Field Values
-
-
Method Detail
-
createSchema
public static Schema createSchema(InputStream is) throws IOException
Creates a new schema. The input stream should contain the LDIF for the schema search results.- Parameters:
is
- containing the schema ldif- Returns:
- schema
- Throws:
IOException
- if an error occurs reading the input stream
-
createSchema
public static Schema createSchema(ConnectionFactory factory) throws LdapException
Creates a new schema. The schema naming context is searched for on the root DSE, followed by searching for all entries under the schema naming context.- Parameters:
factory
- to obtain an LDAP connection from- Returns:
- schema created from the connection factory
- Throws:
LdapException
- if the search fails
-
createSchema
public static Schema createSchema(ConnectionFactory factory, String entryDn) throws LdapException
Creates a new schema. The entryDn is searched to obtain the schema.- Parameters:
factory
- to obtain an LDAP connection fromentryDn
- the schema entries- Returns:
- schema
- Throws:
LdapException
- if the search fails
-
createSchema
public static Schema createSchema(SearchResponse schemaResult)
Creates a new schema. The schema result should contain entries with the 'attributeSchema' and 'classSchema' objectClasses.- Parameters:
schemaResult
- containing the schema entries- Returns:
- schema
-
createSchema
private static Schema createSchema(ConnectionFactory factory, String dn, String filter, String... retAttrs) throws LdapException
Searches for the supplied dn and returns its ldap entry. This methods uses the paged results search control as schema entries typically number beyond the server search size limit. An entry handler is used in order to free memory as soon an entry is processed.- Parameters:
factory
- to obtain an LDAP connection fromdn
- to search forfilter
- to search withretAttrs
- attributes to return- Returns:
- new schema
- Throws:
LdapException
- if the search fails
-
createAttributeType
private static AttributeType createAttributeType(LdapEntry entry)
Creates an attribute type from the supplied ldap entry. The entry must contain an objectClass of 'attributeSchema'. This method only populates the OID, names, description, syntax, and single valued properties of the attribute type.- Parameters:
entry
- containing an attribute schema- Returns:
- attribute type
-
createObjectClass
private static ObjectClass createObjectClass(LdapEntry entry)
Creates an object class from the supplied ldap entry. The entry must contain an objectClass of 'classSchema'. This method only populates the OID, names, description, superior classes, object class type, required attributes, and optional attributes of the object class.- Parameters:
entry
- containing a class schema- Returns:
- object class
-
getFirstAttributeValues
private static String[] getFirstAttributeValues(LdapEntry entry, String... names)
Returns the values for the first attribute name found in the supplied entry.- Parameters:
entry
- containing the attributesnames
- to search for in the entry- Returns:
- attribute values or null if no attributes are found
-
getAllAttributeValues
private static String[] getAllAttributeValues(LdapEntry entry, String... names)
Returns the values for all attributes with the supplied names found in the supplied entry.- Parameters:
entry
- containing the attributesnames
- to search for in the entry- Returns:
- attribute values or null if no attributes are found
-
-