Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Searching and displaying Roles for a user

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

Former Member replied

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).

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question