npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ad-util

v1.1.6

Published

Wrapper around common Active Directory tasks, allowing for object-based retrieval of user and group data, password changes, account disabling, and object creation and deletion.

Downloads

63

Readme

Active Directory Utility

This module provides a wrapper around common Active Directory tasks. It leverages the activedirectory and ldapjs packages for all LDAP calls.

Getting Started

Use the package's default export to instantiate an instance of the DirectoryUtility class.

const DirectoryUtility = require('ad-util');

const utility = new DirectoryUtility({
  url: 'ldaps://10.0.1.1',
  username: '[email protected]',
  password: 'P@ssw0rd!',
});

The class constructor also passes any additional arguments on to the the ActiveDirectory constructor from the activedirectory package.

API

DirectoryUtility

The DirectoryUtility class exposes the following methods:

async getUsers(filter, location) -> [User]

Returns an array of Users, based on the provided filter.

Arguments

  • String filter (optional) - The filter to use when searching.
  • String location (optional) - The location to search in.
// Get all users
const users = await utility.getUsers();

// Get all users whose names start with "John"
const users = await utility.getUsers('(CN=John *)');

// Get all users in the Accounting/Users OU.
const users = await utility.getUsers(null, 'Accounting/Users');

async getUser(username) -> User

Returns the specified user, or undefined.

Arguments

  • String username - The common name or sAMAccountName to search for.
const user = await utility.getUser('jsmith');

async addUser(location, attributes, password) -> User

Creates a new user.

Arguments

  • String location - The location the object should be placed in path format (e.g: 'Corporation/Users').
  • Object attributes - An object containing attributes to set on the user.
  • String password (optional) - The password to set for the user (or none).
const user = await utility.addUser(
  'Corporation/Users',
  {
    givenName: 'John',
    sn: 'Smith',
    sAMAccountName: 'jsmith',
  },
  'P@ssw0rd!',
);

async getGroups(filter, location) -> [Group]

Returns an array of Groups, based on the provided filter.

Arguments

  • String filter (optional) - The filter to use when searching.
  • String location (optional) - The location to search in.
// Get all groups
const groups = await utility.getGroups();

// Get all groups whose names start with "Domain"
const groups = await utility.getGroups('(CN=Domain *)');

// Get all groups in the Accounting/Groups OU.
const groups = await utility.getGroups(null, 'Accounting/Groups');

async getGroup(name) -> Group

Returns the specified group, or undefined.

Arguments

  • String name - The common name or sAMAccountName to search for.
const group = await utility.getGroup('Administrators');

async addGroup(location, attributes) -> Group

Creates a new group.

Arguments

  • String location - The location the object should be placed in path format (e.g: 'Corporation/Groups').
  • Object attributes - An object containing attributes to set on the group.
const group = await utility.addGroup(
  'Corporation/Groups',
  {
    sAMAccountName: 'Accounting',
  },
);

DirectoryObject (Superclass)

The User and Group classes extend this class and expose the following properties and methods:

dn -> String

Returns the object's distinguished name.

console.log(object.dn);

cn -> String

Returns the object's common name.

console.log(object.cn);

groups -> [String]

Returns the object's group membership.

console.log(object.groups);

isMemberOf(groupName) -> Boolean

Returns a value indicating whether the user is a member of a group.

Arguments

  • String group - The group's common name.
const admin = object.isMemberOf('Domain Administrators');

async reload()

Manually reloads the object's data.

await object.reload();

async set(attributes)

Sets attributes on the object and reloads the object's data.

Arguments

  • Object attributes - An object containing attributes to set on the object.
await object.set({ sn: 'Doe' });

async remove()

Deletes the object.

await object.remove();

async move(location)

Move the object to a new location.

Arguments

  • String location - The location the object should be placed in path format (e.g: 'Corporation/Accounting').
await object.move('Corporation/Accounting');

async setCommonName(commonName)

Move the object to a new location.

Arguments

  • String commonName - The new common name for the object.
await object.setCommonName('New Object');

async addToGroup(group)

Adds the object to a Group.

Arguments

  • Group group - The group to add the object to.
const group = await utility.getGroup('Administrators');
await object.addToGroup(group);

async removeFromGroup(group)

Removes the object from a Group.

Arguments

  • Group group - The remove to remove the object from.
const group = await utility.getGroup('Administrators');
await object.removeFromGroup(group);

User

The User class exposes the following properties and methods:

locked -> Boolean

Returns true is the user is locked, otherwise false.

console.log(user.locked);

enabled -> Boolean

Returns true is the user is enabled, otherwise false.

console.log(user.enabled);

disabled -> Boolean

Returns true is the user is disabled, otherwise false.

console.log(user.disabled);

mustChangePassword -> Boolean

Returns true is the user must change their password, otherwise false.

console.log(user.mustChangePassword);

async enable()

Enables the user's account.

await user.enable();

async disable()

Disables the user's account.

await user.disable();

async unlock()

Unlocks the user's account.

await user.unlock();

async forcePasswordChange()

Forces the user to change their password on their next log on.

await user.forcePasswordChange();

async setPassword(password)

Changes the user's password.

Arguments

  • String password - The new password.
await user.setPassword('P@ssw0rd!');

Group

The Group class exposes the following properties and methods:

members -> [String]

Returns the group's member's distinguished names.

console.log(group.members);

async addMember(member)

Adds a member to the group.

Arguments

  • DirectoryObject member - The object to add to the group.
const user = await utility.getUser('jsmith');
await group.addMember(user);

async removeMember(member)

Removes a member from the group.

Arguments

  • DirectoryObject member - The object to remove from the group.
const user = await utility.getUser('jsmith');
await group.removeMember(user);

Notes

Undocumented Methods

There are several undocumented, lower-level methods in the code. These are designed to be easily accessible and allow you perform low-level operations when necessary.