From e2294f210c2e722048f1fe9fdaf1290459ca3348 Mon Sep 17 00:00:00 2001 From: Mariano Converti Date: Wed, 9 Dec 2015 17:33:42 -0300 Subject: [PATCH 1/4] # added support for OpenIdConnectDiscoveryDocument in TokenRestrictionTemplate # added support for Widevine (WIP) --- .../tokenrestriction/ErrorMessages.java | 16 ++++ .../OpenIdConnectDiscoveryDocument.java | 29 +++++++ .../TokenRestrictionTemplate.java | 20 +++++ .../TokenRestrictionTemplateSerializer.java | 82 ++++++++++++------- .../AssetDeliveryPolicyConfigurationKey.java | 9 +- .../media/models/ContentKeyDeliveryType.java | 6 +- 6 files changed, 130 insertions(+), 32 deletions(-) create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/ErrorMessages.java create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/OpenIdConnectDiscoveryDocument.java diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/ErrorMessages.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/ErrorMessages.java new file mode 100644 index 000000000000..5fedc2210b45 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/ErrorMessages.java @@ -0,0 +1,16 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.tokenrestriction; + +public final class ErrorMessages { + + public static final String PRIMARY_VERIFICATIONKEY_AND_OPENIDCONNECTDISCOVERYDOCUMENT_ARE_NULL + = "Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null."; + + public static final String OPENIDDISCOVERYURI_STRING_IS_NULL_OR_EMPTY + = "OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri string value is null or empty."; + + public static final String OPENIDDISCOVERYURI_STRING_IS_NOT_ABSOLUTE_URI + = "String representation of OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri is not valid absolute Uri."; + + private ErrorMessages() { + } +} diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/OpenIdConnectDiscoveryDocument.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/OpenIdConnectDiscoveryDocument.java new file mode 100644 index 000000000000..62c46f0f6ff4 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/OpenIdConnectDiscoveryDocument.java @@ -0,0 +1,29 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.tokenrestriction; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "OpenIdConnectDiscoveryDocument") +public class OpenIdConnectDiscoveryDocument { + + @XmlElement(name = "OpenIdDiscoveryUri") + private String openIdDiscoveryUri; + + /** + * @return the openIdDiscoveryUri + */ + public String getOpenIdDiscoveryUri() { + return openIdDiscoveryUri; + } + + /** + * @param openIdDiscoveryUri the openIdDiscoveryUri to set + */ + public void setOpenIdDiscoveryUri(String openIdDiscoveryUri) { + this.openIdDiscoveryUri = openIdDiscoveryUri; + } + +} diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java index fdc9b05859db..b91312c3ba97 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java @@ -34,6 +34,9 @@ public class TokenRestrictionTemplate { @XmlElement(name = "TokenType") private TokenType tokenType; + + @XmlElement(name = "OpenIdConnectDiscoveryDocument") + private OpenIdConnectDiscoveryDocument openIdConnectDiscoveryDocument; @SuppressWarnings("unused") private TokenRestrictionTemplate() { @@ -146,4 +149,21 @@ public TokenRestrictionTemplate setAlternateVerificationKeys(List claims = new HashMap(); for (TokenClaim claim : tokenTemplate.getRequiredClaims()) { String claimValue = claim.getClaimValue(); if (claimValue == null && claim.getClaimType().equals(TokenClaim.getContentKeyIdentifierClaimType())) { if (keyIdForContentKeyIdentifierClaim == null) { - throw new IllegalArgumentException(String.format("The 'keyIdForContentKeyIdentifierClaim' parameter cannot be null when the token template contains a required '%s' claim type.", TokenClaim.getContentKeyIdentifierClaimType())); + throw new IllegalArgumentException(String.format( + "The 'keyIdForContentKeyIdentifierClaim' parameter cannot be null when the token template contains a required '%s' claim type.", + TokenClaim.getContentKeyIdentifierClaimType())); } claimValue = keyIdForContentKeyIdentifierClaim.toString(); } - claims.put(claim.getClaimType(), claimValue); + claims.put(claim.getClaimType(), claimValue); } - return Jwts.builder() - .setHeaderParam("typ", "JWT") - .setClaims(claims) - .setIssuer(tokenTemplate.getIssuer().toString()) - .setAudience(tokenTemplate.getAudience().toString()) - .setIssuedAt(notBefore) - .setExpiration(tokenExpiration) - .signWith(SignatureAlgorithm.HS256, secretKey) + return Jwts.builder().setHeaderParam("typ", "JWT").setClaims(claims) + .setIssuer(tokenTemplate.getIssuer().toString()).setAudience(tokenTemplate.getAudience().toString()) + .setIssuedAt(notBefore).setExpiration(tokenExpiration).signWith(SignatureAlgorithm.HS256, secretKey) .compact(); } - - public static String generateTestTokenSWT(TokenRestrictionTemplate tokenTemplate, TokenVerificationKey signingKeyToUse, - UUID keyIdForContentKeyIdentifierClaim, Date tokenExpiration) { - + + public static String generateTestTokenSWT(TokenRestrictionTemplate tokenTemplate, + TokenVerificationKey signingKeyToUse, UUID keyIdForContentKeyIdentifierClaim, Date tokenExpiration) { + StringBuilder builder = new StringBuilder(); for (TokenClaim claim : tokenTemplate.getRequiredClaims()) { String claimValue = claim.getClaimValue(); if (claim.getClaimType().equals(TokenClaim.getContentKeyIdentifierClaimType())) { if (keyIdForContentKeyIdentifierClaim == null) { - throw new IllegalArgumentException(String.format("The 'keyIdForContentKeyIdentifierClaim' parameter cannot be null when the token template contains a required '%s' claim type.", TokenClaim.getContentKeyIdentifierClaimType())); + throw new IllegalArgumentException(String.format( + "The 'keyIdForContentKeyIdentifierClaim' parameter cannot be null when the token template contains a required '%s' claim type.", + TokenClaim.getContentKeyIdentifierClaimType())); } claimValue = keyIdForContentKeyIdentifierClaim.toString(); } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/AssetDeliveryPolicyConfigurationKey.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/AssetDeliveryPolicyConfigurationKey.java index 0637d5c9080a..7d33469f8780 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/AssetDeliveryPolicyConfigurationKey.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/AssetDeliveryPolicyConfigurationKey.java @@ -35,9 +35,10 @@ public enum AssetDeliveryPolicyConfigurationKey { /** The PlayReady Custom Attributes to add to the PlayReady Content Header. */ PlayReadyCustomAttributes(5), /** The initialization vector to use for envelope encryption. */ - EnvelopeEncryptionIV(6); - - + EnvelopeEncryptionIV(6), + /** Widevine DRM Acquisition Url to use for common encryption. */ + WidevineLicenseAcquisitionUrl(7); + /** The AssetDeliveryPolicyType code. */ private int assetDeliveryPolicyConfigurationKey; @@ -84,6 +85,8 @@ public static AssetDeliveryPolicyConfigurationKey fromCode(int option) { return AssetDeliveryPolicyConfigurationKey.PlayReadyCustomAttributes; case 6: return AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIV; + case 7: + return AssetDeliveryPolicyConfigurationKey.WidevineLicenseAcquisitionUrl; default: throw new InvalidParameterException("option"); } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyDeliveryType.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyDeliveryType.java index 683466b17fbf..155f0d3e3fd3 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyDeliveryType.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyDeliveryType.java @@ -27,7 +27,9 @@ public enum ContentKeyDeliveryType { /** Use PlayReady License acquisition protocol. */ PlayReadyLicense(1), /** Use MPEG Baseline HTTP key protocol. */ - BaselineHttp(2); + BaselineHttp(2), + /** Use Widevine license acquisition protocol. */ + Widevine(3); /** The AssetDeliveryPolicyType code. */ private int contentKeyDeliveryType; @@ -66,6 +68,8 @@ public static ContentKeyDeliveryType fromCode(int option) { return ContentKeyDeliveryType.PlayReadyLicense; case 2: return ContentKeyDeliveryType.BaselineHttp; + case 3: + return ContentKeyDeliveryType.Widevine; default: throw new InvalidParameterException("option"); } From 143cf741e0095d5c40f3747111f62019ef9d5ef5 Mon Sep 17 00:00:00 2001 From: Emanuel Vecchio Date: Mon, 14 Dec 2015 16:23:25 -0300 Subject: [PATCH 2/4] Added unit tests for OpenConnectId --- .../TokenRestrictionTemplate.java | 2 +- .../TokenRestrictionTemplateSerializer.java | 58 +++++++------ ...kenRestrictionTemplateSerializerTests.java | 86 +++++++++++++++++++ 3 files changed, 119 insertions(+), 27 deletions(-) diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java index b91312c3ba97..742a929c7651 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java @@ -25,7 +25,7 @@ public class TokenRestrictionTemplate { @XmlElement(name = "Issuer", required = true) private URI issuer; - @XmlElement(name = "PrimaryVerificationKey") + @XmlElement(name = "PrimaryVerificationKey", nillable = true) private TokenVerificationKey primaryVerificationKey; @XmlElementWrapper(name = "RequiredClaims") diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java index 9a7aef43292b..96d2029483ac 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java @@ -39,30 +39,9 @@ private TokenRestrictionTemplateSerializer() { } public static String serialize(TokenRestrictionTemplate template) throws JAXBException { - - if (template.getPrimaryVerificationKey() == null && template.getOpenIdConnectDiscoveryDocument() == null) { - throw new IllegalArgumentException( - ErrorMessages.PRIMARY_VERIFICATIONKEY_AND_OPENIDCONNECTDISCOVERYDOCUMENT_ARE_NULL); - } - - if (template.getOpenIdConnectDiscoveryDocument() != null) { - if (template.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri() == null - || template.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri().isEmpty()) { - throw new IllegalArgumentException(ErrorMessages.OPENIDDISCOVERYURI_STRING_IS_NULL_OR_EMPTY); - } - - boolean openIdDiscoveryUrlValid = true; - try { - new URL(template.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri()); - } catch (MalformedURLException e) { - openIdDiscoveryUrlValid = false; - } - - if (!openIdDiscoveryUrlValid) { - throw new IllegalArgumentException(ErrorMessages.OPENIDDISCOVERYURI_STRING_IS_NOT_ABSOLUTE_URI); - } - } - + + validateTokenRestrictionTemplate(template); + StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(TokenRestrictionTemplate.class); Marshaller m = context.createMarshaller(); @@ -85,7 +64,32 @@ public String getPreferredPrefix(String namespaceUri, String suggestion, boolean return writer.toString(); } - public static TokenRestrictionTemplate deserialize(String xml) throws JAXBException { + private static void validateTokenRestrictionTemplate(TokenRestrictionTemplate template) { + if (template.getPrimaryVerificationKey() == null && template.getOpenIdConnectDiscoveryDocument() == null) { + throw new IllegalArgumentException( + ErrorMessages.PRIMARY_VERIFICATIONKEY_AND_OPENIDCONNECTDISCOVERYDOCUMENT_ARE_NULL); + } + + if (template.getOpenIdConnectDiscoveryDocument() != null) { + if (template.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri() == null + || template.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri().isEmpty()) { + throw new IllegalArgumentException(ErrorMessages.OPENIDDISCOVERYURI_STRING_IS_NULL_OR_EMPTY); + } + + boolean openIdDiscoveryUrlValid = true; + try { + new URL(template.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri()); + } catch (MalformedURLException e) { + openIdDiscoveryUrlValid = false; + } + + if (!openIdDiscoveryUrlValid) { + throw new IllegalArgumentException(ErrorMessages.OPENIDDISCOVERYURI_STRING_IS_NOT_ABSOLUTE_URI); + } + } + } + + public static TokenRestrictionTemplate deserialize(String xml) throws JAXBException { try { return deserialize(xml, null); } catch (SAXException e) { @@ -103,7 +107,9 @@ public static TokenRestrictionTemplate deserialize(String xml, String validation Schema schema = factory.newSchema(new File(validationSchemaFileName)); u.setSchema(schema); } - return (TokenRestrictionTemplate) u.unmarshal(new StringReader(xml)); + TokenRestrictionTemplate template = (TokenRestrictionTemplate) u.unmarshal(new StringReader(xml)); + validateTokenRestrictionTemplate(template); + return template; } private static String generateTokenExpiry(Date expiry) { diff --git a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializerTests.java b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializerTests.java index aeae93179e18..1a4a40035555 100644 --- a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializerTests.java +++ b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializerTests.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -232,4 +233,89 @@ public void NullContentKeyIdentifierClaimShouldThrownJWT() throws Exception { assertTrue(e.getMessage().contains("keyIdForContentKeyIdentifierClaim")); } } + + @Test + public void OpenIdDocumentAsVerificationKeyRoundTrip() throws JAXBException, URISyntaxException + { + String openConnectId = "https://openconnectIddiscoveryUri"; + String expectedElement = + "https://openconnectIddiscoveryUri"; + + TokenRestrictionTemplate template = new TokenRestrictionTemplate(TokenType.JWT); + template.setAudience(new URI(_sampleAudience)); + template.setIssuer(new URI(_sampleIssuer)); + OpenIdConnectDiscoveryDocument openId = new OpenIdConnectDiscoveryDocument(); + openId.setOpenIdDiscoveryUri(openConnectId); + template.setOpenIdConnectDiscoveryDocument(openId); + String templateAsString = TokenRestrictionTemplateSerializer.serialize(template); + assertTrue(templateAsString.contains("")); + assertTrue(templateAsString.contains(expectedElement)); + TokenRestrictionTemplate output = TokenRestrictionTemplateSerializer.deserialize(templateAsString); + assertNotNull(output); + assertNotNull(output.getOpenIdConnectDiscoveryDocument()); + assertNull(output.getPrimaryVerificationKey()); + assertTrue(output.getAlternateVerificationKeys().isEmpty()); + assertEquals(output.getOpenIdConnectDiscoveryDocument().getOpenIdDiscoveryUri(), openConnectId); + + } + + @Test + public void TokenRestrictionTemplateSerializeNotPrimaryKeyAndNoOpenConnectIdDocument() throws URISyntaxException + { + TokenRestrictionTemplate template = new TokenRestrictionTemplate(TokenType.JWT); + template.setAudience(new URI(_sampleAudience)); + template.setIssuer(new URI(_sampleIssuer)); + try { + TokenRestrictionTemplateSerializer.serialize(template); + fail(); + } + catch (Exception ex) { + assertEquals("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null.", ex.getMessage()); + } + } + + @Test + public void InputMissingPrimaryKeyShouldNotThrow() + { + String tokenTemplate = "GG07fDPZ+HMD2vcoknMqYjEJMb7LSq8zUmdCYMvRCevnQK//ilbhODO/FydMrHiwZGmI6XywvOOU7SSzRPlI3Q==http://sampleaudience/http://sampleissuerurl/urn:microsoft:azure:mediaservices:contentkeyidentifierurn:myservice:claims:rentaltrue"; + try { + TokenRestrictionTemplateSerializer.deserialize(tokenTemplate); + fail(); + } catch (Exception ex) { + assertEquals("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null.", ex.getMessage()); + } + } + + @Test + public void TokenRestrictionTemplateDeserializeNotAbsoluteDiscoveryUri() + { + String body = + "http://sampleissuerurl/http://sampleaudience/RelativeUri"; + + try + { + TokenRestrictionTemplateSerializer.deserialize(body); + fail(); + } + catch (Exception ex) + { + assertEquals("String representation of OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri is not valid absolute Uri.", ex.getMessage()); + } + } + + @Test + public void TokenRestrictionTemplateDeserializeNilOpenConnectIdDocumentUriNoPrimaryKey() + { + String body = + "http://sampleissuerurl/http://sampleaudience/"; + try + { + TokenRestrictionTemplateSerializer.deserialize(body); + fail(); + } + catch (Exception ex) + { + assertEquals("OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri string value is null or empty.", ex.getMessage()); + } + } } From 24ad29567f904b9ee0c763a97a911a4e89281abd Mon Sep 17 00:00:00 2001 From: Emanuel Vecchio Date: Tue, 15 Dec 2015 13:12:40 -0300 Subject: [PATCH 3/4] Added WidevineMessage --- .../templates/widevine/AllowedTrackTypes.java | 6 ++ .../templates/widevine/ContentKeySpecs.java | 39 ++++++++ .../templates/widevine/Hdcp.java | 7 ++ .../widevine/RequiredOutputProtection.java | 11 +++ .../templates/widevine/WidevineMessage.java | 28 ++++++ .../WidevineMessageSerializerTests.java | 91 +++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java create mode 100644 services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java new file mode 100644 index 000000000000..1060267b2824 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java @@ -0,0 +1,6 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +public enum AllowedTrackTypes { + SD_ONLY, + SD_HD +} diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java new file mode 100644 index 000000000000..3e847a42fc6c --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java @@ -0,0 +1,39 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ContentKeySpecs { + /** + * A track type name. + */ + @JsonProperty + public String track_type; + + /** + * Unique identifier for the key. + */ + @JsonProperty + public String key_id; + + /** + * Defines client robustness requirements for playback. + * 1 - Software-based whitebox crypto is required. + * 2 - Software crypto and an obfuscated decoder is required. + * 3 - The key material and crypto operations must be performed + * within a hardware backed trusted execution environment. + * 4 - The crypto and decoding of content must be performed within + * a hardware backed trusted execution environment. + * 5 - The crypto, decoding and all handling of the media (compressed + * and uncompressed) must be handled within a hardware backed trusted + * execution environment. + */ + @JsonProperty + public Integer security_level; + + /** + * Indicates whether HDCP V1 or V2 is required or not. + */ + @JsonProperty + public RequiredOutputProtection required_output_protection; +} diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java new file mode 100644 index 000000000000..2f1cdf24b12c --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java @@ -0,0 +1,7 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +public enum Hdcp { + HDCP_NONE, + HDCP_V1, + HDCP_V2 +} diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java new file mode 100644 index 000000000000..14fe77edf257 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java @@ -0,0 +1,11 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RequiredOutputProtection { + /** + * Indicates whether HDCP is required. + */ + @JsonProperty + public Hdcp hdcp; +} diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java new file mode 100644 index 000000000000..8844970a2e04 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java @@ -0,0 +1,28 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class WidevineMessage { + /** + * Controls which content keys should be included in a license. + * Only one of allowed_track_types and content_key_specs can be specified. + */ + @JsonProperty + public AllowedTrackTypes allowed_track_types; + + /** + * A finer grained control on what content keys to return. + * Only one of allowed_track_types and content_key_specs can be specified. + */ + @JsonProperty + public ContentKeySpecs[] content_key_specs; + + /** + * Policy settings for this license. In the event this asset has + * a pre-defined policy, these specified values will be used. + */ + @JsonProperty + public Object policy_overrides; +} diff --git a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java new file mode 100644 index 000000000000..ad680b750dae --- /dev/null +++ b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java @@ -0,0 +1,91 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import java.io.IOException; +import java.net.URISyntaxException; +import javax.xml.bind.JAXBException; + +import org.junit.Test; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class WidevineMessageSerializerTests { + + @Test + public void RoundTripTest() throws JAXBException, URISyntaxException, IOException { + ObjectMapper mapper = new ObjectMapper(); + WidevineMessage message = new WidevineMessage(); + message.allowed_track_types = AllowedTrackTypes.SD_HD; + ContentKeySpecs ckspecs = new ContentKeySpecs(); + message.content_key_specs = new ContentKeySpecs[] { ckspecs }; + ckspecs.required_output_protection = new RequiredOutputProtection(); + ckspecs.required_output_protection.hdcp = Hdcp.HDCP_NONE; + ckspecs.security_level = 1; + ckspecs.track_type = "SD"; + message.policy_overrides = new Object() { + public boolean can_play = true; + public boolean can_persist = true; + public boolean can_renew = false; + }; + + String json = mapper.writeValueAsString(message); + + WidevineMessage result = mapper.readValue(json, WidevineMessage.class); + + assertEqualsWidevineMessage(message, result); + } + + @Test + public void FromJsonTest() throws JAXBException, URISyntaxException, JsonProcessingException { + String expected = "{\"allowed_track_types\":\"SD_HD\",\"content_key_specs\":[{\"track_type\":\"SD\",\"key_id\":null,\"security_level\":1,\"required_output_protection\":{\"hdcp\":\"HDCP_NONE\"}}],\"policy_overrides\":{\"can_play\":true,\"can_persist\":true,\"can_renew\":false}}"; + ObjectMapper mapper = new ObjectMapper(); + WidevineMessage message = new WidevineMessage(); + message.allowed_track_types = AllowedTrackTypes.SD_HD; + ContentKeySpecs ckspecs = new ContentKeySpecs(); + message.content_key_specs = new ContentKeySpecs[] { ckspecs }; + ckspecs.required_output_protection = new RequiredOutputProtection(); + ckspecs.required_output_protection.hdcp = Hdcp.HDCP_NONE; + ckspecs.security_level = 1; + ckspecs.track_type = "SD"; + message.policy_overrides = new Object() { + public boolean can_play = true; + public boolean can_persist = true; + public boolean can_renew = false; + }; + + String json = mapper.writeValueAsString(message); + + assertEquals(expected, json); + } + + private static void assertEqualsWidevineMessage(WidevineMessage expected, WidevineMessage actual) { + assertEquals(expected.allowed_track_types, actual.allowed_track_types); + if (expected.content_key_specs == null) { + assertNull(actual.content_key_specs); + } else { + assertNotNull(actual.content_key_specs); + assertEquals(expected.content_key_specs.length, actual.content_key_specs.length); + for(int i = 0; i < expected.content_key_specs.length; i++) { + ContentKeySpecs expectedCks = expected.content_key_specs[i]; + ContentKeySpecs actualCks = actual.content_key_specs[i]; + assertEquals(expectedCks.key_id, actualCks.key_id); + assertEquals(expectedCks.security_level, actualCks.security_level); + assertEquals(expectedCks.track_type, actualCks.track_type); + if (expectedCks.required_output_protection != null) { + assertNotNull(actualCks.required_output_protection); + assertEquals(expectedCks.required_output_protection.hdcp, actualCks.required_output_protection.hdcp); + } else { + assertNull(actualCks.required_output_protection); + } + assertEquals(expectedCks.key_id, actualCks.key_id); + } + } + if (expected.policy_overrides == null) { + assertNull(actual.policy_overrides); + } else { + assertNotNull(actual.policy_overrides); + } + } +} From 9b9cb2a8db8af12c07c772218d173477cfc31759 Mon Sep 17 00:00:00 2001 From: Mariano Converti Date: Tue, 5 Jan 2016 00:57:38 -0300 Subject: [PATCH 4/4] # fixed checkstyle issues --- .../TokenRestrictionTemplate.java | 49 ++++--- .../TokenRestrictionTemplateSerializer.java | 20 +-- .../templates/widevine/AllowedTrackTypes.java | 3 +- .../templates/widevine/ContentKeySpecs.java | 105 +++++++++----- .../templates/widevine/Hdcp.java | 4 +- .../widevine/RequiredOutputProtection.java | 20 ++- .../templates/widevine/WidevineMessage.java | 58 ++++++-- .../templates/widevine/package-info.java | 16 +++ .../ODataSerializationFromJerseyTest.java | 1 - .../WidevineMessageSerializerTests.java | 133 +++++++++--------- .../scenarios/MediaServiceValidation.java | 1 - 11 files changed, 254 insertions(+), 156 deletions(-) create mode 100644 services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/package-info.java diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java index 742a929c7651..2913dafa6ca7 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplate.java @@ -10,50 +10,49 @@ import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; - @XmlRootElement(name = "TokenRestrictionTemplate") @XmlAccessorType(XmlAccessType.FIELD) public class TokenRestrictionTemplate { - + @XmlElementWrapper(name = "AlternateVerificationKeys") @XmlElement(name = "TokenVerificationKey") private List alternateVerificationKeys; - + @XmlElement(name = "Audience", required = true) private URI audience; - + @XmlElement(name = "Issuer", required = true) private URI issuer; - + @XmlElement(name = "PrimaryVerificationKey", nillable = true) private TokenVerificationKey primaryVerificationKey; - + @XmlElementWrapper(name = "RequiredClaims") @XmlElement(name = "TokenClaim") private List requiredClaims; - + @XmlElement(name = "TokenType") private TokenType tokenType; @XmlElement(name = "OpenIdConnectDiscoveryDocument") private OpenIdConnectDiscoveryDocument openIdConnectDiscoveryDocument; - + @SuppressWarnings("unused") private TokenRestrictionTemplate() { this.setTokenType(TokenType.SWT); initCollections(); } - + public TokenRestrictionTemplate(TokenType tokenType) { this.setTokenType(tokenType); initCollections(); } - + private void initCollections() { setRequiredClaims(new ArrayList()); setAlternateVerificationKeys(new ArrayList()); } - + /** * @return the audience */ @@ -62,7 +61,8 @@ public URI getAudience() { } /** - * @param audience the audience to set + * @param audience + * the audience to set * @return this */ public TokenRestrictionTemplate setAudience(URI audience) { @@ -78,7 +78,8 @@ public URI getIssuer() { } /** - * @param issuer the issuer to set + * @param issuer + * the issuer to set * @return this */ public TokenRestrictionTemplate setIssuer(URI issuer) { @@ -94,7 +95,8 @@ public TokenType getTokenType() { } /** - * @param tokenType the tokenType to set + * @param tokenType + * the tokenType to set * @return this */ public TokenRestrictionTemplate setTokenType(TokenType tokenType) { @@ -110,7 +112,8 @@ public TokenVerificationKey getPrimaryVerificationKey() { } /** - * @param primaryVerificationKey the primaryVerificationKey to set + * @param primaryVerificationKey + * the primaryVerificationKey to set * @return this */ public TokenRestrictionTemplate setPrimaryVerificationKey(TokenVerificationKey primaryVerificationKey) { @@ -126,7 +129,8 @@ public List getRequiredClaims() { } /** - * @param requiredClaims the requiredClaims to set + * @param requiredClaims + * the requiredClaims to set * @return this */ public TokenRestrictionTemplate setRequiredClaims(List requiredClaims) { @@ -142,14 +146,15 @@ public List getAlternateVerificationKeys() { } /** - * @param alternateVerificationKeys the alternateVerificationKeys to set + * @param alternateVerificationKeys + * the alternateVerificationKeys to set * @return this */ public TokenRestrictionTemplate setAlternateVerificationKeys(List alternateVerificationKeys) { this.alternateVerificationKeys = alternateVerificationKeys; return this; } - + /** * @return the alternateVerificationKeys */ @@ -158,12 +163,14 @@ public OpenIdConnectDiscoveryDocument getOpenIdConnectDiscoveryDocument() { } /** - * @param alternateVerificationKeys the alternateVerificationKeys to set + * @param alternateVerificationKeys + * the alternateVerificationKeys to set * @return this */ - public TokenRestrictionTemplate setOpenIdConnectDiscoveryDocument(OpenIdConnectDiscoveryDocument openIdConnectDiscoveryDocument) { + public TokenRestrictionTemplate setOpenIdConnectDiscoveryDocument( + OpenIdConnectDiscoveryDocument openIdConnectDiscoveryDocument) { this.openIdConnectDiscoveryDocument = openIdConnectDiscoveryDocument; return this; } - + } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java index 96d2029483ac..306252ab3678 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/tokenrestriction/TokenRestrictionTemplateSerializer.java @@ -39,9 +39,9 @@ private TokenRestrictionTemplateSerializer() { } public static String serialize(TokenRestrictionTemplate template) throws JAXBException { - - validateTokenRestrictionTemplate(template); - + + validateTokenRestrictionTemplate(template); + StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(TokenRestrictionTemplate.class); Marshaller m = context.createMarshaller(); @@ -49,7 +49,9 @@ public static String serialize(TokenRestrictionTemplate template) throws JAXBExc m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapper() { @Override public String[] getPreDeclaredNamespaceUris() { - return new String[] { XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI }; + return new String[] { + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI + }; } @Override @@ -65,7 +67,7 @@ public String getPreferredPrefix(String namespaceUri, String suggestion, boolean } private static void validateTokenRestrictionTemplate(TokenRestrictionTemplate template) { - if (template.getPrimaryVerificationKey() == null && template.getOpenIdConnectDiscoveryDocument() == null) { + if (template.getPrimaryVerificationKey() == null && template.getOpenIdConnectDiscoveryDocument() == null) { throw new IllegalArgumentException( ErrorMessages.PRIMARY_VERIFICATIONKEY_AND_OPENIDCONNECTDISCOVERYDOCUMENT_ARE_NULL); } @@ -86,10 +88,10 @@ private static void validateTokenRestrictionTemplate(TokenRestrictionTemplate te if (!openIdDiscoveryUrlValid) { throw new IllegalArgumentException(ErrorMessages.OPENIDDISCOVERYURI_STRING_IS_NOT_ABSOLUTE_URI); } - } - } + } + } - public static TokenRestrictionTemplate deserialize(String xml) throws JAXBException { + public static TokenRestrictionTemplate deserialize(String xml) throws JAXBException { try { return deserialize(xml, null); } catch (SAXException e) { @@ -108,7 +110,7 @@ public static TokenRestrictionTemplate deserialize(String xml, String validation u.setSchema(schema); } TokenRestrictionTemplate template = (TokenRestrictionTemplate) u.unmarshal(new StringReader(xml)); - validateTokenRestrictionTemplate(template); + validateTokenRestrictionTemplate(template); return template; } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java index 1060267b2824..8e3325cbd8ec 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.media.implementation.templates.widevine; public enum AllowedTrackTypes { - SD_ONLY, - SD_HD + SD_ONLY, SD_HD } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java index 3e847a42fc6c..30d03f7a95eb 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java @@ -1,39 +1,76 @@ package com.microsoft.windowsazure.services.media.implementation.templates.widevine; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -public class ContentKeySpecs { - /** - * A track type name. - */ - @JsonProperty - public String track_type; - - /** - * Unique identifier for the key. - */ - @JsonProperty - public String key_id; - - /** - * Defines client robustness requirements for playback. - * 1 - Software-based whitebox crypto is required. - * 2 - Software crypto and an obfuscated decoder is required. - * 3 - The key material and crypto operations must be performed - * within a hardware backed trusted execution environment. - * 4 - The crypto and decoding of content must be performed within - * a hardware backed trusted execution environment. - * 5 - The crypto, decoding and all handling of the media (compressed - * and uncompressed) must be handled within a hardware backed trusted - * execution environment. - */ - @JsonProperty - public Integer security_level; - - /** - * Indicates whether HDCP V1 or V2 is required or not. - */ - @JsonProperty - public RequiredOutputProtection required_output_protection; +public class ContentKeySpecs { + /** + * A track type name. + */ + @JsonProperty("track_type") + private String trackType; + + /** + * Unique identifier for the key. + */ + @JsonProperty("key_id") + private String keyId; + + /** + * Defines client robustness requirements for playback. 1 - Software-based + * whitebox crypto is required. 2 - Software crypto and an obfuscated + * decoder is required. 3 - The key material and crypto operations must be + * performed within a hardware backed trusted execution environment. 4 - The + * crypto and decoding of content must be performed within a hardware backed + * trusted execution environment. 5 - The crypto, decoding and all handling + * of the media (compressed and uncompressed) must be handled within a + * hardware backed trusted execution environment. + */ + @JsonProperty("security_level") + private Integer securityLevel; + + /** + * Indicates whether HDCP V1 or V2 is required or not. + */ + @JsonProperty("required_output_protection") + private RequiredOutputProtection requiredOutputProtection; + + @JsonProperty("track_type") + public String getTrackType() { + return trackType; + } + + @JsonProperty("track_type") + public void setTrackType(String trackType) { + this.trackType = trackType; + } + + @JsonProperty("key_id") + public String getKeyId() { + return keyId; + } + + @JsonProperty("key_id") + public void setKeyId(String keyId) { + this.keyId = keyId; + } + + @JsonProperty("security_level") + public Integer getSecurityLevel() { + return securityLevel; + } + + @JsonProperty("security_level") + public void setSecurityLevel(Integer securityLevel) { + this.securityLevel = securityLevel; + } + + @JsonProperty("required_output_protection") + public RequiredOutputProtection getRequiredOutputProtection() { + return requiredOutputProtection; + } + + @JsonProperty("required_output_protection") + public void setRequiredOutputProtection(RequiredOutputProtection requiredOutputProtection) { + this.requiredOutputProtection = requiredOutputProtection; + } } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java index 2f1cdf24b12c..f27b7c490a40 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java @@ -1,7 +1,5 @@ package com.microsoft.windowsazure.services.media.implementation.templates.widevine; public enum Hdcp { - HDCP_NONE, - HDCP_V1, - HDCP_V2 + HDCP_NONE, HDCP_V1, HDCP_V2 } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java index 14fe77edf257..99b9d474385f 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java @@ -3,9 +3,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class RequiredOutputProtection { - /** - * Indicates whether HDCP is required. - */ - @JsonProperty - public Hdcp hdcp; + /** + * Indicates whether HDCP is required. + */ + @JsonProperty("hdcp") + private Hdcp hdcp; + + @JsonProperty("hdcp") + public Hdcp getHdcp() { + return hdcp; + } + + @JsonProperty("hdcp") + public void setHdcp(Hdcp hdcp) { + this.hdcp = hdcp; + } } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java index 8844970a2e04..d2d383451091 100644 --- a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java @@ -5,24 +5,54 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class WidevineMessage { - /** - * Controls which content keys should be included in a license. - * Only one of allowed_track_types and content_key_specs can be specified. + /** + * Controls which content keys should be included in a license. Only one of + * allowed_track_types and content_key_specs can be specified. */ - @JsonProperty - public AllowedTrackTypes allowed_track_types; + @JsonProperty("allowed_track_types") + private AllowedTrackTypes allowedTrackTypes; /** - * A finer grained control on what content keys to return. - * Only one of allowed_track_types and content_key_specs can be specified. + * A finer grained control on what content keys to return. Only one of + * allowed_track_types and content_key_specs can be specified. */ - @JsonProperty - public ContentKeySpecs[] content_key_specs; + @JsonProperty("content_key_specs") + private ContentKeySpecs[] contentKeySpecs; - /** - * Policy settings for this license. In the event this asset has - * a pre-defined policy, these specified values will be used. + /** + * Policy settings for this license. In the event this asset has a + * pre-defined policy, these specified values will be used. */ - @JsonProperty - public Object policy_overrides; + @JsonProperty("policy_overrides") + private Object policyOverrides; + + @JsonProperty("allowed_track_types") + public AllowedTrackTypes getAllowedTrackTypes() { + return allowedTrackTypes; + } + + @JsonProperty("allowed_track_types") + public void setAllowedTrackTypes(AllowedTrackTypes allowedTrackTypes) { + this.allowedTrackTypes = allowedTrackTypes; + } + + @JsonProperty("content_key_specs") + public ContentKeySpecs[] getContentKeySpecs() { + return contentKeySpecs; + } + + @JsonProperty("content_key_specs") + public void setContentKeySpecs(ContentKeySpecs[] contentKeySpecs) { + this.contentKeySpecs = contentKeySpecs; + } + + @JsonProperty("policy_overrides") + public Object getPolicyOverrides() { + return policyOverrides; + } + + @JsonProperty("policy_overrides") + public void setPolicyOverrides(Object policyOverrides) { + this.policyOverrides = policyOverrides; + } } diff --git a/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/package-info.java b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/package-info.java new file mode 100644 index 000000000000..bb96dba78597 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/package-info.java @@ -0,0 +1,16 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; \ No newline at end of file diff --git a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 6596241e998f..81521a3f1bb8 100644 --- a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -35,7 +35,6 @@ import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.json.JSONConfiguration; public class ODataSerializationFromJerseyTest extends IntegrationTestBase { diff --git a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java index ad680b750dae..e23d2c7d1d0b 100644 --- a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java +++ b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java @@ -15,77 +15,78 @@ public class WidevineMessageSerializerTests { @Test public void RoundTripTest() throws JAXBException, URISyntaxException, IOException { - ObjectMapper mapper = new ObjectMapper(); - WidevineMessage message = new WidevineMessage(); - message.allowed_track_types = AllowedTrackTypes.SD_HD; - ContentKeySpecs ckspecs = new ContentKeySpecs(); - message.content_key_specs = new ContentKeySpecs[] { ckspecs }; - ckspecs.required_output_protection = new RequiredOutputProtection(); - ckspecs.required_output_protection.hdcp = Hdcp.HDCP_NONE; - ckspecs.security_level = 1; - ckspecs.track_type = "SD"; - message.policy_overrides = new Object() { - public boolean can_play = true; - public boolean can_persist = true; - public boolean can_renew = false; - }; - - String json = mapper.writeValueAsString(message); - - WidevineMessage result = mapper.readValue(json, WidevineMessage.class); - - assertEqualsWidevineMessage(message, result); + ObjectMapper mapper = new ObjectMapper(); + WidevineMessage message = new WidevineMessage(); + message.setAllowedTrackTypes(AllowedTrackTypes.SD_HD); + ContentKeySpecs ckspecs = new ContentKeySpecs(); + message.setContentKeySpecs(new ContentKeySpecs[] { ckspecs }); + ckspecs.setRequiredOutputProtection(new RequiredOutputProtection()); + ckspecs.getRequiredOutputProtection().setHdcp(Hdcp.HDCP_NONE); + ckspecs.setSecurityLevel(1); + ckspecs.setTrackType("SD"); + message.setPolicyOverrides(new Object() { + public boolean can_play = true; + public boolean can_persist = true; + public boolean can_renew = false; + }); + + String json = mapper.writeValueAsString(message); + + WidevineMessage result = mapper.readValue(json, WidevineMessage.class); + + assertEqualsWidevineMessage(message, result); } - + @Test public void FromJsonTest() throws JAXBException, URISyntaxException, JsonProcessingException { String expected = "{\"allowed_track_types\":\"SD_HD\",\"content_key_specs\":[{\"track_type\":\"SD\",\"key_id\":null,\"security_level\":1,\"required_output_protection\":{\"hdcp\":\"HDCP_NONE\"}}],\"policy_overrides\":{\"can_play\":true,\"can_persist\":true,\"can_renew\":false}}"; - ObjectMapper mapper = new ObjectMapper(); - WidevineMessage message = new WidevineMessage(); - message.allowed_track_types = AllowedTrackTypes.SD_HD; - ContentKeySpecs ckspecs = new ContentKeySpecs(); - message.content_key_specs = new ContentKeySpecs[] { ckspecs }; - ckspecs.required_output_protection = new RequiredOutputProtection(); - ckspecs.required_output_protection.hdcp = Hdcp.HDCP_NONE; - ckspecs.security_level = 1; - ckspecs.track_type = "SD"; - message.policy_overrides = new Object() { - public boolean can_play = true; - public boolean can_persist = true; - public boolean can_renew = false; - }; - - String json = mapper.writeValueAsString(message); - - assertEquals(expected, json); + ObjectMapper mapper = new ObjectMapper(); + WidevineMessage message = new WidevineMessage(); + message.setAllowedTrackTypes(AllowedTrackTypes.SD_HD); + ContentKeySpecs ckspecs = new ContentKeySpecs(); + message.setContentKeySpecs(new ContentKeySpecs[] { ckspecs }); + ckspecs.setRequiredOutputProtection(new RequiredOutputProtection()); + ckspecs.getRequiredOutputProtection().setHdcp(Hdcp.HDCP_NONE); + ckspecs.setSecurityLevel(1); + ckspecs.setTrackType("SD"); + message.setPolicyOverrides(new Object() { + public boolean can_play = true; + public boolean can_persist = true; + public boolean can_renew = false; + }); + + String json = mapper.writeValueAsString(message); + + assertEquals(expected, json); } - + private static void assertEqualsWidevineMessage(WidevineMessage expected, WidevineMessage actual) { - assertEquals(expected.allowed_track_types, actual.allowed_track_types); - if (expected.content_key_specs == null) { - assertNull(actual.content_key_specs); - } else { - assertNotNull(actual.content_key_specs); - assertEquals(expected.content_key_specs.length, actual.content_key_specs.length); - for(int i = 0; i < expected.content_key_specs.length; i++) { - ContentKeySpecs expectedCks = expected.content_key_specs[i]; - ContentKeySpecs actualCks = actual.content_key_specs[i]; - assertEquals(expectedCks.key_id, actualCks.key_id); - assertEquals(expectedCks.security_level, actualCks.security_level); - assertEquals(expectedCks.track_type, actualCks.track_type); - if (expectedCks.required_output_protection != null) { - assertNotNull(actualCks.required_output_protection); - assertEquals(expectedCks.required_output_protection.hdcp, actualCks.required_output_protection.hdcp); - } else { - assertNull(actualCks.required_output_protection); - } - assertEquals(expectedCks.key_id, actualCks.key_id); - } - } - if (expected.policy_overrides == null) { - assertNull(actual.policy_overrides); - } else { - assertNotNull(actual.policy_overrides); - } + assertEquals(expected.getAllowedTrackTypes(), actual.getAllowedTrackTypes()); + if (expected.getContentKeySpecs() == null) { + assertNull(actual.getContentKeySpecs()); + } else { + assertNotNull(actual.getContentKeySpecs()); + assertEquals(expected.getContentKeySpecs().length, actual.getContentKeySpecs().length); + for (int i = 0; i < expected.getContentKeySpecs().length; i++) { + ContentKeySpecs expectedCks = expected.getContentKeySpecs()[i]; + ContentKeySpecs actualCks = actual.getContentKeySpecs()[i]; + assertEquals(expectedCks.getKeyId(), actualCks.getKeyId()); + assertEquals(expectedCks.getSecurityLevel(), actualCks.getSecurityLevel()); + assertEquals(expectedCks.getTrackType(), actualCks.getTrackType()); + if (expectedCks.getRequiredOutputProtection() != null) { + assertNotNull(actualCks.getRequiredOutputProtection()); + assertEquals(expectedCks.getRequiredOutputProtection().getHdcp(), + actualCks.getRequiredOutputProtection().getHdcp()); + } else { + assertNull(actualCks.getRequiredOutputProtection()); + } + assertEquals(expectedCks.getKeyId(), actualCks.getKeyId()); + } + } + if (expected.getPolicyOverrides() == null) { + assertNull(actual.getPolicyOverrides()); + } else { + assertNotNull(actual.getPolicyOverrides()); + } } } diff --git a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java index 889e262fe9c3..9f9ccec71cbb 100644 --- a/services/azure-media/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java +++ b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java @@ -26,7 +26,6 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Date; -import java.util.Enumeration; import java.util.Map; import java.util.List;