Stephanie

Sorry to not answer this question direct, and I am sure the 
Java gurus will help, but... why do you need this Action at
all, when you can use the SessionPropagatorAction to
store user info into the sitemap for access by any pipeline, or
use the session-context to retrieve user info for protected
pipelines ?

Derek

>>> [EMAIL PROTECTED] 2004/07/19 10:28:16 AM >>>
Hi all,

I get a NullPointerException in my GetRolesAction, hope somebody of you
guys
can help me.

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(AuthenticationConstants.SESSION_CONTEXT_NAME)){

                        sessionContext =
(AuthenticationContext)
contextProvider.getSessionContext(AuthenticationConstants.SESSION_CONTEXT_NAME);
                }               
                else{
                                        throw new
NullPointerException("Can't get sessionContext");
                }
                
                map = new HashMap(3);
                //check
roles
                if
(sessionContext.getSingleNode("authentication/rights/projects/[EMAIL 
PROTECTED]"+project+"]/admin")!=null)
                        map.put("admin","true");
                else
                        map.put("admin","false");
                
                if
(sessionContext.getSingleNode("authentication/rights/projects/[EMAIL 
PROTECTED]"+project+"]/developer")!=null)
                        map.put("developer","true");
                else
                        map.put("developer","false");
                        
                if
(sessionContext.getSingleNode("authentication/rights/projects/[EMAIL 
PROTECTED]"+project+"]/guest")!=null)
                        map.put("guest","true");
                else
                        map.put("guest","false");
                
                return
map;
        }

}
------------------------------------------------------------------------


java.lang.NullPointerException

        at
org.apache.cocoon.webapps.authentication.context.AuthenticationContextProvider.getSessionContext(AuthenticationContextProvider.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.AbstractParentProcessingNode.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>


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




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to