I need to access the AuthenticationContext from a component. First things first: I have it working, but I've got a question anyways:

 

First I tried two ways:

 

  1. Implement Serviceable and get the ServiceManager, then a) lookup the ContextManager and b) lookup the SessionManager.

 

In short: it didn't work. Both were null and I couldn't get the Context that way.

 

Then I found http://wiki.apache.org/cocoon/AuthFWWithFlow , which suggests the following way:

 

ComponentManager componentManager = CocoonComponentManager.getSitemapComponentManager();
SessionManager sessionManager = (SessionManager)componentManager.lookup(SessionManager.ROLE);
String username = sessionManager.getContextFragment( "authentication", "/authentication/ID").getFirstChild().getNodeValue();
 
This works nicely, however the javadoc inside CocoonComponentManager states:
 
"Cocoon Component Manager. This manager extends the ExcaliburComponentManager by a special lifecycle handling for a RequestLifecycleComponent and by handling the lookup of the SourceResolver. WARNING: This is a "private" Cocoon core class - do NOT use this class directly - and do not assume that a ComponentManager you get via the compose() method is an instance of CocoonComponentManager."
 
So, am I supposed to use this or not? If not, what would be a better way?
 
Cheers,
Stefan

 

Reply via email to