The current user who opened the user session.
Add a new group to the directory and returns it.
var myNewGroup = directory.addGroup( 'astronauts' );
Describes the group name
Returns the new group
Add a new user to the directory and returns it.
var myNewUser = directory.addUser( 'Thomas Pesquet' );
Describes the user name
Describes the user password
Describes the user fullname
Returns the new user
Gets the HA1 key resulting from the combination of userName, password and (optionally) realm parameters using a hash Function.
Create a new user session and sets it as the current session.
var cur = directory.currentSession;
console.log( cur.ID );
// BF44D6E51B8FAKE485D8966ED3EDF6DD
// Create a new session and keep previous session
directory.createUserSession(
{
ID: '0001000100010001000100010001000100010001',
name: 'jsmith',
fullName: 'Jennifer Smith',
belongsTo: [ 'Manager' ],
lifeTime: 60*60
},
true
);
console.log( directory.currentSession.ID );
// 1E121BA4AE82446B9FDB430F0A9055C6
// The new session is now the current session
var previousSession = directory.getSession( 'BF44D6E51B8FAKE485D8966ED3EDF6DD' );
console.log( previousSession.ID );
// BF44D6E51B8FAKE485D8966ED3EDF6DD
// The previous session is still valid
Describes the session to create
(default false
) Set to true
if you want to keep the previous user session, false
if you want to expire the previous user session.
Returns all directory groups starting with filterString
.
var myGroups = directory.filterGroups( '*pers' );
Describe the filtering string
Returns an array of group
Returns all directory users starting with filterString
.
var myUsers = directory.filterUsers("Jo*");
Describe the filtering string
Returns an array of user
Returns the local Group Object referencing the remote group with the alias (i.e. the local name) you passed in the alias parameter.
Returns a local Group Object referencing the remote group that corresponds to the unique Distinguished Name (DN) you passed in the dn parameter.
Get an active session object from a session id.
var previousSession = directory.getSession( 'BF44D6E51B8FAKE485D8966ED3EDF6DD' );
Describes the string session id
Returns the session object if any
Gets a group from its name or ID.
var myGroup = directory.group( 'Spies' );
Describes the group name or ID
Returns the group
Authenticates a user by their name and key and, in case of success, opens a new user Session on the server.
directory.loginByKey('john', '6153A6FA0E4880D9B8D0BE4720F78E895265D0A9');
directory.loginByKey('john', '6153A6FA0E4880D9B8D0BE4720F78E895265D0A9', 60*60);
Describes the user name
Describes a computed key associated to the user
Defines the user session timeout (in seconds)
Returns true
if authentication succeed and false
if an error occured
Authenticates a user by their name and password and, in case of success, opens a new user Session on the server.
directory.loginByPassword('john', 'my-password');
directory.loginByPassword('john', 'my-password', 60*60);
Describes the user name
Describes the user password
(seconds) Defines the user session timeout
Returns true
if authentication succeed and false
if an error occured
Logs out the user from its current session on the Wakanda server.
directory.logout();
Returns true
if the user has been successfully logged out and false
if an error occured
Saves all changes made in the directory.
directory.save();
Returns true
if successfully saved, false
otherwise.
Saves all changes made in the directory.
directory.save( 'PROJECT/backups/2016-01-01.waDirectory' );
Describes a file path for the directory backup.
Returns true
if successfully saved, false
otherwise.
Saves all changes made in the directory.
var myFile = new File( 'PROJECT/backups/2016-01-01.waDirectory' );
directory.save( myFile );
Describes a file for the directory backup.
Returns true
if successfully saved, false
otherwise.
Sets the session whose UUID is passed in sessionID as the new current session of the running thread.
console.log(directory.currentSession.ID);
// 2EA82764A075497181278B2F05DA2EDA
directory.setCurrentSession('E8CBA745124D4BE4BF7D5A224183EC8E', true);
console.log(directory.currentSession.ID);
// E8CBA745124D4BE4BF7D5A224183EC8E
directory.getSession('2EA82764A075497181278B2F05DA2EDA');
// null
// Previous session has expire
Describes the active user session to set as current user session
(default: false
) Set to true
if the previous user session must expire, false
otherwise.
Defines a module to manage all login requests to Wakanda Server.
directory.setLoginManager('my-login-module');
directory.setLoginManager('my-login-module', 'myDirectoryGroup');
This module is defined inside PROJECT/modules/my-login-module
or SOLUTION/modules/my-login-module
.
If the module is not found in the project, it is then check inside the solution.
It must export a login()
method and return the user
object.
// my-login-module/index.js
// Export a login() function
exports.login = function(username, password){
// Verify the username/password through Directory or any other User DB
// If user is authenticated then return the user object
if (user)
return {
// Unique user ID. Must not collide with an existing user ID
ID: 545642165412,
name: user.name,
fullName: user.fullname,
// References the Directory group where the user belongs
belongsTo: 'free-customer',
// Defines the sessionStorage property of the user session
storage: {}
};
}
// If user not authenticated then return an error
else if (!user)
{
return {
// Error code returned
error: 548,
// Error text returned
errorMessage: 'Authentication failed. Login or Password maybe wrong.'
};
}
// or continue using the standard process (with the internal directory)
else
{
return false;
}
}
Module name which handles the login
Group rights assign to the login manager for handling its actions
Handles and manages sessions through a SSJS module.
// Usually defined in a boostrap file
directory.setSessionManager( 'session' );
// Refers to PROJECT/modules/session/index.js module
The module must export the following methods to handle all session operations:
// PROJECT/modules/session/index.js
// This session manager saves all session in the storage (could be a Redis instead)
// Called everytime the server creates or updates a session
exports.writeSession = function( session ){
// Handle/save this data anywhere you want
console.log( session.userName +' logged-in at '+ new Date() );
// Save session in the storage
var sessionInfo = JSON.stringify( session );
storage[ session.sessionID ] = sessionInfo;
// Return true as everything is ok
return true;
}
// Called everytime the server needs a session description
exports.readSession = function( session ){
var sessionID = session.sessionID;
var sessionInfo = storage[ sessionID ];
if( sessionInfo === undefined ){
return false; // Error, sessionInfo is empty
}
sessionInfo = JSON.parse( sessionInfo );
session.userID = sessionInfo.userID;
session.userName = sessionInfo.userName;
session.storage = sessionInfo.storage;
session.belongsTo = sessionInfo.belongsTo;
session.requestInfo = sessionInfo.requestInfo;
session.lifeTime = sessionInfo.lifeTime;
session.expiration = new Date( sessionInfo.expiration );
// Return true as everything is ok
return true;
}
// Calles everytime the server removes a session
exports.removeSession = function( session ){
console.log( session.userName +' logged-out at '+ new Date() );
var sessionID = session.sessionID;
storage[ sessionID ] = undefined;
// Return true as everything is ok
return true;
}
Describes the module path
Synchronizes the local Wakanda directory with a remote LDAP directory.
Gets a user from its name or ID.
var myUser = directory.user( 'Thomas Pesquet' );
Describes the user name or ID
Returns the user
The current user session.