Expand my Community achievements bar.

tutorial on connecting users to policies

Avatar

Level 1

hi all

are there any existing tutorials that show how to connect users, or a list of users to a policy?

for example, if i have an existing policy that is applied to certain documents. how do i add users to that policy through SDK.

1 Reply

Avatar

Level 5

That's exactly what I'm trying to achieve.

Basically  you'll do like this:

//----data fake---
String myPolicyId = new String("B1501606-3803-102D-B9BE-00000A00A096");
List myUserId = new ArrayList();

myUserId.add("318A570D-348B-102D-A98C-00000A00A096");
myUserId.add("3249F171-348B-102D-8DAD-00000A00A096");
//----end data fake----

Properties connectionProps = new Properties();               
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "http://10.0.160.150:9080");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE,"WebSphere");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME,"administrator");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD,"password");

// Create a ServiceClientFactory object
ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);

// Create a RightsManagementClient object
RightsManagementClient rightsClient = new RightsManagementClient(myFactory);               

// Create a policy manager instance
PolicyManager policyManager = rightsClient.getPolicyManager();
// Create an DirectoryManagerServiceClient object
DirectoryManagerServiceClient dirClient = new DirectoryManagerServiceClient(myFactory);               

Policy myPolicy = policyManager.getPolicy(myPolicyId);

System.out.println(myPolicy.getName() + "\n****");
System.out.println(myPolicy.getDescription());


for( int i = 0; i < myUserId.size(); i++ )
{
     PolicyEntry myEntry = InfomodelObjectFactory.createPolicyEntry();
     
     System.out.println(myUserId.get(i));
     Principal usuario = dirClient.findPrincipal((String) myUserId.get(i));     
     
     myEntry.setPrincipal(usuario);

     // Specify the permissions
     Permission copyPermission = InfomodelObjectFactory.createPermission(Permission.PRINT_HIGH);

     // Add permissions to the policy entry
     myEntry.addPermission(copyPermission);
     
     // add the new Entry to the Policy
     myPolicy.addPolicyEntry(myEntry);                    
}
policyManager.updatePolicy(myPolicy);

Please tell us when you get there.

Diego