/** * Create a {@link Policy} in Json format and Base 64 encoded. * * @param policy * The String representation of the {@link Policy} in Json format and encoded into Base 64 * @return The {@link Policy} data */ public static String toBase64EncodedPolicy(Policy policy) { return base64Encode(PolicyUtils.toJson(policy).toJSONString()); }
/** * Get an encrypted version of a {@link Policy} to use as a signature. * * @param policy * {@link Policy} that needs to be encrypted. * @param encryptionKey * The key to use to encrypt the {@link Policy}. * @return An encrypted version of the {@link 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 {@link Policy} */ public static String getPolicySignature(Policy policy, String encryptionKey) throws Exception { return SHA256Util.digest(PolicyUtils.toJson(policy).toJSONString(), encryptionKey); } }
.setRejectionReason(String .format("Forbidden because policy and signature do not match. Policy: '%s' created Signature from this policy '%s' and query string Signature: '%s'.", PolicyUtils.toJson(resourceRequest.getPolicy()).toJSONString(), policySignature, resourceRequest.getSignature())); } catch (Exception e) { .setRejectionReason(String .format("Forbidden because policy and signature do not match. Policy: '%s' and query string Signature: '%s'. Unable to sign policy because: %s", PolicyUtils.toJson(resourceRequest.getPolicy()).toJSONString(), resourceRequest.getSignature(), ExceptionUtils.getStackTrace(e)));