Class PolicyUtils

java.lang.Object
org.opencastproject.urlsigning.utils.PolicyUtils

public final class PolicyUtils extends Object
A Utility class to encode / decode Policy files from and to Base 64 and Json.
  • Method Details

    • base64Encode

      public static String base64Encode(String value)
      Encode a String into Base 64 encoding
      Parameters:
      value - The String to encode into base 64 encoding
      Returns:
      The String encoded into base 64.
    • base64Decode

      public static String base64Decode(String value)
      Decode a String from Base 64 encoding
      Parameters:
      value - The String to encode into Base 64
      Returns:
      The String decoded from base 64.
    • fromJson

      public static Policy fromJson(String policyJson)
      Get a Policy from JSON data.
      Parameters:
      policyJson - The String representation of the json.
      Returns:
      A new Policy object populated from the JSON.
    • toJson

      public static org.json.simple.JSONObject toJson(Policy policy)
      Render a Policy into JSON.
      Parameters:
      policy - The Policy to render into JSON.
      Returns:
      The JSONObject representation of the Policy.
    • fromBase64EncodedPolicy

      public static Policy fromBase64EncodedPolicy(String encodedPolicy)
      Create a Policy in Json format and Base 64 encoded.
      Parameters:
      encodedPolicy - The String representation of the Policy in Json format and encoded into Base 64
      Returns:
      The Policy data
    • toBase64EncodedPolicy

      public static String toBase64EncodedPolicy(Policy policy)
      Create a Policy in Json format and Base 64 encoded.
      Parameters:
      policy - The String representation of the Policy in Json format and encoded into Base 64
      Returns:
      The Policy data
    • getPolicySignature

      public static String getPolicySignature(Policy policy, String encryptionKey) throws Exception
      Get an encrypted version of a Policy to use as a signature.
      Parameters:
      policy - Policy that needs to be encrypted.
      encryptionKey - The key to use to encrypt the Policy.
      Returns:
      An encrypted version of the Policy that is also Base64 encoded to make it safe to transmit as a query parameter.
      Throws:
      Exception - Thrown if there is a problem encrypting or encoding the Policy