AnsweredAssumed Answered

Security errors while versioning!

Question asked by amit_wmw@yahoo.com on Oct 30, 2008
Latest reply on Mar 27, 2017 by martijn
Hi,

I am trying to do versioning after uploading file but during checkin itself I am getting security related error  :cry:  Does anybody have any idea to resolve this out. If, please share.

##############################################################################
My Program
—————-
package org.alfresco.sample;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
//import javax.jcr.version.Version;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.*;

import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.alfresco.repo.version.VersionModel;
import org.alfresco.repo.version.VersionServiceImpl;
import org.alfresco.repo.coci.CheckOutCheckInServiceImpl;



public class FirstJCRClient
{

public static void main(String[] args)
{

try{

// access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");

Repository repository = (Repository)context.getBean("JCR.Repository");

// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

try{

ServiceRegistry serviceRegistry = (ServiceRegistry) context.getBean("ServiceRegistry");

// Get root node for default store: SpacesStore
NodeRef rootNodeRef = serviceRegistry.getNodeService().getRootNode(new StoreRef("workspace://SpacesStore"));

// Find children of root node with association name "app:company_home" (must be one)
List<NodeRef> nodes = (List<NodeRef>) serviceRegistry.getSearchService().selectNodes(rootNodeRef, "app:company_home", null,serviceRegistry.getNamespaceService(), false);

if (nodes.size() == 0) {

throw new AlfrescoRuntimeException("Unable to find store path: app:company_home");
}

NodeRef companyHome = nodes.get(0);

String A="C:/Test/Amitkumar.pdf";

File file=new File(A);

FileFolderService fileFolderService = (FileFolderService) context.getBean("fileFolderService");

FileInfo fileinfo = fileFolderService.create(companyHome, file.getName(), ContentModel.TYPE_CONTENT);

String s= fileinfo.getName();

NodeRef fileRef = fileinfo.getNodeRef();

FileInputStream contentStream=new FileInputStream(file);

ContentService contentService = (ContentService) context.getBean("contentService");

ContentWriter writer = contentService.getWriter(fileRef, ContentModel.PROP_CONTENT, true);

writer.putContent(contentStream);
session.save();
// Amit content versioning
System.out.println("Versioning-1");
VersionService VS= (VersionService) context.getBean("VersionService");
System.out.println("Versioning-2");
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
System.out.println("Versioning-3");
versionProperties.put(Version.PROP_DESCRIPTION, "checkin made by test program");
System.out.println("Versioning-4");
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
System.out.println("Versioning-5");
VS.createVersion(fileRef,versionProperties);
System.out.println("Versioning-6");
//NodeService nodeService = serviceRegistry.getNodeService();
CheckOutCheckInService checkOutCheckInService= serviceRegistry.getCheckOutCheckInService();
checkOutCheckInService.checkin(fileRef, versionProperties);
System.out.println("Versioning-7");
//Amit content versioning



System.out.println("Inside tcheckin-9");
}

catch (Exception exp ){
System.out.println (" error while creating nodes " + exp);
exp.printStackTrace();
}

finally
{
session.logout();
System.exit(0);
System.out.println("Inside tcheckin-10");
}

}
catch (Exception exp ){
System.out.println (" Caught exception " + exp);
exp.printStackTrace();
}
}
}
###############################################33
Error while executing
————————-
18:42:45,397 WARN [remoting.rmi.RmiRegistryFactoryBean] Could not detect RMI registry - creating new one
18:42:48,147 WARN [alfresco.util.OpenOfficeConnectionTester] A connection to OpenOffice could not be established.
18:42:51,553 INFO [domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.
18:42:53,209 INFO [domain.schema.SchemaBootstrap] No changes were made to the schema.
18:42:55,334 INFO [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: C:\Alfresco\alf_data
18:42:55,803 INFO [admin.patch.PatchExecuter] Checking for patches to apply …
18:42:56,006 INFO [repo.module.ModuleServiceImpl] Found 0 module(s).
18:42:56,147 ERROR [alfresco.smb.protocol] Error accessing Win32 NetBIOS, check DLL is on the path
18:42:56,162 INFO [service.descriptor.DescriptorService] Alfresco JVM - v1.5.0_16-b02; maximum heap size 63.563MB
18:42:56,162 WARN [service.descriptor.DescriptorService] Alfresco JVM - WARNING - maximum heap size 63.563MB is less than recommended 512MB
18:42:56,162 INFO [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 2.1.0 (482) schema 64 - Installed version 2.1.0 (482) schema 64
Versioning-1
Versioning-2
Versioning-3
Versioning-4
Versioning-5
Versioning-6
error while creating nodes org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied. You do not have the appropriate permissions to perform this operation.
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 $Proxy88.checkin(Unknown Source)
at org.alfresco.sample.FirstJCRClient.main(FirstJCRClient.java:105)
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
… 10 more
##############################################################33

Thanks
Amit.

Outcomes