Skip to Content
avatar image
Former Member

Obtaining the roles for a user

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 05, 2006 at 03:50 PM

    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);
    		}
    

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 05, 2006 at 02:38 PM

    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

    http://www.sam-solutions.net

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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 😉

  • avatar image
    Former Member
    Dec 06, 2006 at 12:43 AM

    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

    Add comment
    10|10000 characters needed characters exceeded