MWS Groups info. of a user using the Java API


We need to know the group membership of a MWS user using the Java API. We tried IDirectory classes but doesn’t seems to work out and getting the null pointer exception.

Can someone please write the flow of the steps we should follow to get the user’s group details?

GetMWSUserGroup.txt (1.41 KB)

Please have a look at this wiki and the attached pdf for some background information:

Try changing the code to this:

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
	String	user = IDataUtil.getString( pipelineCursor, "User" );
	String tempString = null;
	ArrayList<String> availableValues = new ArrayList<String>();
	String users = "";

// pipeline
	IDirectorySystem system = DirectorySystemFactory.getDirectorySystem();
	System.out.println("System value is: "+system);
	IDirectorySession session = system.createSession();
	System.out.println("Session value is: "+session);
	IDirectoryPrincipal principalUser = session.lookupPrincipalByName(user, IDirectoryPrincipal.TYPE_USER);
	System.out.println("PrincipalUser value is: "+principalUser .getName());
	List<IDirectoryGroup> principalList=session.getGroupMembership(principalUser.getID());
	System.out.println("List is: "+principalList);
	System.out.println("principalUser .getID()"+principalUser.getID());
	for(int i=0;i<principalList.size();i++) &#123;
		if(principalList.get(i).getName() != null && principalList.get(i).getType() == 1) &#123;
			users = users + principalList.get(i).getName();
			users = users + ";";
// added to close the session opend to query Idirectory session

IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "Groups", principalUser.getName() );