cancel
Showing results for 
Search instead for 
Did you mean: 

How to get UME Group of a user

Former Member
0 Kudos

Hello All,

In web dynpro, I want to find out which UME group does the logged in user belong to ? Which API should I use ? Which method of the API to use to get the UME group of the logged in user ?

regards

Mrinalini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try the below code, it will list all the Groups which is assigned to a user.

You can implement your own logic and change it as required.

Please add com.sap.security.api.jar in your project build path.


IWDClientUser clientUser  =  WDClientUser.forceLoggedInClientUser();
IUser    user             =  clientUser.getSAPUser();
Iterator groupIterato     =  user.getParentGroups(true);

IGroupFactory    groupFactory   =   UMFactory.getGroupFactory();
IGroupSearchFilter    groupFilter   =  groupFactory.getGroupSearchFilter();

groupFilter.setSearchAttribute(IPrincipal.DEFAULT_NAMESPACE,
IPrincipal.DESCRIPTION,"*",ISearchAttribute.LIKE_OPERATOR,false);

ISearchResult result	= groupFactory.searchGroups(groupFilter);
 
while(result.hasNext()){

String groupName = (String)result.next();
IGroup group          = groupFactory.getGroup(groupName);
			
wdComponentAPI.getMessageManager().reportSuccess("groupName "+groupName);
wdComponentAPI.getMessageManager().reportSuccess("display name "+group.getDisplayName());
}

Answers (4)

Answers (4)

Former Member
0 Kudos

thanks all

Former Member
0 Kudos

Hi Mrinalini,

First you have to add the .jar file to Java Build Path com.sap.security.api

This File Path C:\Program Files\SAP\IDE\IDE70\eclipse\plugins\com.sap.security_2.0.0\lib

try

{

IUser user = WDClientUser.getCurrentUser().getSAPUser();

boolean result = user.isMemberOfGroup("Unique ID of you are UserGroup", true) ;

if(user.isMemberOfGroup("GRUP.PRIVATE_DATASOURCE.un:TEST_USERGROUP", true))

{

if(result)

{

Here you will mention U r Condition

}

}

else

{

Here you will mention U r Condition

}

}

catch(Exception ex)

{

ex.printStackTrace();

}

Hope this is Help full for you

Regards

Vijay Kalluri

Former Member
0 Kudos

Hi,

Use IGroupFactory interface to get the group by "getGroupByUniqueName()"

PFB the link for more info:

http://help.sap.com/javadocs/NW04S/SPS09/se/com/sap/security/api/IGroupFactory.html

Sample code:

IGroupFactory groupFact= UMFactory.getGroupFactory();

groupFact.getGroupByUniqueName("yourGroup").getUniqueId()

Regards,

Lavanya.G

Abhinav_Sharma
Contributor
0 Kudos

Hi Mrinalini,

You can get the UME group of the logged in user using UME APIs. You can use UM factory and IGroupFactory.

Refer code below:

try {

IUser usr = WDClientUser.getCurrentUser().getSAPUser();

Iterator groups = usr.getParentGroups(true);

while (groups.hasNext()) {

String grpStr = (String) groups.next();

IGroup grp = UMFactory.getGroupFactory().getGroup(grpStr);

}

} catch (WDUMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Also refer http://help.sap.com/javadocs/NW04S/SPS09/se/com/sap/security/api/IUserFactory.html for more details

Regards

Abhinav Sharma