Skip to Content
0
Former Member
Apr 20, 2011 at 09:12 AM

Controlling role visibility through code

17 Views

Hi All,

I need to be able to hide worksets and roles depending upon the user that logs in. I have managed to control iviews and pages using the following code


Hashtable env = new Hashtable();
env.put(
       Context.INITIAL_CONTEXT_FACTORY,
       IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, request.getUser());

env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
InitialContext iCtx = null;
	
try {
iCtx = new InitialContext(env);
						
	IiView result = null;
					
	Object currentObject  =  iCtx.lookup(iViewID);
	if (currentObject instanceof IiView) {
                      	result = (IiView)currentObject;
	}else{
	}
	result.putAttribute("com.sap.portal.navigation.Invisible",invisibleValue);
	result.save();
} catch (UnsupportedOperationException e) {
										e.printStackTrace();
} catch (NamingException e) {
	e.printStackTrace();
} catch (ValidationException e) {
	e.printStackTrace();
} catch (IOException e) {
	e.printStackTrace();
}

After looking around some more, i thought there must be something similar for worksets and roles as well.

I found the use of IRoleService and IRoleDescriptor. But its only given how to create new roles using these. Can someone help me out on how to access existing roles so that I can set the property dynamically for them?