Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface WAKDirectory

Hierarchy

  • WAKDirectory

Index

Properties

currentSession

currentSession: WAKConnectionSession

The current user session.

currentUser

currentUser: User

The current user who opened the user session.

Methods

addGroup

  • addGroup(name: String): Group
  • Add a new group to the directory and returns it.

    var myNewGroup = directory.addGroup( 'astronauts' );
    warning

    All updates done to the directory are temporary. Use directory.save() to save all updates on disk.

    Parameters

    • name: String

      Describes the group name

    Returns Group

    Returns the new group

addUser

  • addUser(name: String, password: String, fullName?: String): User
  • Add a new user to the directory and returns it.

    var myNewUser = directory.addUser( 'Thomas Pesquet' );
    warning

    All updates done to the directory are temporary. Use directory.save() to save all updates on disk.

    Parameters

    • name: String

      Describes the user name

    • password: String

      Describes the user password

    • Optional fullName: String

      Describes the user fullname

    Returns User

    Returns the new user

computeHA1

  • computeHA1(userName: String, password: String, realm?: String): String
  • Gets the HA1 key resulting from the combination of userName, password and (optionally) realm parameters using a hash Function.

    Parameters

    • userName: String
    • password: String
    • Optional realm: String

    Returns String

createUserSession

  • 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

    Parameters

    • sessionObj: WAKConnectionSessionInfo

      Describes the session to create

    • Optional keepPreviousSession: Boolean

      (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 void

filterGroups

  • filterGroups(filterString: String): Array<Group>
  • Returns all directory groups starting with filterString.

    var myGroups = directory.filterGroups( '*pers' );

    Parameters

    • filterString: String

      Describe the filtering string

    Returns Array<Group>

    Returns an array of group

filterUsers

  • filterUsers(filterString: String): Array<User>
  • Returns all directory users starting with filterString.

    var myUsers = directory.filterUsers("Jo*");

    Parameters

    • filterString: String

      Describe the filtering string

    Returns Array<User>

    Returns an array of user

getRemoteGroupByAlias

  • getRemoteGroupByAlias(alias: String): Group
  • Returns the local Group Object referencing the remote group with the alias (i.e. the local name) you passed in the alias parameter.

    warning

    Requires LDAP component.

    Parameters

    • alias: String

    Returns Group

getRemoteGroupByDN

  • getRemoteGroupByDN(dn: String): Group
  • Returns a local Group Object referencing the remote group that corresponds to the unique Distinguished Name (DN) you passed in the dn parameter.

    warning

    Requires LDAP component.

    Parameters

    • dn: String

    Returns Group

getSession

  • Get an active session object from a session id.

    var previousSession = directory.getSession( 'BF44D6E51B8FAKE485D8966ED3EDF6DD' );

    Parameters

    • sessionID: String

      Describes the string session id

    Returns WAKConnectionSession

    Returns the session object if any

group

  • group(name: String): Group
  • Gets a group from its name or ID.

    var myGroup = directory.group( 'Spies' );

    Parameters

    • name: String

      Describes the group name or ID

    Returns Group

    Returns the group

loginByKey

  • loginByKey(name: String, key: String, timeOut?: Number): Boolean
  • 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);

    Parameters

    • name: String

      Describes the user name

    • key: String

      Describes a computed key associated to the user

    • Optional timeOut: Number

      Defines the user session timeout (in seconds)

    Returns Boolean

    Returns true if authentication succeed and false if an error occured

loginByPassword

  • loginByPassword(name: String, password: String, timeOut?: Number): Boolean
  • 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);

    Parameters

    • name: String

      Describes the user name

    • password: String

      Describes the user password

    • Optional timeOut: Number

      (seconds) Defines the user session timeout

    Returns Boolean

    Returns true if authentication succeed and false if an error occured

logout

  • logout(): Boolean
  • Logs out the user from its current session on the Wakanda server.

    directory.logout();

    Returns Boolean

    Returns true if the user has been successfully logged out and false if an error occured

save

  • save(): Boolean
  • save(backup: String): Boolean
  • save(backup: WAKFileInstance): Boolean
  • Saves all changes made in the directory.

    directory.save();

    Returns Boolean

    Returns true if successfully saved, false otherwise.

  • Saves all changes made in the directory.

    directory.save( 'PROJECT/backups/2016-01-01.waDirectory' );
    warning

    Destination file must exist

    Parameters

    • backup: String

      Describes a file path for the directory backup.

    Returns Boolean

    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 );
    warning

    Destination file must exist

    Parameters

    Returns Boolean

    Returns true if successfully saved, false otherwise.

setCurrentSession

  • setCurrentSession(sessionId: String, forceExpire?: Boolean): void
  • 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

    Parameters

    • sessionId: String

      Describes the active user session to set as current user session

    • Optional forceExpire: Boolean

      (default: false) Set to true if the previous user session must expire, false otherwise.

    Returns void

setLoginManager

  • setLoginManager(moduleName: String, group?: String): void
  • 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;
        }
    }

    Parameters

    • moduleName: String

      Module name which handles the login

    • Optional group: String

      Group rights assign to the login manager for handling its actions

    Returns void

setSessionManager

  • setSessionManager(modulePath: String): any
  • 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;
    }

    Parameters

    • modulePath: String

      Describes the module path

    Returns any

sync

  • sync(remoteLDAP?: Object): void
  • Synchronizes the local Wakanda directory with a remote LDAP directory.

    warning

    Requires LDAP component.

    Parameters

    • Optional remoteLDAP: Object

    Returns void

user

  • user(name: String): User
  • Gets a user from its name or ID.

    var myUser = directory.user( 'Thomas Pesquet' );

    Parameters

    • name: String

      Describes the user name or ID

    Returns User

    Returns the user