cancel
Showing results for 
Search instead for 
Did you mean: 

Chnaging the user authentication to NONE for wcmweb scripts

ruchi3
Champ in-the-making
Champ in-the-making
Hi! All

The requirement is that I want to access alfresco's wcm content stored in avm repository using web scripts. I am able to do it using following code
public class RandomSelectWebScript extends AbstractRepositoryWebScript
{
    public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException
    {
       try{
       // get the referenced incoming node
       NodeRef rootNodeRef = new NodeRef("avm://crweb–creator/-1;www;avm_webapps;ROOT;cms;83;NL");
       System.out.println("rootNodeRef:::"+rootNodeRef);
       // draw a random child
       NodeRef childNodeRef = randomChild(rootNodeRef);
       System.out.println("childNodeRef:::"+childNodeRef);
       // stream child back
       output(res, childNodeRef);
       }
       catch(Exception e){
          e.printStackTrace();
         
       }
    }
   
    protected NodeRef randomChild(NodeRef rootNodeRef)
    {
        // count the number of children
       NodeRef nodeRef  = null;
       try{
       System.out.println("call randomChild:::"+rootNodeRef);
        List<FileInfo> files = this.services.getFileFolderService().listFiles(rootNodeRef);
        int fileCount = files.size();
        System.out.println("call fileCount:::"+fileCount);
        // draw random number
        int draw = (int) ((double)Math.random() * (double)fileCount);
        System.out.println("call draw:::"+draw);
        // our draw
        FileInfo fileInfo = (FileInfo) files.get(draw);
        System.out.println("call fileInfo:::"+fileInfo);
       nodeRef = fileInfo.getNodeRef();
        System.out.println("call nodeRef:::"+nodeRef);
       
       }
       catch(Exception e){
          e.printStackTrace();
         
       }
      
       return nodeRef;
    }   
   

   

    protected void output(WebScriptResponse res, NodeRef nodeRef)
    {
      
       System.out.println("call output:::"+nodeRef);
       ContentReader reader = this.services.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
       
        // stream back
        try
        {
            reader.getContent(res.getOutputStream());
            System.out.println("call output:::"+ res.getOutputStream());
        }
        catch (Exception e)
        {
           throw new WebScriptException("Unable to stream output");
        }      
    }


}
The description xml is:
<webscript>
  <shortname>Streams a random content item</shortname>
  <description>Streams a random content item</description>
  <url>/cms/ejustice/europa/wcmcontent/random?taxid={taxid}&amp;msid={msid}&amp;langid={langid}</url>
  <authentication>user</authentication>
  <format default="">argument</format>
</webscript>
and the mapping file *context.xml is
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

   
    <bean id="webscript.com.cms.ejustice.europa.wcmcontent.random.get"
      class="com.ejustice.scripts.RandomSelectWebScript"
      parent="webscript">
  
   <property name="serviceRegistry" ref="ServiceRegistry" />
</bean>
   
</beans>
Now the requirement is that I want to access this content using REST based approach in web script, providing parmeters to search the content the way it is given in this path : cms, then 83, etc –>avm://crweb–creator/-1;www;avm_webapps;ROOT;cms;83;NL. Now the problem is I want to make the user authentication for this webscript as NONE or GUEST, so that it can be even accessed by my guest users, without requiring any authentication. If I make it NONE in my description file, it doesnt allow to read the content in the AVM Node. How can I achieve it? Please help. Looking forward for your reply.
Thanks in advance.
Ruchi
9 REPLIES 9

rogier_oudshoor
Champ in-the-making
Champ in-the-making
You should set authentication to Guest, and then give the Guest user minimal access on your web project. The default Alfresco authenticator will, if access is set to guest and the user isn't authenticated, run the webscript under the Guest user. Since Guest is then able to read your website (you've given him minimal access), the webscript should work.

ruchi3
Champ in-the-making
Champ in-the-making
Thanks a lot. I will try it.

ruchi3
Champ in-the-making
Champ in-the-making
Hi! All

NO SUCCESS. When I changed the authentication odf my webscript to guest as shown here:
<webscript>
  <shortname>Streams a random content item</shortname>
  <description>Streams a random content item</description>
  <url>/cms/ejustice/europa/wcmcontent/random?taxid={taxid}&amp;msid={msid}&amp;langid={langid}</url>
  <authentication>GUEST</authentication>
  <format default="">argument</format>
</webscript>
I get the following exception in my browser
Broken Web Scripts 
Failed to parse web script description document com/cms/ejustice/europa/wcmcontent/random.get.desc.xml ; Authentication 'GUEST' is not a valid value (classpath:alfresco/extension/templates/webscripts/com/cms/ejustice/europa/wcmcontent/random.get.desc.xml)
Infact I have invited Guest user role as reviewer on my web project where my content resides. Please Help!!!! Urgent

