2 Replies Latest reply: May 25, 2013 11:42 PM by 942393 RSS

    Need sample code to assign admin role to a user

    942393
      I am looking for some sample code snippet to assign admin roles to a user.

      Please help.
        • 1. Re: Need sample code to assign admin role to a user
          idamGod
          Try this.

          private void assignAdminRole(String userLogin,String roleName) {       
          AdminRoleService ars = oimClient.getService(AdminRoleService.class);
          AdminRole arole = ars.getAdminRole(roleName);
          AdminRoleMembership arm = new AdminRoleMembership();
          arm.setAdminRole(arole);
          arm.setUserId(getUserKey(userLogin));
          arm.setScopeId("3");
          arm.setHierarchicalScope(false);
          ars.addAdminRoleMembership(arm);
          }


          private String getUserKey(String userLogin) {
          String userKey=null;

          try
          {
          UserManager usrService = oimClient.getService(UserManager.class);
          User user = usrService.getDetails("User Login", userLogin, null);
          userKey=user.getAttribute("usr_key").toString();
          }
          catch(Exception e) {
          e.printStackTrace();
          }
          System.out.println("user Key="+userKey);
          return userKey;
          }
          • 2. Re: Need sample code to assign admin role to a user
            942393
            Thanks Srini.