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.
-
-
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, String entryDn)
Creates a new schema.static Schema
createSchema(SearchResponse schemaResult)
Creates a new schema.private static String
getAttributeValue(LdapEntry entry, String... names)
Returns a single value for the first attribute name found in the supplied entry.private static String[]
getAttributeValues(LdapEntry entry, String... names)
Returns the values for the first attribute name found in the supplied entry.private static SearchResponse
getSearchResult(ConnectionFactory factory, String dn, String filter, String[] retAttrs)
Searches for the supplied dn and returns its ldap entry.
-
-
-
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, 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
-
getSearchResult
private static SearchResponse getSearchResult(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.- Parameters:
factory
- to obtain an LDAP connection fromdn
- to search forfilter
- to search withretAttrs
- attributes to return- Returns:
- ldap entry
- 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
-
getAttributeValue
private static String getAttributeValue(LdapEntry entry, String... names)
Returns a single value for the first attribute name found in the supplied entry.- Parameters:
entry
- containing the attributesnames
- to search for in the entry- Returns:
- single attribute value
-
-