Thursday, April 25, 2013

Add Users into Role and add LADP user into MWS

Add Users into Role in MWS webMethods

and add LADP user into MWS


// get inputs from pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String roleName = IDataUtil.getString(pipelineCursor,"sRoleName");
String userName = IDataUtil.getString(pipelineCursor,"sUserID");

// Create default directory session with no permissions restrictions
IDirectorySession ds = DirectorySystemFactory.getDirectorySystem().createSession();

// Find specified username in LDAP directory
IDirectoryUser ldapUser = (IDirectoryUser) ds.lookupPrincipalByName(userName, IDirectoryPrincipal.TYPE_USER);
if(null == ldapUser) {
    //set status
    IDataUtil.put(pipelineCursor,"bSuccess","false");
    IDataUtil.put(pipelineCursor,"sMessage","Unable to find the user");
} else {
    // Find specified rolename
    IDirectoryPrincipal role = ds.lookupPrincipalByName(roleName, IDirectoryPrincipal.TYPE_ROLE);

    // Assign user to role
    ds.addPrincipalToRole(ldapUser.getID(), role.getID());
   
    //set status
    IDataUtil.put(pipelineCursor,"bSuccess","true");
    IDataUtil.put(pipelineCursor,"sMsg","");
}

// Destroys previously created IDirectorySession
DirectorySystemFactory.getDirectorySystem().destroySession(ds);

// destroy cursor
pipelineCursor.destroy();

1 comment:

  1. Hi, good job, i have a question, how found libraries necessary for compile, thanks!

    ReplyDelete