public function testCreateContentKeyAuthorizationPolicyOptionForPlayReady() { // Setup Token $template = new TokenRestrictionTemplate(TokenType::SWT); $template->setPrimaryVerificationKey(new SymmetricVerificationKey()); $template->setAlternateVerificationKeys(array(new SymmetricVerificationKey())); $template->setAudience('http://sampleaudience/'); $template->setIssuer('http://sampleissuerurl/'); $claims = array(); $claims[] = new TokenClaim(TokenClaim::CONTENT_KEY_ID_CLAIM_TYPE); $claims[] = new TokenClaim('Rental', 'true'); $template->setRequiredClaims($claims); $serializedTemplate = TokenRestrictionTemplateSerializer::serialize($template); // Setup Options $name = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_OPTIONS_NAME . $this->createSuffix(); $restrictionName = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_POLICY_RESTRICTION_NAME . $this->createSuffix(); $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName($restrictionName); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::TOKEN_RESTRICTED); $restriction->setRequirements($serializedTemplate); $restrictions = array($restriction); $options = new ContentKeyAuthorizationPolicyOption(); $options->setName($name); $options->setKeyDeliveryType(ContentKeyDeliveryType::PLAYREADY_LICENSE); $playReadytemplate = $this->getPlayReadyTemplate(); $deliveryConfiguration = MediaServicesLicenseTemplateSerializer::serialize($playReadytemplate); $options->setKeyDeliveryConfiguration($deliveryConfiguration); $options->setRestrictions($restrictions); // Test $result = $this->createContentKeyAuthorizationPolicyOption($options); // Retrieve the CKAPO again. $result = $this->restProxy->getContentKeyAuthorizationPolicyOption($result->getId()); // Assert Options $this->assertEquals($options->getName(), $result->getName()); $this->assertEquals($options->getKeyDeliveryType(), $result->getKeyDeliveryType()); $this->assertEquals($options->getRestrictions(), $result->getRestrictions()); $receivedTemplate = $result->getRestrictions()[0]->getRequirements(); $receivedPlayReadyTemplate = $options->getKeyDeliveryConfiguration(); $playReadyTemplate2 = MediaServicesLicenseTemplateSerializer::deserialize($receivedPlayReadyTemplate); // Assert Restrictions $template2 = TokenRestrictionTemplateSerializer::deserialize($receivedTemplate); $this->assertEqualsTokenRestrictionTemplate($template, $template2); $this->assertEqualsLicenseResponseTemplate($playReadytemplate, $playReadyTemplate2); return $result->getId(); }
function configurePlayReadyLicenseTemplate() { // The following code configures PlayReady License Template using PHP classes // and returns the XML string. //The PlayReadyLicenseResponseTemplate class represents the template for the response sent back to the end user. //It contains a field for a custom data string between the license server and the application //(may be useful for custom app logic) as well as a list of one or more license templates. $responseTemplate = new PlayReadyLicenseResponseTemplate(); // The PlayReadyLicenseTemplate class represents a license template for creating PlayReady licenses // to be returned to the end users. //It contains the data on the content key in the license and any rights or restrictions to be //enforced by the PlayReady DRM runtime when using the content key. $licenseTemplate = new PlayReadyLicenseTemplate(); //Configure whether the license is persistent (saved in persistent storage on the client) //or non-persistent (only held in memory while the player is using the license). $licenseTemplate->setLicenseType(PlayReadyLicenseType::NON_PERSISTENT); // AllowTestDevices controls whether test devices can use the license or not. // If true, the MinimumSecurityLevel property of the license // is set to 150. If false (the default), the MinimumSecurityLevel property of the license is set to 2000. $licenseTemplate->setAllowTestDevices(true); // You can also configure the Play Right in the PlayReady license by using the PlayReadyPlayRight class. // It grants the user the ability to playback the content subject to the zero or more restrictions // configured in the license and on the PlayRight itself (for playback specific policy). // Much of the policy on the PlayRight has to do with output restrictions // which control the types of outputs that the content can be played over and // any restrictions that must be put in place when using a given output. // For example, if the DigitalVideoOnlyContentRestriction is enabled, //then the DRM runtime will only allow the video to be displayed over digital outputs //(analog video outputs won’t be allowed to pass the content). //IMPORTANT: These types of restrictions can be very powerful but can also affect the consumer experience. // If the output protections are configured too restrictive, // the content might be unplayable on some clients. For more information, see the PlayReady Compliance Rules document. // For example: //$licenseTemplate->getPlayRight()->setAgcAndColorStripeRestriction(new AgcAndColorStripeRestriction(1)); $responseTemplate->setLicenseTemplates(array($licenseTemplate)); return MediaServicesLicenseTemplateSerializer::serialize($responseTemplate); }
/** * @covers \WindowsAzure\MediaServices\Templates\MediaServicesLicenseTemplateSerializer::serialize * @covers \WindowsAzure\MediaServices\Templates\MediaServicesLicenseTemplateSerializer::deserialize */ public function testRoundTripTest() { $template = new PlayReadyLicenseResponseTemplate(); $template->setResponseCustomData('test custom data'); $licenseTemplate = new PlayReadyLicenseTemplate(); $template->setLicenseTemplates(array($licenseTemplate)); $licenseTemplate->setLicenseType(PlayReadyLicenseType::PERSISTENT); $licenseTemplate->setBeginDate(new \DateTime('now')); $licenseTemplate->setRelativeExpirationDate(new \DateInterval('PT6H')); $licenseTemplate->setContentKey(new ContentEncryptionKeyFromKeyIdentifier('test custom id')); $playRight = new PlayReadyPlayRight(); $licenseTemplate->setPlayRight($playRight); $playRight->setAgcAndColorStripeRestriction(new AgcAndColorStripeRestriction(1)); $playRight->setAllowPassingVideoContentToUnknownOutput(UnknownOutputPassingOption::ALLOWED); $playRight->setAnalogVideoOpl(100); $playRight->setCompressedDigitalAudioOpl(300); $playRight->setCompressedDigitalVideoOpl(400); $playRight->setExplicitAnalogTelevisionOutputRestriction(new ExplicitAnalogTelevisionRestriction(0, true)); $playRight->setImageConstraintForAnalogComponentVideoRestriction(true); $playRight->setImageConstraintForAnalogComputerMonitorRestriction(true); $playRight->setScmsRestriction(new ScmsRestriction(2)); $playRight->setUncompressedDigitalAudioOpl(250); $playRight->setUncompressedDigitalVideoOpl(270); $result = MediaServicesLicenseTemplateSerializer::serialize($template); $playreadyLicense = MediaServicesLicenseTemplateSerializer::deserialize($result); $this->assertEqualsLicenseResponseTemplate($template, $playreadyLicense); }
/** * @param mixed $xmlElement * @return PlayReadyLicenseTemplate */ private static function deserializePlayReadyLicenseTemplate($xmlElement) { if (!isset($xmlElement->PlayRight)) { throw new \RuntimeException("The PlayReadyLicenseTemplate must contains an 'PlayRight' element"); } if (!isset($xmlElement->ContentKey)) { throw new \RuntimeException("The PlayReadyLicenseTemplate must contains an 'ContentKey' element"); } $result = new PlayReadyLicenseTemplate(); if (isset($xmlElement->AllowTestDevices)) { $result->setAllowTestDevices($xmlElement->AllowTestDevices == "true"); } if (isset($xmlElement->BeginDate)) { if (isset($xmlElement->BeginDate->attributes(Resources::XSI_XML_NAMESPACE)->nil) && $xmlElement->BeginDate->attributes(Resources::XSI_XML_NAMESPACE)->nil == "true") { $result->setBeginDate(null); } else { $result->setBeginDate(new \DateTime((string) $xmlElement->BeginDate)); } } if (isset($xmlElement->ExpirationDate)) { if (isset($xmlElement->ExpirationDate->attributes(Resources::XSI_XML_NAMESPACE)->nil) && $xmlElement->ExpirationDate->attributes(Resources::XSI_XML_NAMESPACE)->nil == "true") { $result->setExpirationDate(null); } else { $result->setExpirationDate(new \DateTime((string) $xmlElement->setExpirationDate)); } } if (isset($xmlElement->RelativeBeginDate)) { $result->setRelativeBeginDate(new \DateInterval((string) $xmlElement->RelativeBeginDate)); } if (isset($xmlElement->RelativeExpirationDate)) { $result->setRelativeExpirationDate(new \DateInterval((string) $xmlElement->RelativeExpirationDate)); } if (isset($xmlElement->GracePeriod)) { $result->setGracePeriod(new \DateInterval((string) $xmlElement->GracePeriod)); } $result->setPlayRight(MediaServicesLicenseTemplateSerializer::deserializePlayReadyPlayRight($xmlElement->PlayRight)); if (isset($xmlElement->LicenseType)) { $result->setLicenseType((string) $xmlElement->LicenseType); } $result->setContentKey(MediaServicesLicenseTemplateSerializer::deserializePlayReadyContentKey($xmlElement->ContentKey)); return $result; }