cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve user groups from EP UME Database using Java WebDybnpro

praveenkumar_kadi
Active Contributor
0 Kudos

Hi,

I am trying to retireve assigned groups and roles for a particular user ID from SAP EP UME Datasource.

Any idea what is the search string I need to use something like to retrieve only from UME Database.

IUserSearchFilter userFilt = usrFactory.getUserSearchFilter();

userFilt.setSearchAttribute("com.sap.security.core.usermanagement","datasource","UME Database",

ISearchAttribute.LIKE_OPERATOR,

false);

Any other idea which retrieves all the assigned groups and roles for a specific User ID supplied are welcome.

Thanks

Praveen

Accepted Solutions (1)

Accepted Solutions (1)

siddharth_jain
Active Contributor
0 Kudos

Hi Praveen,

In EP user management if u look at any User group,in group unique id some prefix is present which represent that it is from UME private data source ,in my portal version 7.0 sp 10 it is USER.PRIVATE_DATASOURCE.un ,same is aaplicable for Group and roles.

u should check the same in your Portal.

i worked on similar kind of requirement before where i have to search only UME users :Below is the code snippet.

IUserFactory userfact = UMFactory.getUserFactory();

IUserSearchFilter sf = ufact.getUserSearchFilter();

sf.setUniqueName("*", ISearchAttribute.LIKE_OPERATOR, false);

ISearchResult sr = userfact.searchUsers(sf);

wdContext.nodeUsers().invalidate();

while (sr.hasNext()) {

IUser fuser = userfact.getUser((String) sr.next());

if (fuser.getUid().startsWith("USER.PRIVATE_DATASOURCE.un")) {

wdContext.nodeUsers().addElement(

wdContext.nodeUsers().createUsersElement());

similar type of logic u can apply for getting groups and roles.if you found the user then there are apis which returns groups and roles and from the return data type u can extract the group or role in similar way.

Siddharth

-


-


Answers (3)

Answers (3)

former_member694037
Discoverer
0 Kudos

Hi,

I need to fetch the roles of the groups assigned to a logon user.Can any one help me in providing the code.

I have used below code to fetch the logged in user group.

IUser user = UMFactory.getAuthenticator().getLoggedInUser(); String userName = user.getUniqueName(); String groupName = ""; String groupsList = ""; String str_grpname = "";

Iterator<?> groups = user.getParentGroups(false); while (groups.hasNext()) { str_grpname = groups.next().toString(); IGroup Group = UMFactory.getGroupFactory().getGroup(str_grpname); groupName = Group.getUniqueName(); groupsList = groupsList + "\n" + groupName; }

Now i am looking code to fetch the roles of the User Groups.

Thanks & Regards

Uday Suvvada

srinivas_sistu
Active Contributor
0 Kudos

Hi,

Check this....

try

{

IUserFactory ufactory=UMFactory.getUserFactory();

IRoleFactory rfcat=UMFactory.getRoleFactory();

IUser myuser=ufactory.getUserByLogonID("ssrinu");

// IUserAccount uacc=uafactory.getMutableUserAccount(myuser.getUniqueID());

Iterator i=myuser.getRoles(true);

IRole urole=null;

while(i.hasNext())

{

String s=(String)i.next();

urole=rfcat.getRole(s);

wdComponentAPI.getMessageManager().reportSuccess("urole.getDisplayName()"+urole.getDisplayName());

}

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportSuccess("Exception "+e);

}

similarly you can do it for groups also,

instead of IRoleFactory use IGroupFactory and Iterator i=myuser.getParentGroups(true);

Regards,

SrinivaS

praveenkumar_kadi
Active Contributor
0 Kudos

Hi Nagraju and Srinivas,

Thanks It's worked but I also trying to narrow down the user group display to only UME Database.

Currently both your code displays all the usergroups including LDAP and UME Database. How I extract only from UME Database as source. or specific to single datasource?

Thanks. I have given you suitable points.

Praveen

srinivas_sistu
Active Contributor
0 Kudos

Hi,

Siddarth's reply is quite interesting.... I want to suggest a small change...

instead of

sf.setUniqueName("*", ISearchAttribute.LIKE_OPERATOR, false);

.

.

.

while (sr.hasNext()) {

IUser fuser = userfact.getUser((String) sr.next());

if (fuser.getUid().startsWith("USER.PRIVATE_DATASOURCE.un")) {

.

.

.}

Make it this way, so that seach will yeild less records...

IUserFactory userfact = UMFactory.getUserFactory();

IUserSearchFilter sf = ufact.getUserSearchFilter();

sf.setUniqueName("* USER.PRIVATE_DATASOURCE.un * ", ISearchAttribute.LIKE_OPERATOR, false);

ISearchResult sr = userfact.searchUsers(sf);

wdContext.nodeUsers().invalidate();

while (sr.hasNext()) {

IUser fuser = userfact.getUser((String) sr.next());

wdContext.nodeUsers().addElement(

wdContext.nodeUsers().createUsersElement());

So tha it searches for users whose userID contains USER.PRIVATE_DATASOURCE.un....

More over, this is a user. Hope you can use it for your Group search....

Regards,

SrinivaS

Edited by: srinivas sistu on Jun 3, 2009 6:10 PM

Edited by: srinivas sistu on Jun 3, 2009 6:11 PM

Former Member
0 Kudos

Hi,

To get assigned roles.

private void getAssignedRoles(String userID) throws UMException {

  IUserFactory uf = UMFactory.getUserFactory();
  IUser acc = uf.getUserByLogonID(userID);
     if (acc != null) {
        Iterator itr = acc.getRoles(true);
        IRoleFactory roleF = UMFactory.getRoleFactory();
        while (itr.hasNext()) {
          String id = (String) itr.next();
          IRole role = roleF.getRole(id);
}

}

The same way you can get the assigned groups also.

Regards,

Naga