AnsweredAssumed Answered

Authentication with TestWebScriptServer

Question asked by si_hutch on Jun 7, 2008
Hi,

I would like to use TestWebScriptServer to test my webscript but I am having a problem with authentication.

The config for my webscript requires an authenticated user


<webscript>
  <shortname>Create an item of feedback</shortname>
  <url>/test/api/feedbackitem</url>
  <format default="xml">argument</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>

If I test using the following


TestWebScriptServer server = TestWebScriptServer.getTestServer();         
MockHttpServletResponse res = server.submitRequest("put", "/test/api/feedbackitem");

I get, as I would expect, an authentication exception


Caught exception from web script.
net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:477)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:355)

I have tried authenticating in the same way that I would when testing an Action (see below)


authenticationService = (AuthenticationService)this.applicationContext.getBean("authenticationService");
authenticationService.authenticate("admin", "admin".toCharArray());

But this causes an exception


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workflowScheduler' defined in class path resource [alfresco/bootstrap-context.xml]: Cannot resolve reference to bean 'jbpm_template' while setting bean property 'JBPMTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration

Could you please tell me the way to test a webscript that requires authentication?

Best regards

Si

Outcomes