diff --git a/azure-mgmt-samples/pom.xml b/azure-mgmt-samples/pom.xml index 9922045dcb91..38101f39c4dc 100644 --- a/azure-mgmt-samples/pom.xml +++ b/azure-mgmt-samples/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../azure/pom.xml diff --git a/azure/pom.xml b/azure/pom.xml index 063a571f9289..d515ff102f73 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -16,7 +16,7 @@ 4.0.0 com.microsoft.azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT azure-bom diff --git a/core/azure-core-test/pom.xml b/core/azure-core-test/pom.xml index b8f32fe7fc6f..7e8432fed27e 100644 --- a/core/azure-core-test/pom.xml +++ b/core/azure-core-test/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/core/azure-core/pom.xml b/core/azure-core/pom.xml index aa662a2b6683..216839d0031e 100644 --- a/core/azure-core/pom.xml +++ b/core/azure-core/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/core/azure-core/src/main/java/com/microsoft/windowsazure/Configuration.java b/core/azure-core/src/main/java/com/microsoft/windowsazure/Configuration.java index cca32f8eaf9d..900809fb76b3 100644 --- a/core/azure-core/src/main/java/com/microsoft/windowsazure/Configuration.java +++ b/core/azure-core/src/main/java/com/microsoft/windowsazure/Configuration.java @@ -56,11 +56,6 @@ public class Configuration { * of the proxy to use */ public static final String PROPERTY_HTTP_PROXY_PORT = "http.proxyPort"; - - /** - * The configuration instance. - */ - private static Configuration instance; /** * The configuration properties. @@ -85,21 +80,14 @@ public Configuration(Builder builder) { } public static Configuration getInstance() { - if (instance == null) { - try { - instance = Configuration.load(); - } catch (IOException e) { - log.error( - "Unable to load META-INF/com.microsoft.windowsazure.properties", - e); - instance = new Configuration(); - } + try { + return Configuration.load(); + } catch (IOException e) { + log.error( + "Unable to load META-INF/com.microsoft.windowsazure.properties", + e); + return new Configuration(); } - return instance; - } - - public static void setInstance(final Configuration configuration) { - Configuration.instance = configuration; } public static Configuration load() throws IOException { diff --git a/core/azure-core/src/main/java/com/microsoft/windowsazure/core/pipeline/apache/ApacheConfigSettings.java b/core/azure-core/src/main/java/com/microsoft/windowsazure/core/pipeline/apache/ApacheConfigSettings.java index fb9f008a8a4b..78f635e3463c 100644 --- a/core/azure-core/src/main/java/com/microsoft/windowsazure/core/pipeline/apache/ApacheConfigSettings.java +++ b/core/azure-core/src/main/java/com/microsoft/windowsazure/core/pipeline/apache/ApacheConfigSettings.java @@ -100,13 +100,11 @@ public HttpClientBuilder applyConfig(HttpClientBuilder httpClientBuilder) { httpClientBuilder.addInterceptorFirst(new HttpHeaderRemovalFilter()); } - if (properties.containsKey("AuthFilters")) + if (properties.containsKey("AuthFilter")) { @SuppressWarnings("unchecked") - ArrayList filters = (ArrayList) properties.get("AuthFilters"); - for (ServiceRequestFilter filter : filters) { - httpClientBuilder.addInterceptorFirst(new FilterInterceptor(filter)); - } + ServiceRequestFilter filter = (ServiceRequestFilter) properties.get("AuthFilter"); + httpClientBuilder.addInterceptorFirst(new FilterInterceptor(filter)); } return httpClientBuilder; diff --git a/core/azure-core/src/main/java/com/microsoft/windowsazure/credentials/TokenCloudCredentials.java b/core/azure-core/src/main/java/com/microsoft/windowsazure/credentials/TokenCloudCredentials.java index 85839d4953dd..d58a9744f6ab 100644 --- a/core/azure-core/src/main/java/com/microsoft/windowsazure/credentials/TokenCloudCredentials.java +++ b/core/azure-core/src/main/java/com/microsoft/windowsazure/credentials/TokenCloudCredentials.java @@ -116,16 +116,7 @@ public void setToken(String token) { @Override @SuppressWarnings("unchecked") public void applyConfig(String profile, Map properties) { - ArrayList filters; - if (!properties.containsKey("AuthFilters")) - { - filters = new ArrayList(); - properties.put("AuthFilters", filters); - } else { - filters = (ArrayList)properties.get("AuthFilters"); - } - - filters.add(new AdalAuthFilter(this.token)); + properties.put("AuthFilter", new AdalAuthFilter(this.token)); } } diff --git a/core/azure-tracing-util/pom.xml b/core/azure-tracing-util/pom.xml index 0b09a8a766b9..3f7cbdc54ea0 100644 --- a/core/azure-tracing-util/pom.xml +++ b/core/azure-tracing-util/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/pom.xml b/pom.xml index b70b75153f48..c96c93e70afe 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 4.0.0 com.microsoft.azure azure-bom - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT pom Microsoft Azure SDK diff --git a/resource-management/azure-mgmt-compute/pom.xml b/resource-management/azure-mgmt-compute/pom.xml index b46a3ff66063..61a7c3f0ddf6 100644 --- a/resource-management/azure-mgmt-compute/pom.xml +++ b/resource-management/azure-mgmt-compute/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-dns/pom.xml b/resource-management/azure-mgmt-dns/pom.xml index 7d5c5e6e7bce..fc806987ffc1 100644 --- a/resource-management/azure-mgmt-dns/pom.xml +++ b/resource-management/azure-mgmt-dns/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-network/pom.xml b/resource-management/azure-mgmt-network/pom.xml index 8a57ff03676f..df2083e6b74d 100644 --- a/resource-management/azure-mgmt-network/pom.xml +++ b/resource-management/azure-mgmt-network/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-resources/pom.xml b/resource-management/azure-mgmt-resources/pom.xml index d307e8416f3e..c8dc2a19eb58 100644 --- a/resource-management/azure-mgmt-resources/pom.xml +++ b/resource-management/azure-mgmt-resources/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-sql/pom.xml b/resource-management/azure-mgmt-sql/pom.xml index 92ce4944793c..3a23198e436a 100644 --- a/resource-management/azure-mgmt-sql/pom.xml +++ b/resource-management/azure-mgmt-sql/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-storage/pom.xml b/resource-management/azure-mgmt-storage/pom.xml index d58ed2c7b9a5..c54fe1b334bb 100644 --- a/resource-management/azure-mgmt-storage/pom.xml +++ b/resource-management/azure-mgmt-storage/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-traffic-manager/pom.xml b/resource-management/azure-mgmt-traffic-manager/pom.xml index 54ddc839afc6..b895dc428221 100644 --- a/resource-management/azure-mgmt-traffic-manager/pom.xml +++ b/resource-management/azure-mgmt-traffic-manager/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperations.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperations.java index cb94b14eb5e5..2ae0cdb6bb5b 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperations.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperations.java @@ -30,7 +30,6 @@ import com.microsoft.azure.management.trafficmanager.models.EndpointUpdateResponse; import com.microsoft.windowsazure.core.OperationResponse; import com.microsoft.windowsazure.exception.ServiceException; - import java.io.IOException; import java.util.concurrent.Future; diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperationsImpl.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperationsImpl.java index f8e2e7b6f7b6..15c96eb01f24 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperationsImpl.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/EndpointOperationsImpl.java @@ -36,6 +36,14 @@ import com.microsoft.windowsazure.core.utils.CollectionStringBuilder; import com.microsoft.windowsazure.exception.ServiceException; import com.microsoft.windowsazure.tracing.CloudTracing; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -48,15 +56,6 @@ import org.codehaus.jackson.node.NullNode; import org.codehaus.jackson.node.ObjectNode; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; - /** * Operations for managing Traffic Manager endpoints. */ @@ -180,7 +179,7 @@ public EndpointCreateOrUpdateResponse createOrUpdate(String resourceGroupName, S url = url + "/"; url = url + URLEncoder.encode(endpointName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -252,6 +251,10 @@ public EndpointCreateOrUpdateResponse createOrUpdate(String resourceGroupName, S if (parameters.getEndpoint().getProperties().getEndpointMonitorStatus() != null) { ((ObjectNode) propertiesValue).put("endpointMonitorStatus", parameters.getEndpoint().getProperties().getEndpointMonitorStatus()); } + + if (parameters.getEndpoint().getProperties().getMinChildEndpoints() != null) { + ((ObjectNode) propertiesValue).put("minChildEndpoints", parameters.getEndpoint().getProperties().getMinChildEndpoints()); + } } StringWriter stringWriter = new StringWriter(); @@ -369,6 +372,13 @@ public EndpointCreateOrUpdateResponse createOrUpdate(String resourceGroupName, S endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue2.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance.setMinChildEndpoints(minChildEndpointsInstance); + } } } @@ -476,7 +486,7 @@ public OperationResponse delete(String resourceGroupName, String profileName, St url = url + "/"; url = url + URLEncoder.encode(endpointName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -616,7 +626,7 @@ public EndpointGetResponse get(String resourceGroupName, String profileName, Str url = url + "/"; url = url + URLEncoder.encode(endpointName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -746,6 +756,13 @@ public EndpointGetResponse get(String resourceGroupName, String profileName, Str endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance.setMinChildEndpoints(minChildEndpointsInstance); + } } } @@ -864,7 +881,7 @@ public EndpointUpdateResponse update(String resourceGroupName, String profileNam url = url + "/"; url = url + URLEncoder.encode(endpointName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -936,6 +953,10 @@ public EndpointUpdateResponse update(String resourceGroupName, String profileNam if (parameters.getEndpoint().getProperties().getEndpointMonitorStatus() != null) { ((ObjectNode) propertiesValue).put("endpointMonitorStatus", parameters.getEndpoint().getProperties().getEndpointMonitorStatus()); } + + if (parameters.getEndpoint().getProperties().getMinChildEndpoints() != null) { + ((ObjectNode) propertiesValue).put("minChildEndpoints", parameters.getEndpoint().getProperties().getMinChildEndpoints()); + } } StringWriter stringWriter = new StringWriter(); @@ -1053,6 +1074,13 @@ public EndpointUpdateResponse update(String resourceGroupName, String profileNam endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue2.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance.setMinChildEndpoints(minChildEndpointsInstance); + } } } diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperations.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperations.java index dffcba841cc9..128a832b3540 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperations.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperations.java @@ -33,7 +33,6 @@ import com.microsoft.azure.management.trafficmanager.models.ProfileUpdateResponse; import com.microsoft.windowsazure.core.OperationResponse; import com.microsoft.windowsazure.exception.ServiceException; - import java.io.IOException; import java.util.concurrent.Future; diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperationsImpl.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperationsImpl.java index 3f0deaef2e85..9a7404bfd8be 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperationsImpl.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/ProfileOperationsImpl.java @@ -42,8 +42,19 @@ import com.microsoft.windowsazure.core.ServiceOperations; import com.microsoft.windowsazure.core.pipeline.apache.CustomHttpDelete; import com.microsoft.windowsazure.core.utils.CollectionStringBuilder; +import com.microsoft.windowsazure.core.utils.EnumUtility; import com.microsoft.windowsazure.exception.ServiceException; import com.microsoft.windowsazure.tracing.CloudTracing; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.Future; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -58,17 +69,6 @@ import org.codehaus.jackson.node.NullNode; import org.codehaus.jackson.node.ObjectNode; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; - /** * Operations for managing Traffic Manager profiles. */ @@ -150,7 +150,7 @@ public CheckTrafficManagerRelativeDnsNameAvailabilityResponse checkTrafficManage url = url + "Microsoft.Network"; url = url + "/checkTrafficManagerNameAvailability"; ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -245,7 +245,7 @@ public CheckTrafficManagerRelativeDnsNameAvailabilityResponse checkTrafficManage JsonNode reasonValue = responseDoc.get("reason"); if (reasonValue != null && reasonValue instanceof NullNode == false) { Reason reasonInstance; - reasonInstance = Enum.valueOf(Reason.class, reasonValue.getTextValue()); + reasonInstance = EnumUtility.fromString(Reason.class, reasonValue.getTextValue()); result.setReason(reasonInstance); } @@ -368,7 +368,7 @@ public ProfileCreateOrUpdateResponse createOrUpdate(String resourceGroupName, St url = url + "/trafficmanagerprofiles/"; url = url + URLEncoder.encode(profileName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -486,6 +486,10 @@ public ProfileCreateOrUpdateResponse createOrUpdate(String resourceGroupName, St if (endpointsItem.getProperties().getEndpointMonitorStatus() != null) { ((ObjectNode) propertiesValue2).put("endpointMonitorStatus", endpointsItem.getProperties().getEndpointMonitorStatus()); } + + if (endpointsItem.getProperties().getMinChildEndpoints() != null) { + ((ObjectNode) propertiesValue2).put("minChildEndpoints", endpointsItem.getProperties().getMinChildEndpoints()); + } } } ((ObjectNode) propertiesValue).put("endpoints", endpointsArray); @@ -718,6 +722,13 @@ public ProfileCreateOrUpdateResponse createOrUpdate(String resourceGroupName, St endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance2.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue4.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance2.setMinChildEndpoints(minChildEndpointsInstance); + } } } } @@ -847,7 +858,7 @@ public OperationResponse delete(String resourceGroupName, String profileName) th url = url + "/trafficmanagerprofiles/"; url = url + URLEncoder.encode(profileName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -971,7 +982,7 @@ public ProfileGetResponse get(String resourceGroupName, String profileName) thro url = url + "/trafficmanagerprofiles/"; url = url + URLEncoder.encode(profileName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -1188,6 +1199,13 @@ public ProfileGetResponse get(String resourceGroupName, String profileName) thro endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance2.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue2.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance2.setMinChildEndpoints(minChildEndpointsInstance); + } } } } @@ -1298,7 +1316,7 @@ public ProfileListResponse listAll() throws IOException, ServiceException { url = url + "Microsoft.Network"; url = url + "/trafficmanagerprofiles"; ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -1351,13 +1369,13 @@ public ProfileListResponse listAll() throws IOException, ServiceException { } if (responseDoc != null && responseDoc instanceof NullNode == false) { - JsonNode valuesArray = responseDoc.get("values"); - if (valuesArray != null && valuesArray instanceof NullNode == false) { - for (JsonNode valuesValue : ((ArrayNode) valuesArray)) { + JsonNode valueArray = responseDoc.get("value"); + if (valueArray != null && valueArray instanceof NullNode == false) { + for (JsonNode valueValue : ((ArrayNode) valueArray)) { Profile profileInstance = new Profile(); result.getProfiles().add(profileInstance); - JsonNode propertiesValue = valuesValue.get("properties"); + JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { ProfileProperties propertiesInstance = new ProfileProperties(); profileInstance.setProperties(propertiesInstance); @@ -1518,40 +1536,47 @@ public ProfileListResponse listAll() throws IOException, ServiceException { endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance2.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue2.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance2.setMinChildEndpoints(minChildEndpointsInstance); + } } } } } - JsonNode idValue2 = valuesValue.get("id"); + JsonNode idValue2 = valueValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); profileInstance.setId(idInstance2); } - JsonNode nameValue2 = valuesValue.get("name"); + JsonNode nameValue2 = valueValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); profileInstance.setName(nameInstance2); } - JsonNode typeValue2 = valuesValue.get("type"); + JsonNode typeValue2 = valueValue.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); profileInstance.setType(typeInstance2); } - JsonNode locationValue = valuesValue.get("location"); + JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); profileInstance.setLocation(locationInstance); } - JsonNode tagsSequenceElement = ((JsonNode) valuesValue.get("tags")); + JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { @@ -1640,7 +1665,7 @@ public ProfileListResponse listAllInResourceGroup(String resourceGroupName) thro url = url + "Microsoft.Network"; url = url + "/trafficmanagerprofiles"; ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -1693,13 +1718,13 @@ public ProfileListResponse listAllInResourceGroup(String resourceGroupName) thro } if (responseDoc != null && responseDoc instanceof NullNode == false) { - JsonNode valuesArray = responseDoc.get("values"); - if (valuesArray != null && valuesArray instanceof NullNode == false) { - for (JsonNode valuesValue : ((ArrayNode) valuesArray)) { + JsonNode valueArray = responseDoc.get("value"); + if (valueArray != null && valueArray instanceof NullNode == false) { + for (JsonNode valueValue : ((ArrayNode) valueArray)) { Profile profileInstance = new Profile(); result.getProfiles().add(profileInstance); - JsonNode propertiesValue = valuesValue.get("properties"); + JsonNode propertiesValue = valueValue.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { ProfileProperties propertiesInstance = new ProfileProperties(); profileInstance.setProperties(propertiesInstance); @@ -1860,40 +1885,47 @@ public ProfileListResponse listAllInResourceGroup(String resourceGroupName) thro endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance2.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue2.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance2.setMinChildEndpoints(minChildEndpointsInstance); + } } } } } - JsonNode idValue2 = valuesValue.get("id"); + JsonNode idValue2 = valueValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); profileInstance.setId(idInstance2); } - JsonNode nameValue2 = valuesValue.get("name"); + JsonNode nameValue2 = valueValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); profileInstance.setName(nameInstance2); } - JsonNode typeValue2 = valuesValue.get("type"); + JsonNode typeValue2 = valueValue.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); profileInstance.setType(typeInstance2); } - JsonNode locationValue = valuesValue.get("location"); + JsonNode locationValue = valueValue.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); profileInstance.setLocation(locationInstance); } - JsonNode tagsSequenceElement = ((JsonNode) valuesValue.get("tags")); + JsonNode tagsSequenceElement = ((JsonNode) valueValue.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { @@ -2016,7 +2048,7 @@ public ProfileUpdateResponse update(String resourceGroupName, String profileName url = url + "/trafficmanagerprofiles/"; url = url + URLEncoder.encode(profileName, "UTF-8"); ArrayList queryParameters = new ArrayList(); - queryParameters.add("api-version=" + "2015-04-28-preview"); + queryParameters.add("api-version=" + "2015-11-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } @@ -2134,6 +2166,10 @@ public ProfileUpdateResponse update(String resourceGroupName, String profileName if (endpointsItem.getProperties().getEndpointMonitorStatus() != null) { ((ObjectNode) propertiesValue2).put("endpointMonitorStatus", endpointsItem.getProperties().getEndpointMonitorStatus()); } + + if (endpointsItem.getProperties().getMinChildEndpoints() != null) { + ((ObjectNode) propertiesValue2).put("minChildEndpoints", endpointsItem.getProperties().getMinChildEndpoints()); + } } } ((ObjectNode) propertiesValue).put("endpoints", endpointsArray); @@ -2369,6 +2405,13 @@ public ProfileUpdateResponse update(String resourceGroupName, String profileName endpointMonitorStatusInstance = endpointMonitorStatusValue.getTextValue(); propertiesInstance2.setEndpointMonitorStatus(endpointMonitorStatusInstance); } + + JsonNode minChildEndpointsValue = propertiesValue4.get("minChildEndpoints"); + if (minChildEndpointsValue != null && minChildEndpointsValue instanceof NullNode == false) { + long minChildEndpointsInstance; + minChildEndpointsInstance = minChildEndpointsValue.getLongValue(); + propertiesInstance2.setMinChildEndpoints(minChildEndpointsInstance); + } } } } diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClient.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClient.java index 55baf1ae24b8..b269ce989621 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClient.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClient.java @@ -25,7 +25,6 @@ import com.microsoft.windowsazure.core.FilterableService; import com.microsoft.windowsazure.credentials.SubscriptionCloudCredentials; - import java.io.Closeable; import java.net.URI; diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClientImpl.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClientImpl.java index 6b894756e7f5..acc84822e9a2 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClientImpl.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/TrafficManagerManagementClientImpl.java @@ -26,13 +26,12 @@ import com.microsoft.windowsazure.core.ServiceClient; import com.microsoft.windowsazure.credentials.SubscriptionCloudCredentials; import com.microsoft.windowsazure.management.configuration.ManagementConfiguration; -import org.apache.http.impl.client.HttpClientBuilder; - -import javax.inject.Inject; -import javax.inject.Named; import java.net.URI; import java.net.URISyntaxException; import java.util.concurrent.ExecutorService; +import javax.inject.Inject; +import javax.inject.Named; +import org.apache.http.impl.client.HttpClientBuilder; /** * Client for creating, updating, listing and deleting Azure Traffic Manager @@ -142,7 +141,7 @@ public TrafficManagerManagementClientImpl(HttpClientBuilder httpBuilder, Executo super(httpBuilder, executorService); this.endpoints = new EndpointOperationsImpl(this); this.profiles = new ProfileOperationsImpl(this); - this.apiVersion = "2015-04-28-preview"; + this.apiVersion = "2015-11-01"; this.longRunningOperationInitialTimeout = -1; this.longRunningOperationRetryTimeout = -1; } diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/EndpointProperties.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/EndpointProperties.java index 18011c4c9e17..676886ee1449 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/EndpointProperties.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/EndpointProperties.java @@ -87,6 +87,30 @@ public void setEndpointStatus(final String endpointStatusValue) { this.endpointStatus = endpointStatusValue; } + private Long minChildEndpoints; + + /** + * Optional. Gets or sets the minimum number of endpoints that must be + * available in the child profile in order for the parent profile to be + * considered available. Only applicable to endpoint of type + * 'NestedEndpoints'. + * @return The MinChildEndpoints value. + */ + public Long getMinChildEndpoints() { + return this.minChildEndpoints; + } + + /** + * Optional. Gets or sets the minimum number of endpoints that must be + * available in the child profile in order for the parent profile to be + * considered available. Only applicable to endpoint of type + * 'NestedEndpoints'. + * @param minChildEndpointsValue The MinChildEndpoints value. + */ + public void setMinChildEndpoints(final Long minChildEndpointsValue) { + this.minChildEndpoints = minChildEndpointsValue; + } + private Long priority; /** diff --git a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/ProfileListResponse.java b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/ProfileListResponse.java index 30c65bd33acb..515551e463d4 100644 --- a/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/ProfileListResponse.java +++ b/resource-management/azure-mgmt-traffic-manager/src/main/java/com/microsoft/azure/management/trafficmanager/models/ProfileListResponse.java @@ -25,7 +25,6 @@ import com.microsoft.windowsazure.core.LazyArrayList; import com.microsoft.windowsazure.core.OperationResponse; - import java.util.ArrayList; import java.util.Iterator; diff --git a/resource-management/azure-mgmt-utility/pom.xml b/resource-management/azure-mgmt-utility/pom.xml index 1dfac4be3333..9ec42f08aa0c 100644 --- a/resource-management/azure-mgmt-utility/pom.xml +++ b/resource-management/azure-mgmt-utility/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/resource-management/azure-mgmt-websites/pom.xml b/resource-management/azure-mgmt-websites/pom.xml index d83608f3ff36..1faf106eeb83 100644 --- a/resource-management/azure-mgmt-websites/pom.xml +++ b/resource-management/azure-mgmt-websites/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-compute/pom.xml b/service-management/azure-svc-mgmt-compute/pom.xml index aac6ef1a2182..bde2c649f676 100644 --- a/service-management/azure-svc-mgmt-compute/pom.xml +++ b/service-management/azure-svc-mgmt-compute/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-media/pom.xml b/service-management/azure-svc-mgmt-media/pom.xml index e2d03efcb7de..e5b0b3cf3cde 100644 --- a/service-management/azure-svc-mgmt-media/pom.xml +++ b/service-management/azure-svc-mgmt-media/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-network/pom.xml b/service-management/azure-svc-mgmt-network/pom.xml index a5bcbc3d4385..cbe3746ee5d6 100644 --- a/service-management/azure-svc-mgmt-network/pom.xml +++ b/service-management/azure-svc-mgmt-network/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-scheduler/pom.xml b/service-management/azure-svc-mgmt-scheduler/pom.xml index 6ecdc67e9ea1..480fbdd9bd62 100644 --- a/service-management/azure-svc-mgmt-scheduler/pom.xml +++ b/service-management/azure-svc-mgmt-scheduler/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-sql/pom.xml b/service-management/azure-svc-mgmt-sql/pom.xml index d6d4b42271bd..37046bcf4f36 100644 --- a/service-management/azure-svc-mgmt-sql/pom.xml +++ b/service-management/azure-svc-mgmt-sql/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-storage/pom.xml b/service-management/azure-svc-mgmt-storage/pom.xml index 9673664f970e..570d2fa8eeca 100644 --- a/service-management/azure-svc-mgmt-storage/pom.xml +++ b/service-management/azure-svc-mgmt-storage/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt-websites/pom.xml b/service-management/azure-svc-mgmt-websites/pom.xml index 6128c43e8aa7..879e90e137a3 100644 --- a/service-management/azure-svc-mgmt-websites/pom.xml +++ b/service-management/azure-svc-mgmt-websites/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/service-management/azure-svc-mgmt/pom.xml b/service-management/azure-svc-mgmt/pom.xml index 455bff754d58..81e7568c974d 100644 --- a/service-management/azure-svc-mgmt/pom.xml +++ b/service-management/azure-svc-mgmt/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/services/azure-media/pom.xml b/services/azure-media/pom.xml index 1b3b1b49fecd..555581d25c3a 100644 --- a/services/azure-media/pom.xml +++ b/services/azure-media/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml 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..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,47 +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") + + @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 */ @@ -59,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) { @@ -75,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) { @@ -91,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) { @@ -107,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) { @@ -123,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) { @@ -139,11 +146,31 @@ 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 + */ + public OpenIdConnectDiscoveryDocument getOpenIdConnectDiscoveryDocument() { + return openIdConnectDiscoveryDocument; + } + + /** + * @param alternateVerificationKeys + * the alternateVerificationKeys to set + * @return this + */ + 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 561d41554738..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 @@ -3,6 +3,8 @@ import java.io.File; import java.io.StringReader; import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URL; import java.net.URLEncoder; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -37,6 +39,9 @@ private TokenRestrictionTemplateSerializer() { } public static String serialize(TokenRestrictionTemplate template) throws JAXBException { + + validateTokenRestrictionTemplate(template); + StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(TokenRestrictionTemplate.class); Marshaller m = context.createMarshaller(); @@ -44,9 +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 @@ -61,6 +66,31 @@ public String getPreferredPrefix(String namespaceUri, String suggestion, boolean return writer.toString(); } + 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); @@ -79,7 +109,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) { @@ -101,8 +133,8 @@ private static String urlEncode(String toEncode) { } public static String generateTestToken(TokenRestrictionTemplate tokenTemplate, TokenVerificationKey signingKeyToUse, - UUID keyIdForContentKeyIdentifierClaim, Date tokenExpiration, Date notBefore) { - + UUID keyIdForContentKeyIdentifierClaim, Date tokenExpiration, Date notBefore) { + if (tokenTemplate == null) { throw new NullPointerException("tokenTemplate"); } @@ -117,61 +149,63 @@ public static String generateTestToken(TokenRestrictionTemplate tokenTemplate, T cal.add(Calendar.MINUTE, 10); tokenExpiration = cal.getTime(); } - + if (notBefore == null) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MINUTE, -5); notBefore = cal.getTime(); } - + if (tokenTemplate.getTokenType().equals(TokenType.SWT)) { - return generateTestTokenSWT(tokenTemplate, signingKeyToUse, keyIdForContentKeyIdentifierClaim, tokenExpiration); + return generateTestTokenSWT(tokenTemplate, signingKeyToUse, keyIdForContentKeyIdentifierClaim, + tokenExpiration); } else { - return generateTestTokenJWT(tokenTemplate, signingKeyToUse, keyIdForContentKeyIdentifierClaim, tokenExpiration, notBefore); + return generateTestTokenJWT(tokenTemplate, signingKeyToUse, keyIdForContentKeyIdentifierClaim, + tokenExpiration, notBefore); } } - public static String generateTestTokenJWT(TokenRestrictionTemplate tokenTemplate, TokenVerificationKey signingKeyToUse, - UUID keyIdForContentKeyIdentifierClaim, Date tokenExpiration, Date notBefore) { - + public static String generateTestTokenJWT(TokenRestrictionTemplate tokenTemplate, + TokenVerificationKey signingKeyToUse, UUID keyIdForContentKeyIdentifierClaim, Date tokenExpiration, + Date notBefore) { + SymmetricVerificationKey signingKey = (SymmetricVerificationKey) signingKeyToUse; SecretKeySpec secretKey = new SecretKeySpec(signingKey.getKeyValue(), "HmacSHA256"); - + // Mapping Claims. Map 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/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..8e3325cbd8ec --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/AllowedTrackTypes.java @@ -0,0 +1,5 @@ +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..30d03f7a95eb --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/ContentKeySpecs.java @@ -0,0 +1,76 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +import com.fasterxml.jackson.annotation.JsonProperty; + +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 new file mode 100644 index 000000000000..f27b7c490a40 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/Hdcp.java @@ -0,0 +1,5 @@ +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..99b9d474385f --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/RequiredOutputProtection.java @@ -0,0 +1,21 @@ +package com.microsoft.windowsazure.services.media.implementation.templates.widevine; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RequiredOutputProtection { + /** + * 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 new file mode 100644 index 000000000000..d2d383451091 --- /dev/null +++ b/services/azure-media/src/main/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessage.java @@ -0,0 +1,58 @@ +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("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. + */ + @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. + */ + @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/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"); } 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/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()); + } + } } 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..e23d2c7d1d0b --- /dev/null +++ b/services/azure-media/src/test/java/com/microsoft/windowsazure/services/media/implementation/templates/widevine/WidevineMessageSerializerTests.java @@ -0,0 +1,92 @@ +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.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.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.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; diff --git a/services/azure-servicebus/pom.xml b/services/azure-servicebus/pom.xml index a98284996187..a14de6ecba8a 100644 --- a/services/azure-servicebus/pom.xml +++ b/services/azure-servicebus/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerProperties.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerProperties.java index 0654c733315b..bb1ae42148ad 100644 --- a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerProperties.java +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerProperties.java @@ -36,6 +36,12 @@ public class BrokerProperties { @JsonProperty("SessionId") private String sessionId; + @JsonProperty("PartitionKey") + private String partitionKey; + + @JsonProperty("ViaPartitionKey") + private String viaPartitionKey; + @JsonProperty("DeliveryCount") private Integer deliveryCount; @@ -147,6 +153,24 @@ public void setSessionId(String sessionId) { this.sessionId = sessionId; } + @JsonIgnore + public String getPartitionKey() { + return partitionKey; + } + + public void setPartitionKey(String partitionKey) { + this.partitionKey = partitionKey; + } + + @JsonIgnore + public String getViaPartitionKey() { + return partitionKey; + } + + public void setViaPartitionKey(String viaPartitionKey) { + this.viaPartitionKey = viaPartitionKey; + } + @JsonIgnore public String getLabel() { return label; diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerPropertiesMapper.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerPropertiesMapper.java index 6a404f72cd9c..b4c796905966 100644 --- a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerPropertiesMapper.java +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/BrokerPropertiesMapper.java @@ -17,8 +17,10 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; +import java.util.TimeZone; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.JsonParseException; @@ -30,9 +32,7 @@ public class BrokerPropertiesMapper { public BrokerProperties fromString(String value) { ObjectMapper mapper = new ObjectMapper(); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat( - "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); - mapper.setDateFormat(simpleDateFormat); + mapper.setDateFormat(getRFC2616DateFormatter()); try { return mapper.readValue(value.getBytes("UTF-8"), BrokerProperties.class); @@ -47,6 +47,7 @@ public BrokerProperties fromString(String value) { public String toString(BrokerProperties value) { ObjectMapper mapper = new ObjectMapper(); + mapper.setDateFormat(getRFC2616DateFormatter()); Writer writer = new StringWriter(); try { mapper.writeValue(writer, value); @@ -59,5 +60,12 @@ public String toString(BrokerProperties value) { } return writer.toString(); } + + private DateFormat getRFC2616DateFormatter() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat( + "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + return simpleDateFormat; + } } diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/BrokeredMessage.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/BrokeredMessage.java index 488ec022d133..da29dbd9e277 100644 --- a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/BrokeredMessage.java +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/BrokeredMessage.java @@ -349,6 +349,54 @@ public BrokeredMessage setSessionId(String sessionId) { return this; } + /** + * Returns the partition key for the message. + * + * @return A String object that represents the partition key. + * + */ + public String getPartitionKey() { + return brokerProperties.getPartitionKey(); + } + + /** + * Sets the partition key for the message. + * + * @param partitionKey + * A String object that represents the partition key. + * + * @return A Message object that represents the updated + * message. + */ + public BrokeredMessage setPartitionKey(String partitionKey) { + brokerProperties.setPartitionKey(partitionKey); + return this; + } + + /** + * Returns the via partition key for the message. + * + * @return A String object that represents the via partition key. + * + */ + public String getViaPartitionKey() { + return brokerProperties.getViaPartitionKey(); + } + + /** + * Sets the via partition key for the message. + * + * @param viaPartitionKey + * A String object that represents the via partition key. + * + * @return A Message object that represents the updated + * message. + */ + public BrokeredMessage setViaPartitionKey(String viaPartitionKey) { + brokerProperties.setViaPartitionKey(viaPartitionKey); + return this; + } + /** * Returns the label of the message. * diff --git a/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/BrokerPropertiesMapperTest.java b/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/BrokerPropertiesMapperTest.java index 738551198f27..33bebd6407f1 100644 --- a/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/BrokerPropertiesMapperTest.java +++ b/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/BrokerPropertiesMapperTest.java @@ -192,4 +192,21 @@ public void deserializeDateInZhCnLocaleCorrectly() { - lockedUntilUtc.getTime(); assertTrue(Math.abs(lockedUntilDelta) < 2000); } + + @Test + public void dateSerializeCorrectlyToRFC2616() { + // Arrange + BrokerPropertiesMapper mapper = new BrokerPropertiesMapper(); + Date date = new Date(1432120118000L); + + // Act + BrokerProperties properties = new BrokerProperties(); + properties.setScheduledEnqueueTimeUtc(date); + String json = mapper.toString(properties); + + // Assert + assertNotNull(json); + assertEquals("{\"ScheduledEnqueueTimeUtc\":\"Wed, 20 May 2015 11:08:38 GMT\"}", json); + + } } diff --git a/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java b/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java index 11c4980b651c..90e98a25f89b 100644 --- a/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java +++ b/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java @@ -95,8 +95,7 @@ public Client alter(String profile, Client instance, }); // applied as default configuration - Configuration.setInstance(config); - service = ServiceBusService.create(); + service = ServiceBusService.create(config); } @Test diff --git a/services/azure-serviceruntime/pom.xml b/services/azure-serviceruntime/pom.xml index fa8f29f31f96..ce40a046a8e0 100644 --- a/services/azure-serviceruntime/pom.xml +++ b/services/azure-serviceruntime/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../azure/pom.xml diff --git a/services/keyvault/azure-keyvault-core/pom.xml b/services/keyvault/azure-keyvault-core/pom.xml index 585ec507cfce..ae8ade4bab40 100644 --- a/services/keyvault/azure-keyvault-core/pom.xml +++ b/services/keyvault/azure-keyvault-core/pom.xml @@ -18,7 +18,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../../azure/pom.xml diff --git a/services/keyvault/azure-keyvault-extensions/pom.xml b/services/keyvault/azure-keyvault-extensions/pom.xml index 1d636123e9fe..5afdd26c74f3 100644 --- a/services/keyvault/azure-keyvault-extensions/pom.xml +++ b/services/keyvault/azure-keyvault-extensions/pom.xml @@ -18,7 +18,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../../azure/pom.xml @@ -54,10 +54,12 @@ ${project.groupId} azure-keyvault + ${project.version} ${project.groupId} azure-keyvault-core + ${project.version} junit @@ -69,19 +71,38 @@ bcprov-jdk16 test + + + + ${project.groupId} + azure-core-test + ${project.version} + test + + + org.hamcrest + hamcrest-all + test + + + org.mockito + mockito-all + test + + + junit + junit + test + + + org.bouncycastle + bcprov-jdk16 + test + + + com.github.tomakehurst + wiremock + test + - - - - ${project.groupId} - azure-keyvault - ${project.version} - - - ${project.groupId} - azure-keyvault-core - ${project.version} - - - diff --git a/services/keyvault/azure-keyvault-extensions/src/main/java/com/microsoft/azure/keyvault/extensions/KeyVaultKey.java b/services/keyvault/azure-keyvault-extensions/src/main/java/com/microsoft/azure/keyvault/extensions/KeyVaultKey.java index bd85758f8367..998db829fe7d 100644 --- a/services/keyvault/azure-keyvault-extensions/src/main/java/com/microsoft/azure/keyvault/extensions/KeyVaultKey.java +++ b/services/keyvault/azure-keyvault-extensions/src/main/java/com/microsoft/azure/keyvault/extensions/KeyVaultKey.java @@ -81,13 +81,15 @@ protected KeyVaultKey(KeyVaultClient client, KeyBundle keyBundle) { } if (key.getKty().equals(JsonWebKeyType.RSA)) { - _implementation = new RsaKey(keyBundle.getKey()); + // The private key is not available for KeyVault keys + _implementation = new RsaKey(key.getKid(), key.toRSA(false)); } else if (key.getKty().equals(JsonWebKeyType.RSAHSM)) { - _implementation = new RsaKey(keyBundle.getKey()); + // The private key is not available for KeyVault keys + _implementation = new RsaKey(key.getKid(), key.toRSA(false)); } if (_implementation == null) { - throw new IllegalArgumentException(String.format("The key type %s is not supported", keyBundle.getKey().getKty())); + throw new IllegalArgumentException(String.format("The key type %s is not supported", key.getKty())); } _client = client; diff --git a/services/keyvault/azure-keyvault-extensions/src/test/java/com/microsoft/azure/keyvault/extensions/test/KeyVaultExtensionsIntegrationTestBase.java b/services/keyvault/azure-keyvault-extensions/src/test/java/com/microsoft/azure/keyvault/extensions/test/KeyVaultExtensionsIntegrationTestBase.java new file mode 100644 index 000000000000..a323dd6be736 --- /dev/null +++ b/services/keyvault/azure-keyvault-extensions/src/test/java/com/microsoft/azure/keyvault/extensions/test/KeyVaultExtensionsIntegrationTestBase.java @@ -0,0 +1,212 @@ +/** + * + * Copyright (c) Microsoft and contributors. All rights reserved. + * + * 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.azure.keyvault.extensions.test; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.http.Header; +import org.apache.http.message.BasicHeader; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.ObjectReader; +import org.codehaus.jackson.map.ObjectWriter; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import com.microsoft.aad.adal4j.AuthenticationContext; +import com.microsoft.aad.adal4j.AuthenticationResult; +import com.microsoft.aad.adal4j.ClientCredential; +import com.microsoft.azure.keyvault.KeyVaultClient; +import com.microsoft.azure.keyvault.KeyVaultClientService; +import com.microsoft.azure.keyvault.KeyVaultConfiguration; +import com.microsoft.azure.keyvault.authentication.KeyVaultCredentials; +import com.microsoft.windowsazure.Configuration; +import com.microsoft.windowsazure.MockIntegrationTestBase; +import com.microsoft.windowsazure.core.pipeline.filter.ServiceRequestContext; +import com.microsoft.windowsazure.credentials.CloudCredentials; +import com.microsoft.windowsazure.credentials.TokenCloudCredentials; + +public class KeyVaultExtensionsIntegrationTestBase extends MockIntegrationTestBase { + + /** + * The client instance that should be used on tests. + */ + protected static KeyVaultClient keyVaultClient; + + /** + * true if current client instance can handle 401 from service, + * false otherwise. + */ + protected static boolean handling401; + + /** + * Primary vault URI, used for keys and secrets tests. + */ + public static String getVaultUri() { + return IS_MOCKED ? MOCK_URI : getLiveVaultUri1(); + } + + /** + * Secondary vault URI, used to verify ability to transparently authenticate + * against a different resource. + */ + public static String getSecondaryVaultUri() { + return IS_MOCKED ? MOCK_URI : getLiveVaultUri2(); + } + + private static String getLiveVaultUri1() { + return getenvOrDefault("keyvault.vaulturi", "https://javasdktestvault.vault.azure.net"); + } + + private static String getLiveVaultUri2() { + return getenvOrDefault("keyvault.vaulturi.alt", "https://javasdktestvault2.vault.azure.net"); + } + + private static String getenvOrDefault(String varName, String defValue) { + String value = System.getenv(varName); + return value != null ? value : defValue; + } + + protected static void createKeyVaultClient() throws Exception { + Configuration config = createConfiguration(); + + keyVaultClient = KeyVaultClientService.create(config); + addClient(keyVaultClient.getServiceClient(), new Callable() { + @Override + public Void call() throws Exception { + createKeyVaultClient(); + return null; + } + }); + addRegexRule(getLiveVaultUri1(), MOCK_URI); + addRegexRule(getLiveVaultUri2(), MOCK_URI); + } + + public static Configuration createConfiguration() throws Exception { + return KeyVaultConfiguration.configure(null, createTestCredentials()); + } + + private static CloudCredentials createTestCredentials() throws Exception { + + handling401 = false; + + if (IS_MOCKED) { + // When mocked, there's no authentication. + return new TokenCloudCredentials(null, MOCK_SUBSCRIPTION, null); + } + + boolean preAuthenticate = "true".equalsIgnoreCase(System.getenv("arm.preauthenticate")); + + if (preAuthenticate) { + String authorization = System.getenv("arm.aad.url") + System.getenv("arm.tenant"); + String resource = System.getenv("arm.resource"); + String subscriptionId = System.getenv("arm.subscriptionid"); + return new TokenCloudCredentials(null, subscriptionId, getAccessToken(authorization, resource).getAccessToken()); + } + + handling401 = true; + return new KeyVaultCredentials() { + + @Override + public Header doAuthenticate(ServiceRequestContext request, Map challenge) { + try { + String authorization = challenge.get("authorization"); + String resource = challenge.get("resource"); + AuthenticationResult authResult = getAccessToken(authorization, resource); + return new BasicHeader("Authorization", authResult.getAccessTokenType() + " " + authResult.getAccessToken()); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + }; + } + + private static AuthenticationResult getAccessToken(String authorization, String resource) throws Exception { + + String clientId = System.getenv("arm.clientid"); + if (clientId == null) { + throw new Exception("Please inform arm.clientid in the environment settings."); + } + + String clientKey = System.getenv("arm.clientkey"); + String username = System.getenv("arm.username"); + String password = System.getenv("arm.password"); + + AuthenticationResult result = null; + ExecutorService service = null; + try { + service = Executors.newFixedThreadPool(1); + AuthenticationContext context = new AuthenticationContext(authorization, false, service); + + Future future = null; + + if (clientKey != null && password == null) { + ClientCredential credentials = new ClientCredential(clientId, clientKey); + future = context.acquireToken(resource, credentials, null); + } + + if (password != null && clientKey == null) { + future = context.acquireToken(resource, clientId, username, password, null); + } + + if (future == null) { + throw new Exception("Missing or ambiguous credentials - please inform exactly one of arm.clientkey or arm.password in the environment settings."); + } + + result = future.get(); + } finally { + service.shutdown(); + } + + if (result == null) { + throw new RuntimeException("authentication result was null"); + } + return result; + } + + protected static ObjectWriter jsonWriter; + protected static ObjectReader jsonReader; + + @BeforeClass + public static void setup() throws Exception { + createKeyVaultClient(); + jsonWriter = new ObjectMapper().writer().withDefaultPrettyPrinter(); + jsonReader = new ObjectMapper().reader(); + } + + @AfterClass + public static void cleanup() throws Exception { + } + + @Before + public void beforeTest() throws Exception { + setupTest(getClass().getSimpleName() + "-" + name.getMethodName()); + } + + @After + public void afterTest() throws Exception { + resetTest(getClass().getSimpleName() + "-" + name.getMethodName()); + } + +} \ No newline at end of file diff --git a/services/keyvault/azure-keyvault-extensions/src/test/java/com/microsoft/azure/keyvault/extensions/test/KeyVaultKeyResolverTest.java b/services/keyvault/azure-keyvault-extensions/src/test/java/com/microsoft/azure/keyvault/extensions/test/KeyVaultKeyResolverTest.java new file mode 100644 index 000000000000..0cb864e6f61a --- /dev/null +++ b/services/keyvault/azure-keyvault-extensions/src/test/java/com/microsoft/azure/keyvault/extensions/test/KeyVaultKeyResolverTest.java @@ -0,0 +1,268 @@ +package com.microsoft.azure.keyvault.extensions.test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; + +import java.security.NoSuchAlgorithmException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import org.apache.commons.codec.binary.Base64; +import org.junit.Assert; +import org.junit.Test; + +import com.microsoft.azure.keyvault.core.IKey; +import com.microsoft.azure.keyvault.extensions.KeyVaultKeyResolver; +import com.microsoft.azure.keyvault.extensions.SymmetricKey; +import com.microsoft.azure.keyvault.models.KeyBundle; +import com.microsoft.azure.keyvault.models.Secret; + +// +//Copyright © Microsoft Corporation, All Rights Reserved +// +//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 +// +//THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +//OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +//ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +//PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +//See the Apache License, Version 2.0 for the specific language +//governing permissions and limitations under the License. + +public class KeyVaultKeyResolverTest extends KeyVaultExtensionsIntegrationTestBase { + + private static final String KEY_NAME = "JavaExtensionKey"; + private static final String SECRET_NAME = "JavaExtensionSecret"; + + private static final Base64 _base64 = new Base64(-1, null, true); + + @Test + public void KeyVault_KeyVaultKeyResolver_Key() throws InterruptedException, ExecutionException + { + // Create a key on a vault. + Future result = keyVaultClient.createKeyAsync(getVaultUri(), KEY_NAME, "RSA", null, null, null, null); + KeyBundle bundle = result.get(); + + if ( bundle != null ) + { + try + { + // ctor with client + KeyVaultKeyResolver resolver = new KeyVaultKeyResolver( keyVaultClient ); + + Future baseKeyFuture = resolver.resolveKeyAsync( bundle.getKeyIdentifier().getBaseIdentifier() ); + Future versionKeyFuture = resolver.resolveKeyAsync( bundle.getKeyIdentifier().getIdentifier() ); + + IKey baseKey = baseKeyFuture.get(); + IKey versionKey = versionKeyFuture.get(); + + Assert.assertEquals( baseKey.getKid(), versionKey.getKid() ); + } + finally + { + // Delete the key + Future deletedKeyFuture = keyVaultClient.deleteKeyAsync( getVaultUri(), KEY_NAME ); + + deletedKeyFuture.get(); + } + } + } + + /* + * Test resolving a key from a 128bit secret encoded as base64 in a vault using various KeyVaultKeyResolver constructors. + */ + @Test + public void KeyVault_KeyVaultKeyResolver_Secret128Base64() throws InterruptedException, ExecutionException + { + // Arrange + byte[] keyBytes = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; + byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; + byte[] EK = { 0x1F, (byte) 0xA6, (byte) 0x8B, 0x0A, (byte) 0x81, 0x12, (byte) 0xB4, 0x47, (byte) 0xAE, (byte) 0xF3, 0x4B, (byte) 0xD8, (byte) 0xFB, 0x5A, 0x7B, (byte) 0x82, (byte) 0x9D, 0x3E, (byte) 0x86, 0x23, 0x71, (byte) 0xD2, (byte) 0xCF, (byte) 0xE5 }; + + + Future futureSecret = keyVaultClient.setSecretAsync(getVaultUri(), SECRET_NAME, _base64.encodeAsString(keyBytes), "application/octet-stream", null, null ); + Secret secret = futureSecret.get(); + + if ( secret != null ) + { + try + { + // ctor with client + KeyVaultKeyResolver resolver = new KeyVaultKeyResolver( keyVaultClient ); + + IKey baseKey = resolver.resolveKeyAsync( secret.getSecretIdentifier().getBaseIdentifier() ).get(); + IKey versionKey = resolver.resolveKeyAsync( secret.getSecretIdentifier().getIdentifier() ).get(); + + // Check for correct key identifiers + Assert.assertEquals( baseKey.getKid(), versionKey.getKid() ); + + // Ensure key operations give the expected results + byte[] encrypted = null; + + try { + encrypted = baseKey.wrapKeyAsync(CEK, "A128KW").get().getLeft(); + } catch (InterruptedException e) { + fail("InterrupedException"); + } catch (ExecutionException e) { + fail("ExecutionException"); + } catch (NoSuchAlgorithmException e) { + fail("NoSuchAlgorithmException"); + } + + // Assert + assertArrayEquals(EK, encrypted); + + try { + encrypted = versionKey.wrapKeyAsync(CEK, "A128KW").get().getLeft(); + } catch (InterruptedException e) { + fail("InterrupedException"); + } catch (ExecutionException e) { + fail("ExecutionException"); + } catch (NoSuchAlgorithmException e) { + fail("NoSuchAlgorithmException"); + } + + // Assert + assertArrayEquals(EK, encrypted); + } + finally + { + // Delete the key + keyVaultClient.deleteSecretAsync( getVaultUri(), SECRET_NAME ).get(); + } + } + } + + /* + * Test resolving a key from a 128bit secret encoded as base64 in a vault using various KeyVaultKeyResolver constructors. + */ + @Test + public void KeyVault_KeyVaultKeyResolver_Secret192Base64() throws InterruptedException, ExecutionException + { + // Arrange + byte[] keyBytes = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }; + byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; + byte[] EK = { (byte) 0x96, 0x77, (byte) 0x8B, 0x25, (byte) 0xAE, 0x6C, (byte) 0xA4, 0x35, (byte) 0xF9, 0x2B, 0x5B, (byte) 0x97, (byte) 0xC0, 0x50, (byte) 0xAE, (byte) 0xD2, 0x46, (byte) 0x8A, (byte) 0xB8, (byte) 0xA1, 0x7A, (byte) 0xD8, 0x4E, 0x5D }; + + Future futureSecret = keyVaultClient.setSecretAsync(getVaultUri(), SECRET_NAME, _base64.encodeAsString(keyBytes), "application/octet-stream", null, null ); + Secret secret = futureSecret.get(); + + if ( secret != null ) + { + try + { + // ctor with client + KeyVaultKeyResolver resolver = new KeyVaultKeyResolver( keyVaultClient ); + + IKey baseKey = resolver.resolveKeyAsync( secret.getSecretIdentifier().getBaseIdentifier() ).get(); + IKey versionKey = resolver.resolveKeyAsync( secret.getSecretIdentifier().getIdentifier() ).get(); + + // Check for correct key identifiers + Assert.assertEquals( baseKey.getKid(), versionKey.getKid() ); + + // Ensure key operations give the expected results + byte[] encrypted = null; + + try { + encrypted = baseKey.wrapKeyAsync(CEK, "A192KW").get().getLeft(); + } catch (InterruptedException e) { + fail("InterrupedException"); + } catch (ExecutionException e) { + fail("ExecutionException"); + } catch (NoSuchAlgorithmException e) { + fail("NoSuchAlgorithmException"); + } + + // Assert + assertArrayEquals(EK, encrypted); + + try { + encrypted = versionKey.wrapKeyAsync(CEK, "A192KW").get().getLeft(); + } catch (InterruptedException e) { + fail("InterrupedException"); + } catch (ExecutionException e) { + fail("ExecutionException"); + } catch (NoSuchAlgorithmException e) { + fail("NoSuchAlgorithmException"); + } + + // Assert + assertArrayEquals(EK, encrypted); + } + finally + { + // Delete the key + keyVaultClient.deleteSecretAsync( getVaultUri(), SECRET_NAME ).get(); + } + } + } + + /* + * Test resolving a key from a 256bit secret encoded as base64 in a vault using various KeyVaultKeyResolver constructors. + */ + @Test + public void KeyVault_KeyVaultKeyResolver_Secret256Base64() throws InterruptedException, ExecutionException + { + // Arrange + byte[] keyBytes = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; + byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; + byte[] EK = { 0x64, (byte) 0xE8, (byte) 0xC3, (byte) 0xF9, (byte) 0xCE, 0x0F, 0x5B, (byte) 0xA2, 0x63, (byte) 0xE9, 0x77, 0x79, 0x05, (byte) 0x81, (byte) 0x8A, 0x2A, (byte) 0x93, (byte) 0xC8, 0x19, 0x1E, 0x7D, 0x6E, (byte) 0x8A, (byte) 0xE7 }; + + Future futureSecret = keyVaultClient.setSecretAsync(getVaultUri(), SECRET_NAME, _base64.encodeAsString(keyBytes), "application/octet-stream", null, null ); + Secret secret = futureSecret.get(); + + if ( secret != null ) + { + try + { + // ctor with client + KeyVaultKeyResolver resolver = new KeyVaultKeyResolver( keyVaultClient ); + + IKey baseKey = resolver.resolveKeyAsync( secret.getSecretIdentifier().getBaseIdentifier() ).get(); + IKey versionKey = resolver.resolveKeyAsync( secret.getSecretIdentifier().getIdentifier() ).get(); + + // Check for correct key identifiers + Assert.assertEquals( baseKey.getKid(), versionKey.getKid() ); + + // Ensure key operations give the expected results + byte[] encrypted = null; + + try { + encrypted = baseKey.wrapKeyAsync(CEK, "A256KW").get().getLeft(); + } catch (InterruptedException e) { + fail("InterrupedException"); + } catch (ExecutionException e) { + fail("ExecutionException"); + } catch (NoSuchAlgorithmException e) { + fail("NoSuchAlgorithmException"); + } + + // Assert + assertArrayEquals(EK, encrypted); + + try { + encrypted = versionKey.wrapKeyAsync(CEK, "A256KW").get().getLeft(); + } catch (InterruptedException e) { + fail("InterrupedException"); + } catch (ExecutionException e) { + fail("ExecutionException"); + } catch (NoSuchAlgorithmException e) { + fail("NoSuchAlgorithmException"); + } + + // Assert + assertArrayEquals(EK, encrypted); + } + finally + { + // Delete the key + keyVaultClient.deleteSecretAsync( getVaultUri(), SECRET_NAME ).get(); + } + } + } +} diff --git a/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Key.json b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Key.json new file mode 100644 index 000000000000..46bf74ea79b0 --- /dev/null +++ b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Key.json @@ -0,0 +1 @@ +[{"User-Agent":"Azure-SDK-For-Java","Method":"POST","Uri":"/keys/JavaExtensionKey/create?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:25 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"627","x-ms-request-id":"86f8b8be-28c5-46ab-addb-ffc919659157","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"key\":{\"kid\":\"https://javasdktestvault.vault.azure.net/keys/JavaExtensionKey/d782a733999c42628ab0836db22cfc6a\",\"kty\":\"RSA\",\"key_ops\":[\"encrypt\",\"decrypt\",\"sign\",\"verify\",\"wrapKey\",\"unwrapKey\"],\"n\":\"vEbFzqpYU1YRYTGPtB9-4EDZx7OSVUc0BPWQxJloMhW6mplEQ72EWGv5aIK-EMZLsep8XWRHuDWIpuj7Dih-tmW-V5X9bK-kIk-n7hf10IaX9XI5YvjPXm-zazYfEnSZfM4SwYXRPRv-xCJ3wWrM9yeJBIyIyGL8G7Zxmga6cKB8NSa0W_Rxi5xOA2qlRF7e6C5_GlGmiBrySvBGQRvwwASNcb1h1hDY6sAjJaqjvLj90CwynH8AW3N5qjbYar98a8siSUsWAu7uzegJ8YoEqRJ2csb5CeG7_iQf1jeXRlC4hopdxcmldrsTobTkpqS-shuhTewNcWVtzlEgwuv_sw\",\"e\":\"AQAB\"},\"attributes\":{\"enabled\":true,\"created\":1452797245,\"updated\":1452797245}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/keys/JavaExtensionKey/?api-version=2015-06-01"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:25 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"627","x-ms-request-id":"3ae6d897-702f-4f89-8e1a-4aa06c2f055a","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"key\":{\"kid\":\"https://javasdktestvault.vault.azure.net/keys/JavaExtensionKey/d782a733999c42628ab0836db22cfc6a\",\"kty\":\"RSA\",\"key_ops\":[\"encrypt\",\"decrypt\",\"sign\",\"verify\",\"wrapKey\",\"unwrapKey\"],\"n\":\"vEbFzqpYU1YRYTGPtB9-4EDZx7OSVUc0BPWQxJloMhW6mplEQ72EWGv5aIK-EMZLsep8XWRHuDWIpuj7Dih-tmW-V5X9bK-kIk-n7hf10IaX9XI5YvjPXm-zazYfEnSZfM4SwYXRPRv-xCJ3wWrM9yeJBIyIyGL8G7Zxmga6cKB8NSa0W_Rxi5xOA2qlRF7e6C5_GlGmiBrySvBGQRvwwASNcb1h1hDY6sAjJaqjvLj90CwynH8AW3N5qjbYar98a8siSUsWAu7uzegJ8YoEqRJ2csb5CeG7_iQf1jeXRlC4hopdxcmldrsTobTkpqS-shuhTewNcWVtzlEgwuv_sw\",\"e\":\"AQAB\"},\"attributes\":{\"enabled\":true,\"created\":1452797245,\"updated\":1452797245}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/keys/JavaExtensionKey/d782a733999c42628ab0836db22cfc6a/?api-version=2015-06-01"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:25 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"627","x-ms-request-id":"cb343e86-2a84-49f9-8b81-63243c63ba7a","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"key\":{\"kid\":\"https://javasdktestvault.vault.azure.net/keys/JavaExtensionKey/d782a733999c42628ab0836db22cfc6a\",\"kty\":\"RSA\",\"key_ops\":[\"encrypt\",\"decrypt\",\"sign\",\"verify\",\"wrapKey\",\"unwrapKey\"],\"n\":\"vEbFzqpYU1YRYTGPtB9-4EDZx7OSVUc0BPWQxJloMhW6mplEQ72EWGv5aIK-EMZLsep8XWRHuDWIpuj7Dih-tmW-V5X9bK-kIk-n7hf10IaX9XI5YvjPXm-zazYfEnSZfM4SwYXRPRv-xCJ3wWrM9yeJBIyIyGL8G7Zxmga6cKB8NSa0W_Rxi5xOA2qlRF7e6C5_GlGmiBrySvBGQRvwwASNcb1h1hDY6sAjJaqjvLj90CwynH8AW3N5qjbYar98a8siSUsWAu7uzegJ8YoEqRJ2csb5CeG7_iQf1jeXRlC4hopdxcmldrsTobTkpqS-shuhTewNcWVtzlEgwuv_sw\",\"e\":\"AQAB\"},\"attributes\":{\"enabled\":true,\"created\":1452797245,\"updated\":1452797245}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"DELETE","Uri":"/keys/JavaExtensionKey/delete?api-version=2015-06-01"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:26 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"627","x-ms-request-id":"ac7cb421-e450-49f6-a5d9-8199f8727ffd","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"key\":{\"kid\":\"https://javasdktestvault.vault.azure.net/keys/JavaExtensionKey/d782a733999c42628ab0836db22cfc6a\",\"kty\":\"RSA\",\"key_ops\":[\"encrypt\",\"decrypt\",\"sign\",\"verify\",\"wrapKey\",\"unwrapKey\"],\"n\":\"vEbFzqpYU1YRYTGPtB9-4EDZx7OSVUc0BPWQxJloMhW6mplEQ72EWGv5aIK-EMZLsep8XWRHuDWIpuj7Dih-tmW-V5X9bK-kIk-n7hf10IaX9XI5YvjPXm-zazYfEnSZfM4SwYXRPRv-xCJ3wWrM9yeJBIyIyGL8G7Zxmga6cKB8NSa0W_Rxi5xOA2qlRF7e6C5_GlGmiBrySvBGQRvwwASNcb1h1hDY6sAjJaqjvLj90CwynH8AW3N5qjbYar98a8siSUsWAu7uzegJ8YoEqRJ2csb5CeG7_iQf1jeXRlC4hopdxcmldrsTobTkpqS-shuhTewNcWVtzlEgwuv_sw\",\"e\":\"AQAB\"},\"attributes\":{\"enabled\":true,\"created\":1452797245,\"updated\":1452797245}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"}] \ No newline at end of file diff --git a/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret128Base64.json b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret128Base64.json new file mode 100644 index 000000000000..16c3120df337 --- /dev/null +++ b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret128Base64.json @@ -0,0 +1 @@ +[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:26 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"256","x-ms-request-id":"7aab733d-2360-44df-885a-e66280bc1ed1","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODw\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/7109e36e2c674805b977787e22b1d337\",\"attributes\":{\"enabled\":true,\"created\":1452797246,\"updated\":1452797246}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:26 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"256","x-ms-request-id":"14ad569e-47df-4836-a004-a15b8f86089e","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODw\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/7109e36e2c674805b977787e22b1d337\",\"attributes\":{\"enabled\":true,\"created\":1452797246,\"updated\":1452797246}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/secrets/JavaExtensionSecret/7109e36e2c674805b977787e22b1d337?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:26 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"256","x-ms-request-id":"078c50d2-2561-471f-aafb-889e07cb066e","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODw\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/7109e36e2c674805b977787e22b1d337\",\"attributes\":{\"enabled\":true,\"created\":1452797246,\"updated\":1452797246}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"DELETE","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:27 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"223","x-ms-request-id":"bc1fd826-11db-4537-9289-ab130aeb6a19","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/7109e36e2c674805b977787e22b1d337\",\"attributes\":{\"enabled\":true,\"created\":1452797246,\"updated\":1452797246}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"}] \ No newline at end of file diff --git a/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret192Base64.json b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret192Base64.json new file mode 100644 index 000000000000..9809d3342980 --- /dev/null +++ b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret192Base64.json @@ -0,0 +1 @@ +[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:24 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"266","x-ms-request-id":"31bc366b-e124-49f1-bfeb-dc7d4cce25f6","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYX\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/51888ccfeb1d4107b54cb68436ee3c14\",\"attributes\":{\"enabled\":true,\"created\":1452797244,\"updated\":1452797244}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:24 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"266","x-ms-request-id":"8202b6fa-28ca-442c-bef6-95807bc7512b","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYX\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/51888ccfeb1d4107b54cb68436ee3c14\",\"attributes\":{\"enabled\":true,\"created\":1452797244,\"updated\":1452797244}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/secrets/JavaExtensionSecret/51888ccfeb1d4107b54cb68436ee3c14?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:24 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"266","x-ms-request-id":"392d258e-fb03-45f5-9ce4-0ce2d2e96eec","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYX\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/51888ccfeb1d4107b54cb68436ee3c14\",\"attributes\":{\"enabled\":true,\"created\":1452797244,\"updated\":1452797244}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"DELETE","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:24 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"223","x-ms-request-id":"7816c9e6-9bb4-4750-bce6-02a6f13b5bd6","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/51888ccfeb1d4107b54cb68436ee3c14\",\"attributes\":{\"enabled\":true,\"created\":1452797244,\"updated\":1452797244}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"}] \ No newline at end of file diff --git a/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret256Base64.json b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret256Base64.json new file mode 100644 index 000000000000..349f820d802b --- /dev/null +++ b/services/keyvault/azure-keyvault-extensions/src/test/resources/session-records/KeyVaultKeyResolverTest-KeyVault_KeyVaultKeyResolver_Secret256Base64.json @@ -0,0 +1 @@ +[{"User-Agent":"Azure-SDK-For-Java","Method":"PUT","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:23 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"277","x-ms-request-id":"ab3014a6-6e61-406e-879e-46f001f12acb","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/398e67ebd476446f9e222b21ae11c135\",\"attributes\":{\"enabled\":true,\"created\":1452797242,\"updated\":1452797242}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:23 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"277","x-ms-request-id":"d205129f-c400-4b59-9aa9-62a314aff0f8","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/398e67ebd476446f9e222b21ae11c135\",\"attributes\":{\"enabled\":true,\"created\":1452797242,\"updated\":1452797242}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"GET","Uri":"/secrets/JavaExtensionSecret/398e67ebd476446f9e222b21ae11c135?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:23 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"277","x-ms-request-id":"3fa4271d-b080-4e88-ad7b-4dea922dd027","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"value\":\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8\",\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/398e67ebd476446f9e222b21ae11c135\",\"attributes\":{\"enabled\":true,\"created\":1452797242,\"updated\":1452797242}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"},{"User-Agent":"Azure-SDK-For-Java","Method":"DELETE","Uri":"/secrets/JavaExtensionSecret?api-version=2015-06-01","Content-Type":"application/json"},{"Server":"Microsoft-IIS/8.5","Pragma":"no-cache","StatusCode":"200","Date":"Thu, 14 Jan 2016 18:47:23 GMT","Strict-Transport-Security":"max-age=31536000;includeSubDomains","Cache-Control":"no-cache","X-AspNet-Version":"4.0.30319","x-ms-keyvault-region":"westus","Expires":"-1","Content-Length":"223","x-ms-request-id":"a8d2ee5f-9502-4945-9f24-c1489dc7fba7","x-ms-keyvault-service-version":"1.0.0.736","Body":"{\"contentType\":\"application/octet-stream\",\"id\":\"https://javasdktestvault.vault.azure.net/secrets/JavaExtensionSecret/398e67ebd476446f9e222b21ae11c135\",\"attributes\":{\"enabled\":true,\"created\":1452797242,\"updated\":1452797242}}","Content-Type":"application/json; charset=utf-8","X-Powered-By":"ASP.NET"}] \ No newline at end of file diff --git a/services/keyvault/azure-keyvault/pom.xml b/services/keyvault/azure-keyvault/pom.xml index 483bd9c840d0..3ea3e11bd3ac 100644 --- a/services/keyvault/azure-keyvault/pom.xml +++ b/services/keyvault/azure-keyvault/pom.xml @@ -17,7 +17,7 @@ com.microsoft.azure azure - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../../azure/pom.xml diff --git a/services/keyvault/azure-keyvault/src/main/java/com/microsoft/azure/keyvault/authentication/KeyVaultCredentials.java b/services/keyvault/azure-keyvault/src/main/java/com/microsoft/azure/keyvault/authentication/KeyVaultCredentials.java index e1f1637bdad5..65605f1e59f6 100644 --- a/services/keyvault/azure-keyvault/src/main/java/com/microsoft/azure/keyvault/authentication/KeyVaultCredentials.java +++ b/services/keyvault/azure-keyvault/src/main/java/com/microsoft/azure/keyvault/authentication/KeyVaultCredentials.java @@ -30,6 +30,7 @@ import com.microsoft.windowsazure.core.pipeline.filter.ServiceRequestContext; import com.microsoft.windowsazure.core.pipeline.filter.ServiceRequestFilter; import com.microsoft.windowsazure.credentials.CloudCredentials; +import org.apache.http.auth.AUTH; /** * An implementation of {@link CloudCredentials} that supports automatic bearer @@ -38,7 +39,7 @@ */ public abstract class KeyVaultCredentials extends CloudCredentials implements BearerCredentialsSupport { - private static final String AUTH_FILTERS_KEY = "AuthFilters"; + private static final String AUTH_FILTERS_KEY = "AuthFilter"; private final HashMap> cachedChallenges = new HashMap>(); @@ -48,17 +49,7 @@ public void applyConfig(String profile, Map properties) { // Modifies properties to add our authenticating filter. - // First get the existing list of filters... - ArrayList filters; - if (!properties.containsKey(AUTH_FILTERS_KEY)) { - filters = new ArrayList(); - properties.put(AUTH_FILTERS_KEY, filters); - } else { - filters = (ArrayList) properties.get(AUTH_FILTERS_KEY); - } - - // ...then we add our filter. - filters.add(new ServiceRequestFilter() { + properties.put(AUTH_FILTERS_KEY, new ServiceRequestFilter() { @Override public void filter(ServiceRequestContext request) {