mikeh
Star Contributor
Star Contributor
"guest" should be lowercase.

Mike

ruchi3
Champ in-the-making
Champ in-the-making
Hi! All

Now though I have made authentication as guest as shown
<webscript>
  <shortname>Streams a random content item</shortname>
  <description>Streams a random content item</description>
  <url>/cms/ejustice/europa/wcmcontent/random?taxid={taxid}&amp;msid={msid}&amp;langid={langid}</url>
  <authentication>guest</authentication>
  <format default="">argument</format>
</webscript>
and invited guest user on the web project as a contributor (the web project has been created by a user 'testuser' who has invited guest on to his web project as content contributor, but still when I call the web script through url in IE using
http://localhost:8080/alfresco/service/cms/ejustice/europa/wcmcontent/random?taxid=83&msid=NL&langid...
, I still get the authentication window, [img]C:\Documents%20and%20Settings\vermaR\My%20Documents\My%20Pictures\webscriptAuth.JPG[/img]though the authentication level is set to guest, even if I give guest as username and password it gives me following access denied error.
org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied.  You do not have the appropriate permissions to perform this operation.
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
11:47:43,845 ERROR [STDERR]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:275)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
11:47:43,845 ERROR [STDERR]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
11:47:43,845 ERROR [STDERR]    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
11:47:43,845 ERROR [STDERR]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
11:47:43,845 ERROR [STDERR]    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
11:47:43,845 ERROR [STDERR]    at $Proxy90.getReader(Unknown Source)
11:47:43,845 ERROR [STDERR]    at com.ejustice.scripts.RandomSelectWebScript.output(RandomSelectWebScript.java:79)
11:47:43,845 ERROR [STDERR]    at com.ejustice.scripts.RandomSelectWebScript.execute(RandomSelectWebScript.java:37)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:328)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:322)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:229)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:377)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:399)
11:47:43,845 ERROR [STDERR]    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:282)
11:47:43,845 ERROR [STDERR]    at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:294)
11:47:43,845 ERROR [STDERR]    at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:172)
11:47:43,845 ERROR [STDERR]    at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122)
11:47:43,845 ERROR [STDERR]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
11:47:43,845 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
11:47:43,845 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
11:47:43,845 ERROR [STDERR]    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
11:47:43,845 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
11:47:43,845 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
11:47:43,845 ERROR [STDERR]    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
11:47:43,845 ERROR [STDERR]    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
11:47:43,855 ERROR [STDERR]    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
11:47:43,855 ERROR [STDERR]    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
11:47:43,855 ERROR [STDERR]    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
11:47:43,855 ERROR [STDERR]    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
11:47:43,855 ERROR [STDERR]    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
11:47:43,855 ERROR [STDERR]    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
11:47:43,855 ERROR [STDERR]    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
11:47:43,855 ERROR [STDERR]    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
11:47:43,855 ERROR [STDERR]    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
11:47:43,855 ERROR [STDERR]    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
11:47:43,855 ERROR [STDERR]    at java.lang.Thread.run(Unknown Source)
11:47:43,855 ERROR [STDERR] Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
11:47:43,855 ERROR [STDERR]    at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
11:47:43,855 ERROR [STDERR]    at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
11:47:43,855 ERROR [STDERR]    at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
11:47:43,855 ERROR [STDERR]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
11:47:43,855 ERROR [STDERR]    at org.alfresco.repo.model.ml.MLContentInterceptor.invoke(MLContentInterceptor.java:91)
11:47:43,855 ERROR [STDERR]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
11:47:43,855 ERROR [STDERR]    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
11:47:43,855 ERROR [STDERR]    … 38 more

mderting
Champ in-the-making
Champ in-the-making
You might want to try passing guest=true within your query string. For example:
http://localhost:8080/alfresco/service/cms/ejustice/europa/wcmcontent/random?taxid=83&msid=NL&langid...

mrogers
Star Contributor
Star Contributor
You may also want to deploy your content into a another store which is open to everyone to read.

guests should not be looking at your authoring environment.

mrogers
Star Contributor
Star Contributor
The other thing you can do in your web script is to use "run as".

Run as "system user" will read anything.    Or you could set up a proxy account.

ruchi3
Champ in-the-making
Champ in-the-making
Hi! I have tried making gues=true in my url as u stated in your post but still unable to do so. Please if you can provide any code snippet showing the usage of run as user (system user), then it it will be of great help.

Thanks in advance