Skip to content

Commit

Permalink
Version 1.4.0 of the AWS Java SDK
Browse files Browse the repository at this point in the history
This release adds support for Amazon EC2 default virtual private
clouds. It also adds an easier way to control client endpoints by AWS region.
  • Loading branch information
Zach Musgrave committed Mar 11, 2013
1 parent d1821e9 commit 70840d0
Show file tree
Hide file tree
Showing 2,237 changed files with 12,286 additions and 3,315 deletions.
2 changes: 0 additions & 2 deletions .gitignore
@@ -1,3 +1 @@
target/
.idea
aws-java-sdk.iml
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: AWS SDK for Java
Bundle-SymbolicName: com.amazonaws.sdk;singleton:=true
Bundle-Version: 1.3.33
Bundle-Version: 1.4.0
Bundle-Vendor: Amazon Technologies, Inc
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@
<artifactId>aws-java-sdk</artifactId>
<packaging>jar</packaging>
<name>AWS SDK for Java</name>
<version>1.3.33</version>
<version>1.4.0</version>
<description>The Amazon Web Services SDK for Java provides Java APIs for building software on AWS’ cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).</description>
<url>http://aws.amazon.com/sdkforjava</url>

Expand Down
51 changes: 51 additions & 0 deletions src/main/java/com/amazonaws/AmazonWebServiceClient.java
Expand Up @@ -26,6 +26,8 @@
import com.amazonaws.http.ExecutionContext;
import com.amazonaws.http.HttpMethodName;
import com.amazonaws.http.HttpRequest;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.ServiceAbbreviations;

/**
* Abstract base class for Amazon Web Service Java clients.
Expand Down Expand Up @@ -107,6 +109,55 @@ public void setEndpoint(String endpoint) throws IllegalArgumentException {
throw new IllegalArgumentException(e);
}
}

/**
* An alternative to {@link AmazonDynamoDB#setEndpoint(String)}, sets the
* regional endpoint for this client's service calls. Callers can use this
* method to control which AWS region they want to work with.
* <p>
* <b>This method is not threadsafe. A region should be configured when the
* client is created and before any service requests are made. Changing it
* afterwards creates inevitable race conditions for any service requests in
* transit or retrying.</b>
* <p>
* By default, all service endpoints in all regions use the https protocol.
* To use http instead, specify it in the {@link ClientConfiguration}
* supplied at construction.
*
* @param region
* The region this client will communicate with. See
* {@link Region#getRegion(com.amazonaws.regions.Regions)} for
* accessing a given region.
* @throws java.lang.IllegalArgumentException
* If the given region is null, or if this service isn't
* available in the given region. See
* {@link Region#isServiceSupported(String)}
* @see Region#getRegion(com.amazonaws.regions.Regions)
*/
public void setRegion(Region region) throws IllegalArgumentException {
if ( region == null )
throw new IllegalArgumentException("No region provided");
if ( !region.isServiceSupported(getServiceAbbreviation()) )
throw new IllegalArgumentException(getServiceAbbreviation() + " isn't supported in region "
+ region.getName());
String serviceEndpoint = region.getServiceEndpoint(getServiceAbbreviation());
int protocolIdx = serviceEndpoint.indexOf("://");
// Strip off the protocol to allow the client config to specify it
if ( protocolIdx >= 0 ) {
serviceEndpoint = serviceEndpoint.substring(protocolIdx + "://".length());
}
setEndpoint(serviceEndpoint);
}

/**
* Returns the service abbreviation for this service, used for identifying
* service endpoints by region.
*
* @see ServiceAbbreviations
*/
protected String getServiceAbbreviation() {
return "NO_SERVICE_ABBREVIATION_SPECIFIED";
}

