cancel
Showing results for 
Search instead for 
Did you mean: 

Access User Roles

Former Member
0 Kudos

Hi,

Can I access user roles by using the following code and if so, then how do I retrieve the role information from the iterator.

//This is code for getting Username and role.

IWDClientUser user1 = WDClientUser.forceLoggedInClientUser();

IUser user2 = user1.getSAPUser();

try{

if (user2 != null) { IUserAccount[] acct = user2.getUserAccounts();

if(acct[0] != null)

{

String strUserid = acct[0].getLogonUid();

wdComponentAPI.getMessageManager().reportSuccess("name"+strUserid);

Iterator it = acct[0].getRoles(true);

}

}

}

catch (UMException e) {

wdComponentAPI.getMessageManager().reportSuccess(e.toString());

}

Thanks,

Jay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

This should help you.

//Get Role Information
  if (it.hasNext()) {
    IRoleFactory rfact = UMFactory.getRoleFactory();
    while (it.hasNext()) {
        String roleName = (String) it.next();
        IRole role = null;
        try {
            role = rfact.getRole(roleName);
            wdComponentAPI.getMessageManager().reportSuccess("Role:" + roleName  
            + "Display Name:"    + role.getDisplayName()
            + "ID: " + role.getUniqueID()
            + "Uniquename: " + role.getUniqueName()
            + "Description: " + role.getDescription());
        } catch (UMException e) {
        wdComponentAPI.getMessageManager.reportException("error: " + e.getLocalizedMessage(),true);
        }
    }
  }

regards

ravi

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Ravi's code gives all the details.

Thanks

Jay

Former Member
0 Kudos

Hi AnilKumar,

Your code gives me the roles assigned, but not the description. I get the result as :

ROLE.PCD_ROLE_PERSISTENCE.VvlvkEGjiW9zPFaxR/4pd2/bX5Q=

How can i get the description for the roles

Thanks

Jay

detlev_beutner
Active Contributor
0 Kudos

Hi Jay,

see /thread/7752 [original link is broken]

Hope it helps

Detlev

Former Member
0 Kudos

Hi,

Try this

Iterator it=user.getSAPUser().getRoles(true);

while(it.hasNext())

{

String role=it.next().toString();

}

Regards, Anilkumar

Former Member
0 Kudos

Hi Santhosh,

I did not get the list of roles assigned. I program execution did not enter the while loop.

Is the call to getRoles() function incorrect?

Iterator it = acct[0].getRoles(true);

The UserID is displayed fine and I have six roles assigned to my userID

Thanks,

Jay

Former Member
0 Kudos

Hi Jay,

Write the following piece of code below the "Iterator it" statement

while(it.hasNext()){

IRole role = (IRole)it.next();

wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("role::"+role);

}

Regards,

Santhosh.C