cancel
Showing results for 
Search instead for 
Did you mean: 

Change Folder Permissions -& How to initialise IResource Object

Former Member
0 Kudos

Hi All,

I Was just trying to programatically change the permission of a folder ['/documents/Aditya'].

The folder name is 'Aditya' located in /documents.

[E.g. /documents/Aditya]

I was thinking of doing the above by creating a Portal Component & deploying a par file of it & create a iview of it.

In the below code i was not able to figure out, how to intialize the IResource object, Please help:

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

//here i am not quite clear how to initialize this resource object

IResource resource;

String root = "/documents/Aditya";

try{

String rid = RID rid = RID.getRID(root);

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){

LOCATION.errorT("I raised an AclPersistenceException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(ResourceException e){

LOCATION.errorT("I raised a ResourceException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(NotAuthorizedException e){

LOCATION.errorT("I raised a NotAuthorizedException @"(new Date()).toString()": " +e.getMessage() + "**" + LoggingFormatter.extractCallstack(e));

}catch(AclExistsException e){

LOCATION.errorT("I raised an AclExistsException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(UserManagementException e){

LOCATION.errorT("I raised a UserManagementException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(InvalidClassException e){

LOCATION.errorT("I raised an InvalidClassException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(AlreadyAssignedToAclException e){

LOCATION.errorT("I raised an AlreadyAssignedToAclException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(PermissionNotSupportedException e){

LOCATION.errorT("I raised a PermissionNotSupportedException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}

}

}

Accepted Solutions (1)

Accepted Solutions (1)

alexander_link
Explorer
0 Kudos

Hi,

something like...


IUser user = portalComponentRequest.getUser();
IResourceContext resourceContext = ResourceContext.getInstance(user);
IResource resource = ResourceFactory.getInstance().getResource(rid, resourceContext);

...should help.

Regards, Alex

Former Member
0 Kudos

First of all, thankx Alexander it really worked.

Below is the working code:

package com.permissions1;

import com.sapportals.portal.prt.component.*;

import java.util.Collection;

import java.util.Iterator;

//import com.sap.tc.logging.Location;

import com.sapportals.wcm.util.logging.LoggingFormatter;

import java.util.Date;

import com.sapportals.portal.security.usermanagement.IGroup;

import com.sapportals.portal.security.usermanagement.IUMPrincipal;

import com.sapportals.portal.security.usermanagement.UserManagementException;

import com.sapportals.wcm.WcmException;

import com.sapportals.wcm.crt.component.IReconfigurable;

import com.sapportals.wcm.crt.component.StartupException;

import com.sapportals.wcm.crt.configuration.ConfigurationException;

import com.sapportals.wcm.crt.configuration.IConfiguration;

import com.sapportals.wcm.repository.IResource;

import com.sapportals.wcm.repository.ResourceException;

import com.sapportals.wcm.repository.manager.IAclSecurityManager;

import com.sapportals.wcm.repository.manager.IRepositoryManager;

import com.sapportals.wcm.repository.manager.IResourceEventReceiver;

import com.sapportals.wcm.repository.manager.ISecurityManager;

import com.sapportals.wcm.repository.manager.ResourceEvent;

import com.sapportals.wcm.repository.security.IResourceAcl;

import com.sapportals.wcm.repository.security.IResourceAclEntryList;

import com.sapportals.wcm.repository.security.IResourceAclEntryListIterator;

import com.sapportals.wcm.repository.security.IResourceAclManager;

import com.sapportals.wcm.repository.service.AbstractRepositoryService;

import com.sapportals.wcm.repository.service.ServiceNotAvailableException;

import com.sapportals.wcm.util.acl.AclExistsException;

import com.sapportals.wcm.util.acl.AclPersistenceException;

import com.sapportals.wcm.util.acl.AlreadyAssignedToAclException;

import com.sapportals.wcm.util.acl.IAclPermission;

import com.sapportals.wcm.util.acl.InvalidClassException;

import com.sapportals.wcm.util.acl.NotAuthorizedException;

import com.sapportals.wcm.util.acl.PermissionNotSupportedException;

import com.sapportals.wcm.util.events.IEvent;

import com.sapportals.wcm.util.usermanagement.WPUMFactory;

import com.sapportals.wcm.util.acl.*;

import com.sapportals.wcm.repository.ICollection;

import com.sapportals.wcm.repository.IResourceContext;

import com.sapportals.wcm.util.uri.RID;

import com.sapportals.wcm.repository.ResourceFactory;

import com.sapportals.wcm.repository.security.IResourceAclEntry;

import com.sapportals.portal.security.usermanagement.IGroup;

import com.sapportals.wcm.util.logging.LoggingFormatter;

import com.sapportals.wcm.util.acl.AclPersistenceException;

import com.sapportals.wcm.repository.IResourceFactory;

import com.sapportals.wcm.util.content.IContent;

import com.sapportals.wcm.repository.ResourceContext;

import com.sapportals.portal.security.usermanagement.IUser;

//import com.sap.engine.interfaces.security.*;

public class KMPermission extends AbstractPortalComponent

{

private IUser loggedOnUser;

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

{

try{

this.loggedOnUser = (IUser) request.getUser().getUser();

ICollection aCollection = null;

ICollection parent= null;

com.sapportals.wcm.repository.IResource aResource = null;

ResourceContext rContext = null;

// create a resource context with the authenticated user

rContext = new ResourceContext(loggedOnUser);

RID aRid = RID.getRID("/documents/aditya");

response.write("RID:::::::::::::"+aRid);

// get an instance of a resource factory

IResourceFactory aResourceFactory = ResourceFactory.getInstance();

IResource resource = aResourceFactory.getResource(aRid,rContext);

response.write(":::::::::::::got resource ");

IContent content = resource.getContent();

response.write(":::::::::::::got content ");

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

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

IAclSecurityManager asm = (IAclSecurityManager)sm;

IResourceAclManager ram = asm.getAclManager();

ram.removeAcl(resource);

response.write(":::::::::::::creating acl ");

IResourceAcl ra = ram.createAcl(resource);

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

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

IUMPrincipal user = WPUMFactory.getUserFactory().getUser("aditya");

IResourceAclEntryList rel = ra.getEntries();

IResourceAclEntryListIterator it = rel.iterator();

response.write(":::::::::::::removing entries ");

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));

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

response.write("permission assigned");

}

}catch(AclPersistenceException e){

response.write("I raised an AclPersistenceException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(ResourceException e){

response.write("I raised a ResourceException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(NotAuthorizedException e){

response.write("I raised a NotAuthorizedException @"(new Date()).toString()": " +e.getMessage() + "**" + LoggingFormatter.extractCallstack(e));

}catch(AclExistsException e){

response.write("I raised an AclExistsException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(UserManagementException e){

response.write("I raised a UserManagementException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(InvalidClassException e){

response.write("I raised an InvalidClassException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(AlreadyAssignedToAclException e){

response.write("I raised an AlreadyAssignedToAclException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}catch(PermissionNotSupportedException e){

response.write("I raised a PermissionNotSupportedException @"(new Date()).toString()": " + LoggingFormatter.extractCallstack(e));

}

}

}

Answers (0)