cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning users to role using Security API

Former Member
0 Kudos

Hi,

I am trying to assign portal users to portal role using the IRoleFactory and IRole class of Secutiy API from my web dynpro application.

For getting the role , i can use either the uniqueId of the role or the uniqueName of the role.(Using methods of IRole class, getRole(uid) or getRoleByUniqueName(uname)).

The UniqueId of roles contains some hash values and cannot be used. For example ROLE.PCD_ROLE_PERSISTENCE.6dT95vZpyNWQHm59z7B9FxAM/fg=.

And the for getting the role using the uniqueName, i need to give like pcd:portal_content/other_vendors/<folder name>/<my prefix>.<rolename>. Which is also not feasible.

Is there any way to get the role only using the role name that we give while creating it?

Thanks and Regards,

Venkat

Accepted Solutions (0)

Answers (1)

Answers (1)

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

Check if this helps.

 try  {
	IRoleFactory rfact = UMFactory.getRoleFactory();
	IRoleSearchFilter isf = rfact.getRoleSearchFilter();
	isf.setDisplayName ("*",ISearchAttribute.LIKE_OPERATOR,false);
	ISearchResult rit = rfact.searchRoles(isf);
	while(rit.next()!=null){
	    String roleName = (String) rit.next();
	    IRole role = rfact.getRole(roleName);
	    response.write("nRole:" + role.getUniqueName());
	 }		  
  }catch(Exception e){
  	response.write("exception");
  }	

U will get list of roles. U can pass these directly or use String tokenizer to separate the role name alone using '.' as separator.

Regards,

Vijai