cancel
Showing results for 
Search instead for 
Did you mean: 

Searching and displaying Roles for a user

Amey-Mogare
Contributor
0 Kudos

Hi,

I want to access roles, worksets, iviews for logged on user.

I am using following piece of code which gives me ALL roles and other PCD contents in portal.


IUser iUser = WDClientUser.getCurrentUser().getSAPUser();
Hashtable env = new Hashtable();
env.put(IPcdContext.SECURITY_PRINCIPAL, iUser);
env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(com.sap.portal.directory.Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
		
InitialContext ctx = null;
DirContext dirCtx;
ctx = new InitialContext(env);
dirCtx = (DirContext) ctx.lookup("pcd:portal_content/");
		
PcdSearchControls pcdSearchControls = new PcdSearchControls();
pcdSearchControls.setReturningObjFlag(false);
pcdSearchControls.setSearchScope(PcdSearchControls.SUBTREE_WITH_UNIT_ROOTS_SCOPE);
dirCtx.addToEnvironment(com.sap.portal.directory.Constants.APPLY_ASPECT_TO_CONTEXTS, com.sap.portal.directory.Constants.APPLY_ASPECT_TO_CONTEXTS);

NamingEnumeration ne = dirCtx.search("","(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.role)",pcdSearchControls);

Any idea how can I get details of the roles for specific user (in this case, logged on user)?

Thanks and regards,

Amey

Accepted Solutions (1)

Accepted Solutions (1)

MaheshChandra
Active Contributor
0 Kudos

hi amey,

check this thread

hope you solve your issue

regards,

Maheshchandra.

( Little bit search helps you more rather than posting the same type of Questions)

Edited by: maheshchandra.lanco on Jun 28, 2010 11:11 AM

Amey-Mogare
Contributor
0 Kudos

Hi,

Thank you for reply.

And I did search before posting this question and also I knew the way to get Roles using UME APIs.


IUser iUser = WDClientUser.getCurrentUser().getSAPUser();
Iterator umeRoleIterator = iUser.getRoles(true);
IRole role = null;
String rolestr = null; 
while(umeRoleIterator.hasNext()){
			
	rolestr = (String) umeRoleIterator.next();
	role = UMFactory.getRoleFactory().getRole(rolestr);
}

But I can see some differences with actual Roles in Portal (the main tabs) and the list of Roles I am getting with above code.

In Portal, I can see total 9 Roles (tabs). However the iterator contains 22 roles.

I need only those roles which I can see when I login to Portal (9 roles).

Any idea how this can be achieved?

(The requirement is that I have to prepare dynamic portal screen using Web Dynpro Java. Hence after getting this list of roles, I also need to somehow navigate to them via URL)

Thanks and regards,

Amey

MaheshChandra
Active Contributor
0 Kudos

hi amey,

Once check ths article on getting portal roles of a loged user.

[Fetching all the Portal Roles Assigned to the Current Logged in User, Using Web Dynpro for Java|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80ef07f8-3e6c-2b10-9cb7-81d4ef2e294a?QuickLink=index&overridelayout=true]

The coding is dfferent from yours and its simple to understand the article.

Regards,

Maheshchandra.

Amey-Mogare
Contributor
0 Kudos

Hi,

This is exactly what I did in my code.

Code in Article -->


IWDClientUser clientUser = WDClientUser.getCurrentUser();
IUser user = clientUser.getSAPUser();

Iterator role = user.getRoles(true);
String str = "";
while (role.hasNext()) {

String rolestr = (String) role.next();
IRole r = UMFactory.getRoleFactory().getRole(rolestr);
str = str +"\n"+ r.getDisplayName();
}

Which is exactly same as what I am doing.

Yes, I am getting all those roles in Portal.

But I am additionally getting many other roles (which are invisible roles may be..the one which are not displayed as "tab" in portal)

I hope I am conveying my issue correctly!

Thanks and regards,

Amey

Former Member
0 Kudos

Hi Arney,

I am not sure whether I completely understand your issue... but anyway, maybe you can solve your issue in a different way. Take a look at [http://help.sap.com/saphelp_nw70/helpdata/en/44/489edff5ee4e35e10000000a1553f6/content.htm|http://help.sap.com/saphelp_nw70/helpdata/en/44/489edff5ee4e35e10000000a1553f6/content.htm], especially at the method getNavNodes(...).

All reachable navigation entries for the current user are fetched in here. This is much more easier, faster and cleaner than traversing the PCD...

If this doesn't fit your needs, then you can e.g. traverse the PCD and test for every found role whether the current user is assigned to it or not (this is however of course not very efficient... maybe there exist more efficient ways...). But you have also to take care of the "entry point" property. Only if this is set to true a role will appear in the top level navigation (furthermore if a role has not set this attribute, but e.g. a subfolder of a role has this property set, then this subfolder will appear in the top level navigation).

MaheshChandra
Active Contributor
0 Kudos

Hi amey,

The code in the article is working for us.

once check did u Add WD_RUNTIME/com.sap.security/lib/com.sap.security.api.jar to your project`s java build path

and

for more check these forums

http://help.sap.com/saphelp_nw04/helpdata/en/f4/67b340be3dff5fe10000000a155106/frameset.htm

Regards,

Maheshchandra

Amey-Mogare
Contributor
0 Kudos

Hi Clemens,

Thank you for reply.

Here is the issue which I am facing -->

Task --> To get all the roles for logged in user which user sees when he logs into portal (top levels Tabs)

Issue --> With UME APIs, the iterator returns the list of roles which contains roles which user sees at top level tabs, but additionally, it contains many other roles which dont have any "tab" for it.

You are correct with Navigation nodes, top level navigation and other types of roles.

Let me have a look at the link which you mentioned.

Thanks and regards,

Amey

Amey-Mogare
Contributor
0 Kudos

Hi Maheshchandra,

Thanks for help, but you are not at all getting my point.

I am not saying that the code in the article doesn't work, ok?

It works well for me too.

Let me explain my question once again -->

Task --> To get all the roles for logged in user which user sees when he logs into portal (top levels Tabs)

Issue --> With UME APIs, the iterator returns the list of roles which contains roles which user sees at top level tabs, but additionally, it contains many other roles which dont have any "tab" for it in Portal screen.

So if you understood clearly, I am not saying that I am not getting all roles or the code in that article is not working.

Its just that I need some way by which I can figure out the roles which are at Top Level navigation for an User.

I hope you understood what I am saying.

Thanks and regards,

Amey

Former Member
0 Kudos

There have been quite a few articles and blogs about building a sitemap, which is effectively what you are trying to do.

For example, <a href="http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/4d46fb8a-0b01-0010-9fbe-e4b96533b222?QuickLink=index&overridelayout=true">this article</a> might be a usful starting point.

Former Member
0 Kudos

Hi again Arney,

then the linked page in my previous post (and also the PDF that Michael linked) is exactly the solution for your issue.

It should be very easy, because it is part of a tutorial ([http://help.sap.com/saphelp_nw70/helpdata/en/44/47b87e9d780597e10000000a155369/content.htm|http://help.sap.com/saphelp_nw70/helpdata/en/44/47b87e9d780597e10000000a155369/content.htm]), in which all necessary steps are explained, even how to set up the portalapp.xml etc.

Amey-Mogare
Contributor
0 Kudos

Hi Clemens,

The Sitemap.java link which you gave worked!

Thank you very much.

Thanks and regards,

Amey

Answers (0)