cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Portal Role Creation

Former Member
0 Kudos

Hi,

Can someone explain how to create a role dynamically for users on the portal? We have to create this dynamic portal role using a webdynpro application.

The scenario is like this: User logs into portal. Based on certain data available for this particular user I have to create a role dynamically. If data is not present for the user, we need not create the role.

Hope my query is clear. Please help resolve the problem. Thanks for the help.

Regards,

Chaitanya

Message was edited by:

chaitanya

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

IUserFactory uFact = UMFactory.getUserFactory();

IRoleFactory rFact = UMFactory.getRoleFactory();

IRole test = rFact.getRoleByUniqueName(role1);

IUser me = request.getUser();

IUserMaint mutUser = uFact.getMutableUser(me.getUid());

mutUser.addToRole(test.getUniqueID());

mutUser.commit();

mutUser.save();

Warm Regards,

Murtuza

Former Member
0 Kudos

Hi Murtaza,

I have already tried with your code snippet. I'm able to pick up the right userid. But unable to assign a role to the user. May be i'm not checking it properly. Can you please guide me how to check if the role for the user has been created?

Regards,

Chaitanya

Former Member
0 Kudos

Hi,

You can check it after commit.

Just put this in if else clause and print some msg:

if(me.isMemberOfRole(test.getUniqueID(),true))

{

wdComponentAPI.getMessageManager().reportSuccess("Created");

}

else

{

wdComponentAPI.getMessageManager().reportSuccess("Not Created");

}

Warm Regards,

Murtuza

Former Member
0 Kudos

Hi Murtaza,

Just noticed a small thing in your previous post. what have you declared role1 as?

Regards,

Chaitanya

Former Member
0 Kudos

Hi,

It would be a string specifying the pcd path of your role:

String role1 = "pcd:portal_content/xxx/role1";

You can get this path by clicking on the role that you created in portal and specifying the same over here.

Warm Regards,

Murtuza

Former Member
0 Kudos

Thanks Murtaza. According to the validation, the role is not created. I'm pasting my Java Webdynpro code below. Can you please have a look at it and tell me where i'm going wrong.

String role1 = "pcd:portal_content/THD/Test";

UserFactory userFact = UMFactory.getUserFactory();

IGroupFactory groupFact = UMFactory.getGroupFactory();

IRoleFactory roleFact = UMFactory.getRoleFactory();

IWDClientUser currentUser = WDClientUser.getCurrentUser();

IUser sapCurrentUser = currentUser.getSAPUser();

sapUser = sapCurrentUser;

String userId = currentUser.getClientUserID();

if (sapCurrentUser != null)

{

portalUserId = sapCurrentUser.getUniqueName();

wdComponentAPI.getMessageManager().reportSuccess("portal user id is"+ portalUserId);

testRole1 = roleFact.getRoleByUniqueName(role1);

IUserMaint modUser = userFact.getMutableUser(sapCurrentUser.getUid());

modUser.addToRole(testRole1.getUniqueID());

modUser.commit();

modUser.save();

if(sapCurrentUser.isMemberOfRole(testRole1.getUniqueID(),true))

{

wdComponentAPI.getMessageManager().reportSuccess("ROLE CREATED");

}

else

{

wdComponentAPI.getMessageManager().reportSuccess("ROLE NOT CREATED");

}

}

Regards,

Chaitanya

Former Member
0 Kudos

Code seems to be perfect.. Just try one thing.. assign the role Test to the user manually from user administration and then see what is the output.

Regards,

Murtuza

Former Member
0 Kudos

Hi Murtuza,

I assigned the role manually. Now the role is created.

What do you think is the problem?

Regards,

Chaitanya

Former Member
0 Kudos

Hi

Try out by putting

modUser.save();

modUser.commit();

i.e save first and then commit

I was also facing the same problem.The role would have been assigned to the user at portal side but my checking condition is wrong.

Check out for the condition

modUser.isMemberOfRole(testRole1.getUniqueID(),true)

Regards

Akshaya

Former Member
0 Kudos

Hi chaitanya

Check this blog /people/michael.nicholls/blog/2006/08/09/dynamic-portal-role-assignment

Seems to be helpfull to you

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Ayyaparaj,

I had a look at the blog Michael. But it explains for role creation using portal application and not a webdynpro application.

Regards,

Chaitanya

Former Member
0 Kudos

Hi! chaitanya,

Ues the UME API to create a role from webDynpro appl.link for UME API:--<a href="http://help.sap.com/javadocs/NW04/current/um/index.html">http://help.sap.com/javadocs/NW04/current/um/index.html</a>

use IRoleFactory to create a role or assign a role based on userInput.

Code for getting role will be like this..


 IRoleFactory roleFact = UMFactory.getRoleFactory();
 String[] str = roleFact.getRolesOfUser(UniqueIDOfUser,true);

let me know if you have any problem.

regards,

Mithileshwar