Skip to content

Commit

Permalink
Merge pull request #37 from rnagpal/master
Browse files Browse the repository at this point in the history
Java SDK 1.4.0 release
  • Loading branch information
Ryan CrawCour committed Oct 6, 2015
2 parents 1e6fa97 + 25b6147 commit cc3e58e
Show file tree
Hide file tree
Showing 20 changed files with 2,544 additions and 641 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
</classpath>
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>1.2.0</version>
<version>1.4.0</version>
</dependency>

###Option 2: Source Via Git
Expand All @@ -35,6 +35,7 @@ To download a copy of the source code, click "Download ZIP" on the right side of
### Dependencies
* Apache Commons Lang 3.3.2 (org.apache.commons / commons-lang3 / 3.3.2)
* Apache HttpClient 4.2.5 (org.apache.httpcomponents / httpclient / 4.2.5)
* Apache HttpCore 4.2.5 (org.apache.httpcomponents / httpcore / 4.2.5)
* Jackson Data Mapper 1.8 (org.codehaus.jackson / jackson-mapper-asl / 1.8.5)
* JSON 20140107 (org.json / json / 20140107)
* JUnit 4.11 (junit / junit / 4.11)
Expand Down Expand Up @@ -91,7 +92,7 @@ public class SampleApp {
myCollection.setId(COLLECTION_ID);

// Configure the new collection performance tier to S1.
RequestOptions requestOptions = new RequestOptions();
RequestOptions requestOptions = new RequestOptions();
requestOptions.setOfferType("S1");

// Create a new collection.
Expand Down
11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
## Changes in 1.4.0 : ##

- Implement Upsert. New upsertXXX methods added to support Upsert feature.
- Implement ID Based Routing. No public API changes, all changes internal.

## Changes in 1.3.0 : ##

- Release skipped to bring version number in alignment with other SDKs

## Changes in 1.2.0 : ##

- Supports GeoSpatial index.
- Validates resource id.
- Validates id property for all resources. Ids for resources cannot contain ?, /, #, \\, characters or end with a space.
- Adds new header "index transformation progress" to ResourceResponse.

## Changes in 1.1.0 : ##
Expand Down
9 changes: 6 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>1.2.0</version>
<version>1.4.0</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Java SDK for Microsoft Azure DocumentDB</description>
<url>http://azure.microsoft.com/en-us/services/documentdb/</url>
Expand All @@ -13,10 +13,13 @@
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<developers>
<developer>
<name>Pu Shi</name>
<email>pushi@microsoft.com</email>
<name>Rajesh Nagpal</name>
<email>rnagpal@microsoft.com</email>
<organization>Microsoft</organization>
<organizationUrl>http://www.microsoft.com/</organizationUrl>
</developer>
Expand Down
33 changes: 16 additions & 17 deletions src/com/microsoft/azure/documentdb/AuthorizationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ final class AuthorizationHelper {
* This API is a helper method to create auth header based on client request using masterkey.
*
* @param verb the verb.
* @param resourceId the resource id.
* @param resourceIdOrFullName the resource id or full name
* @param resourceType the resource type.
* @param headers the request headers.
* @param masterKey the master key.
* @return the key authorization signature.
*/
public static String GenerateKeyAuthorizationSignature(String verb,
String resourceId,
String resourceIdOrFullName,
ResourceType resourceType,
Map<String, String> headers,
String masterKey) {
if (verb == null || verb.isEmpty()) {
throw new IllegalArgumentException("verb");
}

if (resourceId == null) {
resourceId = "";
if (resourceIdOrFullName == null) {
resourceIdOrFullName = "";
}

if (resourceType == null) {
Expand All @@ -60,26 +60,25 @@ public static String GenerateKeyAuthorizationSignature(String verb,

byte[] decodedBytes = Base64.decodeBase64(masterKey.getBytes());
SecretKey signingKey = new SecretKeySpec(decodedBytes, "HMACSHA256");

String text = String.format("%s\n%s\n%s\n",
verb,
AuthorizationHelper.getResourceSegement(resourceType),
resourceId.toLowerCase());

// Skipping lower casing of resourceId since it may now contain "ID" of the resource as part of the FullName
String body = String.format("%s\n%s\n%s\n",
verb.toLowerCase(),
AuthorizationHelper.getResourceSegement(resourceType).toLowerCase(),
resourceIdOrFullName);

if (headers.containsKey(HttpConstants.HttpHeaders.X_DATE)) {
text += headers.get(HttpConstants.HttpHeaders.X_DATE);
body += headers.get(HttpConstants.HttpHeaders.X_DATE).toLowerCase();
}

text += '\n';
body += '\n';

if (headers.containsKey(HttpConstants.HttpHeaders.HTTP_DATE)) {
text += headers.get(HttpConstants.HttpHeaders.HTTP_DATE);
body += headers.get(HttpConstants.HttpHeaders.HTTP_DATE).toLowerCase();
}

text += '\n';

String body = text.toLowerCase();

body += '\n';

Mac mac = null;
try {
mac = Mac.getInstance("HMACSHA256");
Expand All @@ -96,7 +95,7 @@ public static String GenerateKeyAuthorizationSignature(String verb,

byte[] digest = mac.doFinal(body.getBytes());

String auth = Helper.encodeBase64String(digest);
String auth = Utils.encodeBase64String(digest);

String authtoken = "type=master&ver=1.0&sig=" + auth;

Expand Down
Loading

0 comments on commit cc3e58e

Please sign in to comment.