AnsweredAssumed Answered

setting READ permission on folder within user's home folder

Question asked by awkhan on Apr 27, 2008
Latest reply on Apr 27, 2008 by awkhan
hi,

i am writing a application on top of alresco using alfresco java api.

the application creates user using PersonService.createPerson() and also creates one folder "company" in users home directory.

since the "company" folder is within users home folder user has full permission on it. i have a requirement whereby user should have only READ access on the folder.

is it possible to achive the same ?

following is the code snippet that i m using


final ServiceRegistry serviceRegistry = (ServiceRegistry)this.getServletConfig().getServletContext().getAttribute("SERVICE");
String fname = request.getParameter("FirstName");
String lname = request.getParameter("LastName");
String passw = request.getParameter("Password");


Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_FIRSTNAME, fname);
contentProps.put(ContentModel.PROP_LASTNAME, lname);
contentProps.put(ContentModel.PROP_USERNAME, "testuser");
contentProps.put(ContentModel.PROP_PASSWORD, passw);


NodeRef homeSpaceRef = null;
UserTransaction utx = null;
try{
//login as admin and create user and his folders
Authentication.login(serviceRegistry, "admin", "admin");
TransactionService transactionService = serviceRegistry.getTransactionService();
utx = transactionService.getUserTransaction();
utx.begin();
NodeRef personNode = serviceRegistry.getPersonService().createPerson(contentProps);

// ensure the user can access their own Person object
serviceRegistry.getPermissionService().setPermission(personNode, "testuser", serviceRegistry.getPermissionService().getAllPermission(), true);

// create the ACEGI Authentication instance for the new user
serviceRegistry.getAuthenticationService().createAuthentication("testuser", passw.toCharArray());

homeSpaceRef = (NodeRef) serviceRegistry.getNodeService().getProperty(personNode, ContentModel.PROP_HOMEFOLDER);

String folder = "COMPANY";


contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, folder);

// create folder node
NodeService nodeService = serviceRegistry.getNodeService();
ChildAssociationRef association = nodeService.createNode(homeSpaceRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, folder),
ContentModel.TYPE_FOLDER,
contentProps);

//===========================this is though not working===================================================
//giving READ only permission to testuser on folder company
serviceRegistry.getPermissionService().setPermission(association.getChildRef(), "testuser", serviceRegistry.getPermissionService().READ_PERMISSIONS, true);

utx.commit();

}catch(Exception e){

try {
utx.rollback();
} catch (Exception ex2) {

System.out.print(e.toString());

}

System.out.print(e.toString());
}

Outcomes