cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephanie Zohner" <stephanie.zoh...@gmx.at>
Subject RE: HELP! Custom Action using AuthenticationContext
Date Mon, 19 Jul 2004 14:59:53 GMT
I substituted the AuthenticationContextProvider with the ContextManager as
proposed by you, but unfortunately I still get a NullPointerException.

the stacktrace is:

java.lang.NullPointerException
	at
org.apache.cocoon.components.ContextHelper.getRequest(ContextHelper.java:88)
	at
org.apache.cocoon.webapps.session.components.DefaultContextManager.getSession(DefaultContextManager.java:113)
	at
org.apache.cocoon.webapps.session.components.DefaultContextManager.existsContext(DefaultContextManager.java:337)
	at archivesystem.roles.GetRolesAction.act(GetRolesAction.java:60)
....

The exception in my Action occurs in this
line:

if(contextManager.existsContext(AuthenticationConstants.SESSION_CONTEXT_NAME))


This time the problem seems to be the context object in
DefaultContextManager, which seems to be null.

What I've done wrong?

Is it a good idea to implement the initializable interface and intitialize
the DefaultContextManager there?

Here's my changed source code:
--------------------------------------------------------------------

public class GetRolesAction extends AbstractAction implements ThreadSafe,
Initializable{
	
	protected ContextManager contextManager; 

	public void initialize() throws Exception {
		contextManager = new DefaultContextManager();
	}

	
	public Map act(
		Redirector redirector,
		SourceResolver sourceResolver,
		Map objectModel,
		String src,
		Parameters parameters)
		throws Exception {
			
		Map map = null;
		
		//check parameter
		final String project = parameters.getParameter("project");
		if(project == null){
			throw new ProcessingException("GetRolesAction requires the parameter
'project'.");
		}
		if (contextManager == null){
			throw new NullPointerException("Can't get contextManager.");
		}
		SessionContext sessionContext =
null;
		
		if(contextManager.existsContext(AuthenticationConstants.SESSION_CONTEXT_NAME)){

			sessionContext =
contextManager.getContext(AuthenticationConstants.SESSION_CONTEXT_NAME);
		}		
		else{
					throw new NullPointerException("Can't get sessionContext");
		}
		
		map = new HashMap(3);
		//check roles
		if
(sessionContext.getSingleNode("authentication/rights/projects/project[@name="+project+"]/admin")!=null)
			map.put("admin","true");
		else
			map.put("admin","false");
		
                 /*......*/
		}

}

--------------------------------------------------------------------


Thanks a lot for your help in advance,

Regards,

Stephanie




> You should access the context using the ContextManager (in the session
> block). The provider classes are internal "plugins" for the context
> manager to make such custom contexts, like the authentication context,
> available.
> 
> HTH
> Carsten 
> 
> > -----Original Message-----
> > From: Stephanie Zohner [mailto:stephanie.zohner@gmx.at] 
> > Sent: Monday, July 19, 2004 2:34 PM
> > To: dev@cocoon.apache.org
> > Subject: HELP! Custom Action using AuthenticationContext
> > 
> > 
> > Hi all,
> > 
> > 
> > Sorry for double posting but I got no anwers in the users 
> > list, so I hope that one of you java gurus can help me.
> > 
> > 
> > I get a NullPointerException in my GetRolesAction.
> > 
> > With my action I want to make the user roles available to the 
> > sitemap. The roles are stored in the Authentication Context. 
> > 
> > All I want to do is read out the roles from the 
> > Authentication context and put it in the map that is returned 
> > to the sitemap.
> > 
> > However I get a NullPointerException when retrieving the 
> > authentication context.
> > I "followed" the exception to the Class 
> > AuthenticationContextProvider. I guess the problem is that 
> > the ServiceManager is not initialized, but is null.
> > 
> > How can I make my Code working? Do I have to call the 
> > service() method of the AuthenticationContextProvider to set 
> > the serviceManager instance??
> > 
> > Thanks alot for bringing light into my darkness,
> > 
> > Regards,
> > 
> > Stephanie
> > 
> > P.S.: Code and Exception Text see below:
> > 
> > ______________________________________________________________
> > __________
> > 
> > public class GetRolesAction extends AbstractAction implements 
> > ThreadSafe, Initializable{
> > 	
> > 	protected AuthenticationContextProvider contextProvider; 
> > 
> > 	public void initialize() throws Exception {
> > 		contextProvider = new AuthenticationContextProvider();
> > 	}
> > 
> > 	
> > 	public Map act(
> > 		Redirector redirector,
> > 		SourceResolver sourceResolver,
> > 		Map objectModel,
> > 		String src,
> > 		Parameters parameters)
> > 		throws Exception {
> > 			
> > 		Map map = null;
> > 		
> > 		//check parameter
> > 		final String project = 
> > parameters.getParameter("project");
> > 		if(project == null){
> > 			throw new 
> > ProcessingException("GetRolesAction requires the parameter 
> > 'project'.");
> > 		}
> > 		if (contextProvider == null){
> > 			throw new NullPointerException("Can't 
> > get contextProvider.");
> > 		}
> > 		AuthenticationContext
> > sessionContext
> > =
> > null;
> > 		
> > 		
> > if(contextProvider.existsSessionContext(AuthenticationConstant
> > s.SESSION_CONTEXT_NAME)){
> > 
> > 			sessionContext
> > =
> > (AuthenticationContext)
> > contextProvider.getSessionContext(AuthenticationConstants.SESS
> > ION_CONTEXT_NAME);
> > 		}		
> > 		else{
> > 					throw new 
> > NullPointerException("Can't get sessionContext");
> > 		}
> > 		
> > 		map = new
> > HashMap(3);
> > 		//check
> > roles
> > 		if
> > (sessionContext.getSingleNode("authentication/rights/projects/
> > project[@name="+project+"]/admin")!=null)
> > 			map.put("admin","true");
> > 		else
> > 			map.put("admin","false");
> > 		
> > 		if
> > (sessionContext.getSingleNode("authentication/rights/projects/
> > project[@name="+project+"]/developer")!=null)
> > 			map.put("developer","true");
> > 		else
> > 			map.put("developer","false");
> > 			
> > 		if
> > (sessionContext.getSingleNode("authentication/rights/projects/
> > project[@name="+project+"]/guest")!=null)
> > 			map.put("guest","true");
> > 		else
> > 			map.put("guest","false");
> > 		
> > 		return
> > map;
> > 	}
> > 
> > }
> > --------------------------------------------------------------
> > ----------
> > 
> > 
> > java.lang.NullPointerException
> > 
> > 	at
> > org.apache.cocoon.webapps.authentication.context.Authenticatio
> > nContextProvider.getSessionContext(AuthenticationContextProvid
> > er.java:97)
> > 
> > 	at
> > archivesystem.roles.GetRolesAction.act(GetRolesAction.java:57)
> > 
> > 	at
> > org.apache.cocoon.components.treeprocessor.sitemap.ActTypeNode
> > .invoke(ActTypeNode.java:152)
> > 
> > 	at
> > org.apache.cocoon.components.treeprocessor.AbstractParentProce
> > ssingNode.invokeNodes(AbstractParentProcessingNode.java:84)
> > 
> > ....
> > --------------------------------------------------------------
> > ------------
> > 
> > My Sitemap snippet 
> > 
> > <map:match pattern="protected-*">
> >   <map:act type="auth-protect">
> >     <map:match pattern="protected-delivery">
> >       	<map:generate type="request"/>
> > 	  <map:act type="getRoles">
> > 	    <map:parameter name="project" 
> > value="{session-attr:project}"/>
> > 		<map:select type="parameter">
> > 		  <map:parameter name="parameter-selector-test" 
> > value="{admin}"/>
> > 		 <map:when test="true">
> > 		  <map:transform type="xslt" 
> > src="stylesheets/deliveries.xsl"/>
> > 		</map:when>
> > 		<map:otherwise>
> > 		<map:transform type="xslt" 
> > src="stylesheets/deliveries-readonly.xsl"/>
> > 		</map:otherwise>
> > 	       </map:select>
> > 	      <map:serialize type="html"/>
> >             </map:act>
> > 	</map:match>
> >       </map:act>
> > </map:match>
> > 
> > 
> > --------------------------------------------------------------
> > ------------
> > 
> > 
> 

-- 
 


Mime
View raw message