You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Simon Hutchinson <si...@misgl.com> on 2003/12/11 23:21:05 UTC

Authentication context and modular database action.

Hi,

I am using a ModularDatabaseAction to insert a row into a database.
Everything is working fine as most of the field values are available
as request parameters.However I also need to store a value that is
stored in the authentication context.
I am sure that writing my own InputModule for this is overkill as the
information is available already.

Either of the following types of solution would be cool if anyone could
point me in the right direction.(of course I am completely open to a 
better solution :))

1). Is it possible to access the authentication context using the 
session-context InputModule in the database descriptor ?

ie

<value name="fieldname"  type="int">
	<mode name="session-context">                					 
<parameter>authentication/authentication/ID</parameter>
          </mode>
</value>


note: I tried this and it didn't work.The IDs value is available in the 
sitemap using the same input module

ie

{session-context:authentication/authentication/ID}

So maybe I am writing the <mode> incorrectly ?


2). Is it possible to pass values as parameters to the action directly 
from sitemap.

ie

<map:act type="mod-db-add">
   <map:parameter name="table-set" value="mySet"/> 

   <map:parameter name="myparam" 
value="{session-context:authentication/authentication/ID}"/>
</map:act>


If the answer is yes than a code snippet showing how to access the 
parameter from within the database descriptor would be great.

Any assistance to a new cocoon user would be wonderful.

Thanks

Si


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Authentication context and modular database action.

Posted by Simon Hutchinson <si...@misgl.com>.
hed wrote:
>>I am using a ModularDatabaseAction to insert a row into a database.
>>Everything is working fine as most of the field values are available
>>as request parameters.However I also need to store a value that is
>>stored in the authentication context.
>>I am sure that writing my own InputModule for this is overkill as the
>>information is available already.
>>
> 
> 
> I've had the same problem a couple days ago.
> I think that I've found a bug in this module - it doesn't use a parameter
> name correctly.
> So I've write my own - and now everything's ok.
> simply, I've redefined getAttribute method:
> 
> public Object getAttribute(String name,
> Configuration modeConf,
> Map objectModel)
> throws ConfigurationException {
> if ( name == null ) {
> return null;
> }
> if ( modeConf != null ) {
> name = modeConf.getAttribute( "parameter", name );
> // preferred
> name = modeConf.getChild("parameter").getValue(name);
> }
> return super.getAttribute(name,modeConf,objectModel);
> }
> 
> 
>>1). Is it possible to access the authentication context using the
>>session-context InputModule in the database descriptor ?
>>
>>ie
>>
>><value name="fieldname"  type="int">
>><mode name="session-context">
>><parameter>authentication/authentication/ID</parameter>
>>          </mode>
>></value>
>>
>>
>>note: I tried this and it didn't work.The IDs value is available in the
>>sitemap using the same input module
> 
> 
> it is correct, theoretically (but doesn't work cause of the bug)
> 
> regards
> hed
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 

Hi hed,

Thanks for your time and assistance.
I actually resolved the issue by another means, which I am posting in 
case it is useful to anyone else.

I failed to mention that I am using ModularDatabaseAction to save values
from a woody form controlled via flow.
My approach is based on sample.js in the authentication block


########################################################################

//First I get the AuthenticationManager

var authMgr = 
cocoon.getComponent(Packages.org.apache.cocoon.webapps.authentication.AuthenticationManager.ROLE);

//Next I get the name of the handler which I passed as a parameter in 
//the sitemap ie <map:parameter name="handler" value="myHandler"/>

var handler = cocoon.parameters["handler"];

//The user in my case has to be authenticated so I get the UserHandler 
//by calling the isAuthenticated() method on the AuthenticationManager

var userHandler =  authMgr.isAuthenticated(handler);

//From the user handler I can then access authentication data as
//follows.

if(userHandler!=null) {
    var ID =userHandler.getContext().getContextInfo().get("ID");
    cocoon.request.setAttribute("ID",ID);
    cocoon.sendPage("success-pipeline");
}



########################################################################

I can then use the request-attr InputModule in my database descriptor.

I know that it's a hack but thought that the information might be useful
anyway.


Thanks again for your help

Si









---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Authentication context and modular database action.

Posted by hed <he...@interia.pl>.
> I am using a ModularDatabaseAction to insert a row into a database.
> Everything is working fine as most of the field values are available
> as request parameters.However I also need to store a value that is
> stored in the authentication context.
> I am sure that writing my own InputModule for this is overkill as the
> information is available already.
>

I've had the same problem a couple days ago.
I think that I've found a bug in this module - it doesn't use a parameter
name correctly.
So I've write my own - and now everything's ok.
simply, I've redefined getAttribute method:

public Object getAttribute(String name,
Configuration modeConf,
Map objectModel)
throws ConfigurationException {
if ( name == null ) {
return null;
}
if ( modeConf != null ) {
name = modeConf.getAttribute( "parameter", name );
// preferred
name = modeConf.getChild("parameter").getValue(name);
}
return super.getAttribute(name,modeConf,objectModel);
}

>
> 1). Is it possible to access the authentication context using the
> session-context InputModule in the database descriptor ?
>
> ie
>
> <value name="fieldname"  type="int">
> <mode name="session-context">
> <parameter>authentication/authentication/ID</parameter>
>           </mode>
> </value>
>
>
> note: I tried this and it didn't work.The IDs value is available in the
> sitemap using the same input module

it is correct, theoretically (but doesn't work cause of the bug)

regards
hed




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Authentication context and modular database action.

Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
Simon Hutchinson wrote:
> Hi,
> 
> I am using a ModularDatabaseAction to insert a row into a database.
> Everything is working fine as most of the field values are available
> as request parameters.However I also need to store a value that is
> stored in the authentication context.
> I am sure that writing my own InputModule for this is overkill as the
> information is available already.
> 
> Either of the following types of solution would be cool if anyone could
> point me in the right direction.(of course I am completely open to a 
> better solution :))
> 
> 1). Is it possible to access the authentication context using the 
> session-context InputModule in the database descriptor ?
> 
> ie
> 
> <value name="fieldname"  type="int">
>     <mode name="session-context">                                     
> <parameter>authentication/authentication/ID</parameter>
>          </mode>
> </value>

you need to tell the action when to use this mode with the type
attribute. For example, you might want to use it only on updates from a
specific form. This corrolates to the others-mode attribute for tables
in tablesets.

Since you most likely will use this mode for every operation, you need
to add type="all" to the mode:

  <mode name="session-context" type="all">
   <parameter>authentication/authentication/ID</parameter>
  </mode>

> 2). Is it possible to pass values as parameters to the action directly 
> from sitemap.

No, because input modules don't have access to parameters passed to the
action.

	Chris.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org