Skip to Content
avatar image
Former Member

Dynamic role assignment

Hi,

i want to assign to an user a new role depending on one of the selection made in an iview. I used the following code:

private static String FED_MODE = "FED";
private static String FED_ROLE = "FED_ROLE";

IRoleFactory roleFactory = UMFactory.getRoleFactory();
String authentificationMode =
  wdContext.currentGeneralInformationElement()
    .getAuthentificationMode();
if (roleFactory != null) {
  if (authentificationMode.equalsIgnoreCase(FED_MODE)) {
    roleFactory.addUserToRole(portalid,FED_ROLE);
  }
  else {
    roleFactory
      .removeUserFromRole(portalid,"Federal_Role");	
  }
}

i get the following exception:

"The given ID "testuser" is not valid!"

The user-id "testuser" is correct because i use IUserMaint to change thisuser email address and it works fine.

Thanks for the reply,

Peter Ha

Message was edited by: Armin Reichert

(code formatted)

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jun 03, 2005 at 08:03 AM

    There are 2 kinds of IDs -- unique principal ID and "almost-human-readable" logon ID.

    In your case it seems that you have logon ID, but method requires unique principal ID.

    Do not remember exactly, but you may convert it via smth. like that:

    UMFactory.getUserFactory().getUserByLogonID("testuser").getUniqueID();

    VS

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Valery,

      i found it:

      if(roleFactory != null) {

      if(authentificationMode.equalsIgnoreCase(FED_MODE)) {

      roleFactory.addUserToRole(user.getUniqueID(), role.getUniqueID());

      }

      else {

      roleFactory.removeUserFromRole(user.getUniqueID(),role.getUniqueID());

      }

      }

      thanks.