cancel
Showing results for 
Search instead for 
Did you mean: 

check group of the login user using IGroup

Former Member
0 Kudos

try{
	Iterator rit = null;
IWDClientUser clientUser = WDClientUser.getCurrentUser();

IUser user = clientUser.getSAPUser();
rit = user.getRoles(true);
String post=new String();

IRoleFactory rfact = UMFactory.getRoleFactory();
while (rit.hasNext()) {
String roleName = (String) rit.next();
IRole role = rfact.getRole(roleName);
post=role.getDisplayName();


//this method is wrong and not dynamic
//TODO:  check the login user from which group he/she belong
if(user.isMemberOfGroup("super_admin_role",true)==true){
	 //do something
}
if(post.equalsIgnoreCase("Administrator") || post.equalsIgnoreCase("super_admin_role")){
           //do something
	}

}
	}catch(WDUMException wd){
	wd.printStackTrace();
	}catch(UMException e){
	e.printStackTrace();
	}

this code iterate the members within the Everyone group which i only what to check the specific login user group


try{
	IUserFactory myUF=UMFactory.getUserFactory();
	IGroup grp=UMFactory.getGroupFactory().getGroupByUniqueName("Everyone");
	Iterator userMembers=grp.getUserMembers(true);
	ArrayList aUser=new ArrayList();
	
	while(userMembers.hasNext()){
		String userID=(String)userMembers.next();
		IUser myUser=myUF.getUser(userID);
		aUser.add(myUser.getDisplayName());
		}
		
	}catch(Exception ex){
		ex.printStackTrace();
		}

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

ANYONE KNOW HOW TO RETRIEVE THE USER GROUP IT BELONGS TO BASED ON THE PARTICULAR LOGIN USER

0 Kudos

This code returns the iterator containing the user groups. Once you have called it, you have to loop this iterator while hasnext = false.

<b> try{

IWDClientUser clientuser = WDClientUser.getCurrentUser();

IUser user = clientuser.getSAPUser();

Iterator userGroups = null;

userGroups = user.getParentGroups(true);

}

catch(Exception ex){

wdThis.wdGetAPI().getComponent().getMessageManager().raiseMessage( IMessageYSP_CRM_CP_COCKPIT.USER_E , null,true);

}</b>

userGroups has the groups.

Don't forget to loop the iterator in try statement.

I Hope it can work

Grites!