Updating a policy using the Java API

To update a policy by using the Java API, perform the following steps:

  1. Set up your development environment and include all of the JAR files mentioned in Setting up the development environment within your project.

  2. Create a Policy instance and read in the policy from a file or database.

    Policy policy = new Policy(policyBytes);
  3. Update the Policy object by setting its properties, such as its name and usage rules.

      // Change the policy name.
      // Add DRM module restrictions to the play right
      for (Right r: policy.getRights()) {
       if (r instanceof PlayRight) {
        PlayRight pr = (PlayRight) r;
        // Disallow Linux versions up to and including 1.9.  Allow
        // all other OSes and Linux versions above 1.9
        VersionInfo toExclude = new VersionInfo();
        Collection<VersionInfo> exclusions = new ArrayList<VersionInfo>();
        ModuleRequirements drmRestrictions = new ModuleRequirements();
  4. Serialize the updated Policy object and store it in a file or database.

       // Serialize the policy.
       byte[] policyBytes = policy.getBytes();
       System.out.println("New policy revision number: "
        +  policy.getRevision());
       // Write the policy to a file.
       // Alternatively, the policy may be stored in a database.
       FileOutputStream out = new FileOutputStream("demopolicy-updated.pol");

For the full source of this sample code, see com.adobe.flashaccess.samples.policy.UpdatePolicy in the Reference Implementation Command Line Tools “samples” directory.

On this page