AnsweredAssumed Answered

Chnaging the user authentication to NONE  for wcmweb scripts

Question asked by ruchi3 on Sep 1, 2009
Latest reply on Sep 23, 2009 by ruchi3
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

Outcomes