## Modules
adlap
## Constants
adldapClient

A simple Promise based interface to Active Directory backed by the ldapjs library.

## Functions
init([$log])clientFactory

Initialize the module with a logger and return a client factory function. If no logger instance is provided, a noop logger will be used.

## Typedefs
SearchOptions : object
LdapjsOptions : object
ClientConfig : object
## adlap ## adldapClient A simple `Promise` based interface to Active Directory backed by the `ldapjs` library. **Kind**: global constant **Properties** | Name | Type | Description | | --- | --- | --- | | Change | function | Method from the `ldapjs` library to create change objects for use with [adldapClient#replace](adldapClient#replace). See the `ldapjs` client API documentation for information on this function. | * [adldapClient](#adldapClient) * [.authenticate(username, password)](#adldapClient.authenticate) ⇒ Promise * [.bind()](#adldapClient.bind) ⇒ Promise * [.unbind()](#adldapClient.unbind) ⇒ Promise * [.findUser([username], [options])](#adldapClient.findUser) ⇒ Promise * [.replace(dn, change)](#adldapClient.replace) ⇒ Promise * [.replaceAttribute(dn, attribute, value)](#adldapClient.replaceAttribute) ⇒ Promise * [.incrementAttribute(cn, attribute)](#adldapClient.incrementAttribute) ⇒ Promise * [.search([base], [options], [controls])](#adldapClient.search) ⇒ Promise * [.userInGroup(username, groupName)](#adldapClient.userInGroup) ⇒ Promise ### adldapClient.authenticate(username, password) ⇒ Promise Attempt to authenticate a given user by attempting to bind using the supplied credentials. Username formats accepted: + Simple: regular user name, e.g. `juser` for `Joe User` + Filter: an LDAP filter that resolves to the username + DN: the full LDAP DN for the user, e.g. `cn=juser,ou=users,dn=example,dn=com`. + Domain: an Active Directory style username, e.g. 'domain\user' + Principal: a user principal name, e.g. 'juser@domain' **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: boolean On successful authentication `true`, otherwise `false`. **Reject**: Error When an unrecoverable error occurs, e.g. connection failure. | Param | Type | Description | | --- | --- | --- | | username | string | The username for the user to authenticate. | | password | string | The user's password. | ### adldapClient.bind() ⇒ Promise Bind to the directory using the search user's credentials. This method must be invoked prior to any other method. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: \* No value is returned on success. **Reject**: Error On bind failure an error is returned. ### adldapClient.unbind() ⇒ Promise Close the connection to the directory. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: \* No value is returned on success **Reject**: Error ### adldapClient.findUser([username], [options]) ⇒ Promise Performs a search of the directory to find the user identified by the given username. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: object A user object with the properties specified in the attributes option. The user returned is the first entry from a generic search result set. **Reject**: Error | Param | Type | Description | | --- | --- | --- | | [username] | string | Either a simple name, e.g. 'juser', or an LDAP filter that should result in a single user. If it returns multiple users, only the first result will be returned. If omitted, a filter must be supplied in the `options`. Default: `(&(objectcategory=user)(sAMAccountName=username))`. | | [options] | [SearchOptions](#SearchOptions) | Options to be used for the search. | ### adldapClient.replace(dn, change) ⇒ Promise A wrapper around the `ldapjs` library's `modify` method. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: undefined Does not return anything on success. **Reject**: Error | Param | Type | Description | | --- | --- | --- | | dn | string | The full path to the object to modify. | | change | object | An instance of `Change` from the `ldapjs` library describing the change to be made. The `Change` method is available via the `Change` property on the client. | ### adldapClient.replaceAttribute(dn, attribute, value) ⇒ Promise Update an attribute at a specified path with a new value. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: undefined No value is returned on success. **Reject**: Error | Param | Type | Description | | --- | --- | --- | | dn | string | The full path to the object that has the atribute to be modified. | | attribute | string | The name of the attribute to change. | | value | \* | Any valid LDAP attribute value, e.g. a string or an array of strings. | **Example** ```js client.replaceAttribute('foobar', 'coolAttr', 'hello world') ``` ### adldapClient.incrementAttribute(cn, attribute) ⇒ Promise Update an attribute that is a number by incrementing its value by one. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: undefined Does not return anything on success. **Reject**: Error | Param | Type | Description | | --- | --- | --- | | cn | string | The `CN` value for the object to modify. | | attribute | string | The name of the attribute to increment. | **Example** ```js client.incrementAttribute('foobar', 'myCounter') ``` ### adldapClient.search([base], [options], [controls]) ⇒ Promise Perform a generic LDAP query against the directory. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: Array An array of search results. **Reject**: Error | Param | Type | Description | | --- | --- | --- | | [base] | string | The directory tree to use as the search root. Default: [LdapjsOptions#searchBase](LdapjsOptions#searchBase). | | [options] | [SearchOptions](#SearchOptions) | Options to use during the search. | | [controls] | array | A list of directory controls to use during the search. | ### adldapClient.userInGroup(username, groupName) ⇒ Promise Query the directory to determine if a user is a member of a specified group. **Kind**: static method of [adldapClient](#adldapClient) **Resolve**: boolean If the user is a member then `true`, otherwise `false`. **Reject**: Error | Param | Type | Description | | --- | --- | --- | | username | string | A username as described in [Client#findUser](Client#findUser). | | groupName | string | The name of the group to verify. Can be a partial match. | ## init([$log]) ⇒ clientFactory Initialize the module with a logger and return a client factory function. If no logger instance is provided, a noop logger will be used. **Kind**: global function | Param | Type | Description | | --- | --- | --- | | [$log] | object | A logger that conforms to the Log4j interface. | ### init~clientFactory(config) ⇒ [adldapClient](#adldapClient) Build an adldap instance. **Kind**: inner method of [init](#init) **Throws**: - Error When an invalid configuration object is supplied. | Param | Type | Description | | --- | --- | --- | | config | [ClientConfig](#ClientConfig) | Required configuration object to configure the client. | ## SearchOptions : object **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | | filter | string | A valid LDAP filter to use as the query. | | searchBase | string | The base tree to search through. Default: [LdapjsOptions#searchBase](LdapjsOptions#searchBase) | | scope | string | The search scope to use. Can be 'base', 'one', or 'sub'. Default: [LdapjsOptions#scope](LdapjsOptions#scope). | | array | attributes | Default list of attributes to return from searches. Default: [LdapjsOptions#attributes](LdapjsOptions#attributes). | ## LdapjsOptions : object **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | | url | string | The address of the LDAP (AD) server to connect to. This property is required if `socketPath` is not set. | | socketPath | string | A Unix socket path to connect to. | | searchBase | string | The base tree to search through. Can be overriden via options on certain methods. | | scope | string | The search scope to use. Can be 'base', 'one', or 'sub'. Default: 'base'. | | array | attributes | Default list of attributes to return from searches. Default: `['dn', 'cn', 'sn', 'givenName', 'mail', 'memberOf']` | | tlsOptions | object | Standard Node.js TLS options to pass to ldapjs. | ## ClientConfig : object **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | | searchUser | string | User to bind as that will be used to search the directory. | | searchUserPass | string | The password for the `searchUser`. | | ldapjs | LdapjsConfig | Default options to pass to `ldapjs` methods. |