Skip to Content
0
Former Member
Nov 09, 2005 at 08:36 AM

Changing permissions using a RepositoryService?

22 Views

Hi All

I have created a Repository Service using an example from posts in the forums and examples. Which I am trying to do is change the permissions of a text document when it is created in a folder in KM. However nothing is happening when the document is created and the permissions are just inherited from the parent folder.

I must be doing something wrong but I don know what. I have posted my code below and if any one can help me solve this that would be great!

CODE:

public void received(IEvent event) {

IResource resource = (IResource)event.getParameter();

try{

String rid = resource.getRID().toString();

if(rid.equals("/new_news/"+resource.getName())){

ISecurityManager sm = resource.getRepositoryManager().getSecurityManager(resource);

if(sm != null && sm instanceof IAclSecurityManager){

IAclSecurityManager asm = (IAclSecurityManager)sm;

IResourceAclManager ram = asm.getAclManager();

ram.removeAcl(resource);

IResourceAcl ra = ram.createAcl(resource);

IUMPrincipal everyone = WPUMFactory.getGroupFactory().getGroup("Everyone");

IUMPrincipal owner = WPUMFactory.getUserFactory().getUser(resource.getCreatedBy());

IResourceAclEntryList rel = ra.getEntries();

IResourceAclEntryListIterator it = rel.iterator();

while(it.hasNext()){

ra.removeEntry(it.next());

}

ra.addEntry(ram.createAclEntry(everyone, false, ram.getPermission(IAclPermission.ACL_PERMISSION_READ), 0));

ra.addEntry(ram.createAclEntry(owner, false, ram.getPermission(IAclPermission.ACL_PERMISSION_FULL_CONTROL), 2));

}

}

}catch(AclPersistenceException e){

e.printStackTrace();

}catch(ResourceException e){

e.printStackTrace();

}catch(NotAuthorizedException e){

e.printStackTrace();

}catch(AclExistsException e){

e.printStackTrace();

}catch(UserManagementException e){

e.printStackTrace();

}catch(InvalidClassException e){

e.printStackTrace();

}catch(AlreadyAssignedToAclException e){

e.printStackTrace();

}catch(PermissionNotSupportedException e){

e.printStackTrace();

}

}