You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stefan Pietschmann <sp...@inf.tu-dresden.de> on 2004/12/23 11:12:04 UTC

Retrieving AuthenticationContext from custom Action

Hi guys,

I'm currently writing an action which merges some things from the request
and deli into the AuthenticationContext.

I just don't seem to get the Context, though. 
I'd prefer to get it as DOM (a Document or DocumentFragment), so I don't
really want to use streamContextFragment(..) from the sessionManager like
Cocoon's SessionPreTransformer does.

I have the ContextManager and the SessionManager. 
I tried with the AuthenticationContextProvider (though I'm really not sure
why this is needed at all), but it returned a NullPointerException.

Well, the action (shortened to the important bits) looks like this:

public void service(ServiceManager manager)... {
super.service(manager);
        try {
            getDeli();
            getContextManager();
            getSessionManager();
        }
        catch (ProcessingException pe) {
            throw new ServiceException("Error looking up components.");
        }
} 

public Map act( ...) ..{

if
(contextManager.existsContext(AuthenticationConstants.SESSION_CONTEXT_NAME))
{
	authContext =
(AuthenticationContext)contextManager.getContext(AuthenticationConstants.SES
SION_CONTEXT_NAME);
	System.out.println("1st way:
"+sessionManager.getContextFragment(authContext.getName(),"/authentication")
.toString());
	System.out.println("2nd way:
"+authContext.getXML("/authentication").toString());}
}

So far this is only for debugging purpose to see if I get the context or not
- but it doesn't look so. This is what the console says:
1st way: [#document-fragment: null]
2nd way: [#document-fragment: null]

My first question would be: 
Which is the best way to obtain the authentication context? Via the
SessionManager, ContextManager.. or AuthenticationContextProvider? Is there
any striking difference?

Second question of course: How do I get the context??

The pipeline part looks like this:

<map:act type="auth-protect">
	<map:parameter name="handler" value="portalhandler"/>
	 ...
	<!-- my action: -->
	<map:act type="updateModel">
		<map:parameter name="requestParam" value="xml:Foo"/>
	</map:act>
	...
	<map:transform type="session"/>
		<map:transform
src="{global:trans}outputauthentication.xsl"/>
	<map:transform type="session"/>
	...
</map:act>

Funnily the outputauthentication stylesheet (see below) returns the context,
so it must be possible with my action as well :O

<xsl:template match="/">
	<authContext ...>
		<session:getxml context="authentication"
path="/authentication"/>
	</authContext>
</xsl:template>

Thank you for your help!

Cheers and Merry Christmas,
Stefan 

P.S.: Using Cocoon 2.1.6 on Tomcat 5.0.28 on JDK 1.4.2_06


RE: Retrieving AuthenticationContext from custom Action

Posted by Carsten Ziegeler <cz...@apache.org>.
Stefan Pietschmann wrote: 
> 
> <SNIP/>
> 
> My first question would be: 
> Which is the best way to obtain the authentication context? 
> Via the SessionManager, ContextManager.. or 
> AuthenticationContextProvider? Is there any striking difference?
> 
> Second question of course: How do I get the context??
> 
The best way is to use the ContextManager. The SessionManager is
a legacy component and the authenticationcontextprovider is an
internal component.

So, you fetch the context from the ContextManager like you did
in your sample code and then using getXML("/authentication")
you should get a DocumentFragment with the contents. Did
you check if the fragment has children?

Carsten