public void setConfiguration(ClientConfiguration clientConfiguration) {
this.clientConfiguration = clientConfiguration;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/amazonaws/auth/AbstractAWSSigner.java
Expand Up @@ -392,8 +392,9 @@ protected String newString(byte[] bytes) {
protected Date getSignatureDate(int timeOffset) {
Date dateValue = new Date();
if (timeOffset != 0) {
long epochSeconds = dateValue.getTime();
dateValue = new Date(epochSeconds-timeOffset);
long epochMillis = dateValue.getTime();
epochMillis -= timeOffset*1000;
dateValue = new Date(epochMillis);
}
return dateValue;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/amazonaws/auth/policy/Condition.java
Expand Up @@ -60,7 +60,7 @@
* should use the many available conditions and condition factories in the
* com.amazonaws.auth.policy.conditions package.
*/
public abstract class Condition {
public class Condition {
protected String type;
protected String conditionKey;
protected List<String> values;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void setType(String type) {
* Your policy is evaluated for each incoming request, and condition keys
* specify what information to pull out of those incoming requests and plug
* into the conditions in your policy.
*
*
* @return The name of the condition key involved in this condition.
*/
public String getConditionKey() {
Expand Down Expand Up @@ -145,16 +145,16 @@ public List<String> getValues() {
public void setValues(List<String> values) {
this.values = values;
}

/**
* Fluent version of {@link Condition#setType(String)}
* @return this
*/
public Condition withType(String type) {
setType(type);
return this;
return this;
}

/**
* Fluent version of {@link Condition#setConditionKey(String)}
* @return this
Expand All @@ -163,7 +163,7 @@ public Condition withConditionKey(String key) {
setConditionKey(key);
return this;
}

/**
* Fluent version of {@link Condition#setValues(List)}
* @return this
Expand All @@ -172,8 +172,8 @@ public Condition withValues(String... values) {
setValues(Arrays.asList(values));
return this;
}


/**
* Fluent version of {@link Condition#setValues(List)}
* @return this
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/com/amazonaws/auth/policy/Policy.java
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Set;

import com.amazonaws.auth.policy.internal.JsonPolicyReader;
import com.amazonaws.auth.policy.internal.JsonPolicyWriter;

/**
Expand Down Expand Up @@ -189,10 +190,10 @@ public void setStatements(Collection<Statement> statements) {
* <p>
* Any statements that don't have a statement ID yet will automatically be
* assigned a unique ID within this policy.
*
*
* @param statements
* The collection of statements included in this policy.
*
*
* @return The updated policy object, so that additional method calls can be
* chained together.
*/
Expand All @@ -212,16 +213,32 @@ public String toJson() {
return new JsonPolicyWriter().writePolicyToString(this);
}

/**
* Returns an AWS access control policy object generated from JSON string.
*
* @param jsonString
* The JSON string representation of this AWS access control policy.
*
* @return An AWS access control policy object.
*
* @throws IllegalArgumentException
* If the specified JSON string is null or invalid and cannot be
* converted to an AWS policy object.
*/
public static Policy fromJson(String jsonString) {
return new JsonPolicyReader().createPolicyFromJsonString(jsonString);
}

private void assignUniqueStatementIds() {
Set<String> usedStatementIds = new HashSet<String>();
for (Statement statement : statements) {
if (statement.getId() != null) usedStatementIds.add(statement.getId());
}

int counter = 0;
for (Statement statement : statements) {
if (statement.getId() != null) continue;

while (usedStatementIds.contains(Integer.toString(++counter)));
statement.setId(Integer.toString(counter));
}
Expand Down
58 changes: 37 additions & 21 deletions src/main/java/com/amazonaws/auth/policy/Principal.java
Expand Up @@ -42,14 +42,14 @@ public class Principal {
private final String id;
private final String provider;

/**
* Constructs a new principal with the specified AWS web service which
* is being allowed or denied access to a resource through an access control
* policy.
*
* @param service
* An AWS service.
*/
/**
* Constructs a new principal with the specified AWS web service which
* is being allowed or denied access to a resource through an access control
* policy.
*
* @param service
* An AWS service.
*/
public Principal(Services service) {
if (service == null) {
throw new IllegalArgumentException("Null AWS service name specified");
Expand Down Expand Up @@ -88,34 +88,50 @@ public String getProvider() {
* @return The unique ID for this principal.
*/
public String getId() {
return id;
return id;
}

/**
* The services who have the right to do the assume the role
* action. The AssumeRole action returns a set of temporary security
* credentials that you can use to access resources that are defined in the
* role's policy. The returned credentials consist of an Access Key ID, a
* Secret Access Key, and a security token.
*/
/**
* The services who have the right to do the assume the role
* action. The AssumeRole action returns a set of temporary security
* credentials that you can use to access resources that are defined in the
* role's policy. The returned credentials consist of an Access Key ID, a
* Secret Access Key, and a security token.
*/
static public enum Services {

AWSDataPipeline("datapipeline.amazonaws.com"),
AmazonElasticTranscoder("elastictranscoder.amazonaws.com"),
AmazonEC2("ec2.amazonaws.com");
AmazonEC2("ec2.amazonaws.com"),
AWSOpsWorks("opsworks.amazonaws.com");
private String serviceId;

/**
* The service which has the right to assume the role.
*/
/**
* The service which has the right to assume the role.
*/
private Services(String serviceId) {
this.serviceId = serviceId;
this.serviceId = serviceId;
}

public String getServiceId() {
return serviceId;
}

/**
* Construct the Services object from a string representing the service id.
*/
public static Services fromString(String serviceId) {
if (serviceId != null) {
for (Services s : Services.values()) {
if (s.getServiceId().equalsIgnoreCase(serviceId)) {
return s;
}
}
}

return null;
}


}

Expand Down
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. 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.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.amazonaws.auth.policy.internal;

public class JsonDocumentFields {
public static final String VERSION = "Version";
public static final String POLICY_ID = "Id";
public static final String STATEMENT = "Statement";
public static final String STATEMENT_EFFECT = "Effect";
public static final String EFFECT_VALUE_ALLOW = "Allow";
public static final String STATEMENT_ID = "Sid";
public static final String PRINCIPAL = "Principal";
public static final String ACTION = "Action";
public static final String RESOURCE = "Resource";
public static final String CONDITION = "Condition";
}

0 comments on commit 70840d0

Please sign in to comment.