on 08-19-2009 10:08 PM
Hi,
I was trying to get all the users that are assigned to a role using the following code:
IRoleFactory roleFac = UMFactory.getRoleFactory();
String[] allUsrs = roleFac.getUsersOfRole("rl_guideln_administrators", true);
,but it doesnt work, it give me an exception saying that the ID doesnt exist. The id of the role in portal is:rl_guideln_administrators.
What should i do ?!
thanks!
Hi,
try this code,
package com.hcl.user;
import java.util.Iterator;
import java.util.Vector;
import com.sap.security.api.IRole;
import com.sap.security.api.IRoleFactory;
import com.sap.security.api.IRoleSearchFilter;
import com.sap.security.api.ISearchResult;
import com.sap.security.api.IUser;
import com.sap.security.api.IUserAccount;
import com.sap.security.api.IUserFactory;
import com.sap.security.api.UMFactory;
import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
public class role_member extends AbstractPortalComponent {
public void doContent(
IPortalComponentRequest request,
IPortalComponentResponse response) {
try {
IUserFactory userfactory = UMFactory.getUserFactory();
IRoleFactory rolefactory = UMFactory.getRoleFactory();
IRoleSearchFilter rolefltr = rolefactory.getRoleSearchFilter();
rolefltr.setMaxSearchResultSize(2000);
ISearchResult result = rolefactory.searchRoles(rolefltr);
while (result.hasNext()) {
response.write("<table border=0>n");
String uniqueid = (String) result.next();
IRole role = rolefactory.getRole(uniqueid);
response.write("<tr><td bgcolor=Red>"+ role.getDisplayName()+ "</tr></td>n");
Iterator users = role.getUserMembers(true);
while (users.hasNext()) {
String unique_user = (String) users.next();
IUser user = userfactory.getUser(unique_user);
IUserAccount account[] = user.getUserAccounts();
response.write(
"<tr><td>" + account[0].getLogonUid() + "</tr></td>n");
}
response.write("</table>n");
response.write("</br>n");
}
} catch (Exception e) {
}
}
}
Regards,
Sunaina Reddy T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Use this code to get the roles
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);
}
[For details Check this Blog.|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2080] [original link is broken];
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the below code, i guess role name might be wrong. Give full role name.
try {
IWDClientUser wdUser = WDClientUser.getCurrentUser();
if(wdUser != null){
IUser user = wdUser.getSAPUser();
if(user!= null){
Iterator rolesList = user.getRoles(true);
IRoleFactory roleFactory = UMFactory.getRoleFactory();
while(rolesList.hasNext()){
wdComponentAPI.getMessageManager().reportSuccess("Role List "+ rolesList.next().toString());
String users[] = roleFactory.getUsersOfRole("ROLE.UME_ROLE_PERSISTENCE.un:Administrator", true);
if(users != null){
for(int i=0; i< users.length; i++){
wdComponentAPI.getMessageManager().reportSuccess("User "+ users<i>);
}
}
}
}
}
}catch(Exception exp){
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.