Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Policy update Java exception

Avatar

Former Community Member

I'm getting this exception when trying update a Policy.

                //Get ServiceClientFactory
          ServiceClientFactory myFactory = getServiceClientFactory();
               
          // Create an RightsManagementClient object
          RightsManagementClient rightsClient = new RightsManagementClient(myFactory);
          
          // Create an DirectoryManager object
          DirectoryManager dirManager = new DirectoryManagerServiceClient(myFactory);
               
          
          //Create a policy manager instance
             PolicyManager policyManager = rightsClient.getPolicyManager();
        
             //Retrieve an existing policy
             Policy myPolicy = policyManager.getPolicy(da.getProduct().getPolicySet(),da.getProduct().getPolicyName());
            
            
             //     Grab the Principal (aka User)
             Principal p = retrievePrincipal(da.getCustomer().getEmail(), dirManager);
            
            
             logger.info("Policy grabbed");
            
             List<PolicyEntryImpl> policyEntries = myPolicy.getPolicyEntries();
     
             for(PolicyEntryImpl pe : policyEntries){
                  
                  Principal pep = pe.getPrincipal();
                  if(p.getOid().equals(pep.getCanonicalName())){
                       myPolicy.removePolicyEntry(pe);
                       logger.info("Policy removed");
                  }
                  
                  
             }
            
            
             //Update the policy
             policyManager.updatePolicy(myPolicy);

0 Replies