on 12-05-2006 2:23 PM
I am trying to obtain the roles for a user OTHER than the one that is currently logged in and display them in drop down list box. Some example code where I have hard-coded the user name is as follows:
final IWDClientUser wdUser = WDClientUser.getClientUser("Purissimus");
final IUser user = wdUser.getSAPUser();
final IRoleFactory roleFactory = UMFactory.getRoleFactory();
// set up the drop attribute for the drop down list box
IWDAttributeInfo attributeInfo_Distributors = wdContext.getNodeInfo().getAttribute(IPrivateEditCountries.IContextElement.CUR_SAP_USER);
ISimpleTypeModifiable DistributorType = attributeInfo_Distributors.getModifiableSimpleType();
IModifiableSimpleValueSet valueSet_Distributors = DistributorType.getSVServices().getModifiableSimpleValueSet();
// retrieve roles
try {
final AttributeList attrs = new AttributeList();
attrs.addAttribute( IPrincipal.DEFAULT_NAMESPACE, IPrincipal.UNIQUE_NAME );
final IRole[] roles = roleFactory.getRoles(roleFactory.getRolesOfUser(user.getUniqueID(), true ),attrs);
wdContext.currentContextElement().setSAPUserName(user.getUniqueName());
// copy roles to the listbox
for (int i = roles.length - 1; i >= 0; i-- ) {
IRole role = roles[ i ];
valueSet_Distributors.put(role.toString(),role.toString());
}
}
catch (final UMException exOnGetRoles)
{
wdComponentAPI.getMessageManager().reportException( new WDNonFatalException(exOnGetRoles), false );
}
As you can see in this example, I am trying to obtain the roles of the user "Purissimus". For some reason though, the .getRolesOfUser method always seems to return my own roles rather than those of the user I specified.
Thanks for any advice you might be able to offer
-Sheldon
Message was edited by:
Sheldon Lyttle
Hi Sheldon,
Can you try this code to get the list of roles, I havent looked at your code in detail, but this one should get the list of roles,. you will have to add the logic for the dropdowns..see if it works,
Regards,
LM
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
try {
IWDClientUser wdUser = WDClientUser.getClientUser("Purissimus");
String id = wdUser.getClientUserID();
IUser user = wdUser.getSAPUser();
Iterator it = user.getRoles(true);
if (user != null) {
IUserAccount[] acct = user.getUserAccounts();
if (acct[0] != null) {
if (!it.hasNext()) {
wdComponentAPI.getMessageManager().reportSuccess(
"No roles");
}
while (it.hasNext()) {
String roleId = (String) it.next();
IRole role = UMFactory.getRoleFactory().getRole(roleId);
String roleName = role.getUniqueName();
if (roleName != null) {
wdComponentAPI.getMessageManager().reportSuccess("User assigned to" + roleName);
}
}
}
}
} catch (Exception ex) {
msgMgr.reportException(
"Error while retrieving Role information: "
+ ex.getLocalizedMessage(),
false);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This didn't solve the problem BUT it actually proved that it is ignoring this statement becuase I changed it to something silly like
final IWDClientUser wdUser = WDClientUser.getClientUser("MarvinTheParanoidAndroid");
String id = wdUser.getClientUserID();
final IUser user = wdUser.getSAPUser();
Iterator iterator = user.getRoles(true);
final IRoleFactory roleFactory = UMFactory.getRoleFactory();
and obtained the same results ... ie. my own set of roles.
I'll think about this one
Hi Sheldon,
Find the documentation for that method <a href="https://media.sdn.sap.com/javadocs/NW04/SP9/webdynpro/com/sap/tc/webdynpro/services/sal/um/api/WDClientUser.html#getClientUser(java.lang.String)">here</a>
it says that the user id need not match the UME user.
Check it out for more clues,
Regards,
LM
Sheldon,
<a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=k13kfvhfuwg%3d">l Menon</a> find a root of problem -- call to WDClientUser returns new client user wrapper for currently logged-in IUser (i.e. your and my treatment of clientID parameter is wrong ;).
So just retrieve IUser directly via UME API. Try the following:
/* -- COMMENTED OUT
final IWDClientUser wdUser = WDClientUser.getClientUser("MarvinTheParanoidAndroid");
String id = wdUser.getClientUserID();
-- */
final IUser user = UMFactory.getUserFactory().getUserByLogonID("AnyLogonId");
The rest is the same.
Valery Silaev
SaM Solutions
Try to loop though all the logged in users by following code
final IWDClientUser wdUser[] = WDClientUser.getClientUsers();
for (int i = 0; i<wdUser.length; i++){
manager.reportSuccess(wdUser[ i ].getClientUserID());
}
and see if the used id you were testing on i.e. <b>Purissimus</b> exists in this list or not. If the passed in userd id does not exist then the method WDClientUser.getClientUser("<b>Purissimus</b>"); will take the currently logged in user. .
Hope this helps
Firasath
Peace
Message was edited by:
Firasath Riyaz
Message was edited by:
Firasath Riyaz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sheldon,
Strange, the code looks OK.
Try the more direct form: IUser.getRoles(boolean recursive)
Does this variant work as expected?
Valery Silaev
SaM Solutions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestion
'fraid it still returns my roles rather than those of the user I have specified.
I'm stumped for the moment.
for reference, I changed the code to
Iterator iterator = user.getRoles(true);
.
.
.
while (iterator.hasNext()) {
String roleName = (String)iterator.next();
IRole role = roleFactory.getRole(roleName);
valueSet_Distributors.put(role.getDisplayName(),role.getDisplayName());
}
Sheldon Lyttle
Sheldon,
Then I have only a dumb guess: probably you are in fact both have same role set? I mean you (as logged-in user) and user you are testing?
Try to run http://server-host:port/useradmin and verify are there any differences in roles.
Valery Silaev
SaM Solutions
Message was edited by:
Valery Silaev
definitely different:
My account:
<i>Role(s) Currently Assigned to this User:
No of Hits:4 Display 10 hits per page. This is page 1 of 1 pages
Name Description
ca.apotex.clozapine.admin_qa Clozapine Admin QA
ca.apotex.clozapine.demo ApoClozapine Registry Demo
ca.apotex.ferriprox.master_data Ferriprox Master Data
super_admin_role Super Administration
No of Hits:4 Display 10 hits per page. This is page 1 of 1 pages </i>
<b>Purissimus</b> user
Role(s) Currently Assigned to this User:
No of Hits:1 Display 10 hits per page. This is page 1 of 1 pages
Name Description
ca.apotex.ferriprox.distributor Ferriprox Distributor
No of Hits:1 Display 10 hits per page. This is page 1 of 1 pages
I can't imagine this would be related but I am performing the following imports for security
import com.sap.security.api.AttributeList;
import com.sap.security.api.IPrincipal;
import com.sap.security.api.IRole;
import com.sap.security.api.IRoleFactory;
import com.sap.security.api.IUser;
import com.sap.security.api.UMException;
import com.sap.security.api.UMFactory;
import com.sap.tc.webdynpro.services.sal.um.api.IWDClientUser;
import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;
Those are the correct api calls aren't they?
Back to scratching my head I guess
User | Count |
---|---|
83 | |
24 | |
12 | |
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.