AnsweredAssumed Answered

Access Denied when creating content from a scheduled task

Question asked by mark.smithson on Aug 29, 2007
Latest reply on Aug 29, 2007 by mark.smithson
We have a scheduled task which imports news from an xml feed into a WCM sandbox.

This works fine on a windows Alfresco instance, but throws an Access Denied error when on our test server (linux).

org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy15.addAspect(Unknown Source)
   at com.dm.alfresco.AlfrescoContentCreatorImpl.saveToAlfresco(AlfrescoContentCreatorImpl.java:79)

The code used to create the content is as follows:

String path = AVMUtil.buildSandboxRootPath(sandbox) + "/ROOT/WEB-INF/resources/content/" + contentPath ;

      createFile(path, name, edit);
      
    String filePath = path + '/' + name;
    NodeRef fileNodeRef = AVMNodeConverter.ToNodeRef(-1, filePath);
   
    // apply the titled aspect - title and description
    Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
    titledProps.put(ContentModel.PROP_TITLE, name);
    titledProps.put(ContentModel.PROP_DESCRIPTION, "Imported from News Feed");
    this.nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, titledProps);
   
    // attach the form is supplied
    if (StringUtils.isNotEmpty(this.formName)){
       Map<QName, Serializable> formProps = new HashMap<QName, Serializable>(2, 1.0f);
       formProps.put(WCMAppModel.PROP_PARENT_FORM_NAME, this.formName);
       formProps.put(WCMAppModel.PROP_ORIGINAL_PARENT_PATH, path);
       this.nodeService.addAspect(fileNodeRef, WCMAppModel.ASPECT_FORM_INSTANCE_DATA, titledProps);
    }
   
    // get a writer for the content and put the file
    ContentWriter writer = this.contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setMimetype("text/xml");
    writer.setEncoding("UTF-8");
    writer.putContent(content);

createFile is as follows

private void createFile(String path, String name, boolean edit) {
      try {
         this.avmService.createFile(path, name);
      }
      catch (AVMExistsException e){
         if (!edit){
            createFile(path, randomise(name), edit);
         }
      }
   }

the calling code does a login using this code

this.authenticationService.authenticate(username, password.toCharArray());

The exception stacktrace originates from this line

this.nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, titledProps);

The user is configured as a content contributor on the web project and the sandbox we are importing to is the sandbox for the user.

Is there anything else we should be checking, or doing?

Outcomes