Skip to content

Commit 889eda6

Browse files
authored
Merge pull request #72 from oracle/release_2018-07-26
Releasing version 1.2.43
2 parents f8395a9 + e2e5911 commit 889eda6

File tree

56 files changed

+3025
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3025
-134
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1313
### Added
1414
- N/A
1515

16+
## 1.2.43 - 2018-07-26
17+
### Added
18+
- Support for the OCI Search service. An example of how to call this service is available [here](https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/ResourceSearchExample.java)
19+
- Support for specifying a backup policy when creating a boot volume in the Block Storage service
20+
- Support for using the Java SDK in a FIPS compliant environment. Details available [here](https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/javasdk.htm#download)
21+
1622
## 1.2.42 - 2018-07-12
1723
### Added
1824
- Support for tagging Load Balancers in the Load Balancing service

bmc-audit/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.oracle.oci.sdk</groupId>
77
<artifactId>oci-java-sdk</artifactId>
8-
<version>1.2.42</version>
8+
<version>1.2.43</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>com.oracle.oci.sdk</groupId>
2020
<artifactId>oci-java-sdk-common</artifactId>
21-
<version>1.2.42</version>
21+
<version>1.2.43</version>
2222
</dependency>
2323
</dependencies>
2424

bmc-bom/pom.xml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0"?>
1+
<?xml version='1.0' encoding='UTF-8'?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<!-- http://howtodoinjava.com/maven/maven-bom-bill-of-materials-dependency/ -->
55
<parent>
66
<groupId>com.oracle.oci.sdk</groupId>
77
<artifactId>oci-java-sdk</artifactId>
8-
<version>1.2.42</version>
8+
<version>1.2.43</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<artifactId>oci-java-sdk-bom</artifactId>
@@ -19,71 +19,77 @@
1919
<dependency>
2020
<groupId>com.oracle.oci.sdk</groupId>
2121
<artifactId>oci-java-sdk-common</artifactId>
22-
<version>1.2.42</version>
22+
<version>1.2.43</version>
2323
<optional>false</optional>
2424
</dependency>
2525
<!-- Service modules, alpha sorted -->
2626
<dependency>
2727
<groupId>com.oracle.oci.sdk</groupId>
2828
<artifactId>oci-java-sdk-audit</artifactId>
29-
<version>1.2.42</version>
29+
<version>1.2.43</version>
3030
<optional>false</optional>
3131
</dependency>
3232
<dependency>
3333
<groupId>com.oracle.oci.sdk</groupId>
3434
<artifactId>oci-java-sdk-containerengine</artifactId>
35-
<version>1.2.42</version>
35+
<version>1.2.43</version>
3636
<optional>false</optional>
3737
</dependency>
3838
<dependency>
3939
<groupId>com.oracle.oci.sdk</groupId>
4040
<artifactId>oci-java-sdk-core</artifactId>
41-
<version>1.2.42</version>
41+
<version>1.2.43</version>
4242
<optional>false</optional>
4343
</dependency>
4444
<dependency>
4545
<groupId>com.oracle.oci.sdk</groupId>
4646
<artifactId>oci-java-sdk-database</artifactId>
47-
<version>1.2.42</version>
47+
<version>1.2.43</version>
4848
<optional>false</optional>
4949
</dependency>
5050
<dependency>
5151
<groupId>com.oracle.oci.sdk</groupId>
5252
<artifactId>oci-java-sdk-dns</artifactId>
53-
<version>1.2.42</version>
53+
<version>1.2.43</version>
5454
<optional>false</optional>
5555
</dependency>
5656
<dependency>
5757
<groupId>com.oracle.oci.sdk</groupId>
5858
<artifactId>oci-java-sdk-email</artifactId>
59-
<version>1.2.42</version>
59+
<version>1.2.43</version>
6060
<optional>false</optional>
6161
</dependency>
6262
<dependency>
6363
<groupId>com.oracle.oci.sdk</groupId>
6464
<artifactId>oci-java-sdk-filestorage</artifactId>
65-
<version>1.2.42</version>
65+
<version>1.2.43</version>
6666
<optional>false</optional>
6767
</dependency>
6868
<dependency>
6969
<groupId>com.oracle.oci.sdk</groupId>
7070
<artifactId>oci-java-sdk-identity</artifactId>
71-
<version>1.2.42</version>
71+
<version>1.2.43</version>
7272
<optional>false</optional>
7373
</dependency>
7474
<dependency>
7575
<groupId>com.oracle.oci.sdk</groupId>
7676
<artifactId>oci-java-sdk-loadbalancer</artifactId>
77-
<version>1.2.42</version>
77+
<version>1.2.43</version>
7878
<optional>false</optional>
7979
</dependency>
8080
<dependency>
8181
<groupId>com.oracle.oci.sdk</groupId>
8282
<artifactId>oci-java-sdk-objectstorage</artifactId>
83-
<version>1.2.42</version>
83+
<version>1.2.43</version>
8484
<optional>false</optional>
8585
<type>pom</type>
8686
</dependency>
87+
<dependency>
88+
<groupId>com.oracle.oci.sdk</groupId>
89+
<artifactId>oci-java-sdk-resourcesearch</artifactId>
90+
<optional>false</optional>
91+
<version>1.2.43</version>
92+
</dependency>
8793
</dependencies>
8894
</dependencyManagement>
89-
</project>
95+
</project>

bmc-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.oracle.oci.sdk</groupId>
77
<artifactId>oci-java-sdk</artifactId>
8-
<version>1.2.42</version>
8+
<version>1.2.43</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

bmc-common/src/main/java/com/oracle/bmc/auth/internal/AuthUtils.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.bouncycastle.asn1.x500.RDN;
2626
import org.bouncycastle.asn1.x500.X500Name;
2727
import org.bouncycastle.asn1.x500.style.BCStyle;
28-
import org.bouncycastle.jce.PrincipalUtil;
2928
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
3029

3130
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -211,21 +210,15 @@ public static String base64EncodeNoChunking(X509Certificate certificate)
211210
public static String getTenantIdFromCertificate(X509Certificate certificate) {
212211
Preconditions.checkNotNull(certificate);
213212

214-
try {
215-
X500Name name =
216-
X500Name.getInstance(PrincipalUtil.getSubjectX509Principal(certificate));
217-
218-
for (RDN rdn : name.getRDNs(BCStyle.OU)) {
219-
for (AttributeTypeAndValue typeAndValue : rdn.getTypesAndValues()) {
220-
String value = typeAndValue.getValue().toString();
221-
if (value.startsWith("opc-tenant:")) {
222-
return value.substring("opc-tenant:".length());
223-
}
213+
X500Name name = new X500Name(certificate.getSubjectX500Principal().getName());
214+
215+
for (RDN rdn : name.getRDNs(BCStyle.OU)) {
216+
for (AttributeTypeAndValue typeAndValue : rdn.getTypesAndValues()) {
217+
String value = typeAndValue.getValue().toString();
218+
if (value.startsWith("opc-tenant:")) {
219+
return value.substring("opc-tenant:".length());
224220
}
225221
}
226-
} catch (CertificateEncodingException ex) {
227-
throw new InstancePrincipalUnavailableException(
228-
"The certificate is not valid one.", ex);
229222
}
230223

231224
throw new InstancePrincipalUnavailableException(

bmc-common/src/main/java/com/oracle/bmc/http/signing/internal/RequestSignerImpl.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
package com.oracle.bmc.http.signing.internal;
55

6+
import java.io.IOException;
67
import java.io.InputStream;
78
import java.net.URI;
89
import java.nio.charset.StandardCharsets;
@@ -22,6 +23,7 @@
2223
import javax.annotation.concurrent.Immutable;
2324

2425
import com.google.common.annotations.VisibleForTesting;
26+
import com.google.common.io.ByteStreams;
2527
import com.oracle.bmc.http.signing.RequestSignerException;
2628
import org.apache.commons.codec.binary.Base64;
2729
import org.apache.commons.lang3.StringUtils;
@@ -143,7 +145,12 @@ private Map<String, String> signRequest(
143145
// 3) calculate any required headers that are missing
144146
final Map<String, String> missingHeaders =
145147
calculateMissingHeaders(
146-
lowerHttpMethod, uri, existingHeaders, body, requiredHeaders);
148+
lowerHttpMethod,
149+
uri,
150+
existingHeaders,
151+
body,
152+
requiredHeaders,
153+
signingConfiguration);
147154

148155
// 4) create a map containing both existing + missing headers
149156
final Map<String, String> allHeaders = new HashMap<>();
@@ -247,12 +254,14 @@ private static String extractPath(URI uri) {
247254
return path;
248255
}
249256

250-
private Map<String, String> calculateMissingHeaders(
257+
static Map<String, String> calculateMissingHeaders(
251258
final String httpMethod,
252259
final URI uri,
253260
final Map<String, String> existingHeaders,
254261
final Object body,
255-
final List<String> requiredHeaders) {
262+
final List<String> requiredHeaders,
263+
final SigningConfiguration signingConfiguration)
264+
throws IOException {
256265
// all of the required headers that are currently missing
257266
Map<String, String> missingHeaders = new HashMap<>();
258267

@@ -301,21 +310,10 @@ private Map<String, String> calculateMissingHeaders(
301310
if (!existingHeaders.containsKey(Constants.CONTENT_TYPE)) {
302311
LOG.warn("Missing 'content-type' header, defaulting to 'application/json'");
303312
missingHeaders.put(Constants.CONTENT_TYPE, Constants.JSON_CONTENT_TYPE);
304-
} else if (!existingHeaders
305-
.get(Constants.CONTENT_TYPE)
306-
.toLowerCase(Locale.ROOT)
307-
.equals(Constants.JSON_CONTENT_TYPE)) {
308-
throw new IllegalArgumentException(
309-
"Only 'application/json' supported for content type");
310313
}
311314
}
312-
byte[] bodyBytes;
313-
try {
314-
bodyBytes = getJsonBody(body);
315-
} catch (JsonProcessingException e) {
316-
throw new IllegalArgumentException("Unable to process JSON body", e);
317-
}
318315

316+
final byte[] bodyBytes = readBodyBytes(body);
319317
if (isRequiredHeaderMissing(Constants.CONTENT_LENGTH, requiredHeaders, existingHeaders)) {
320318
missingHeaders.put(Constants.CONTENT_LENGTH, Integer.toString(bodyBytes.length));
321319
}
@@ -398,17 +396,19 @@ private List<String> getRequiredSigningHeaders(final String httpMethod) {
398396

399397
// JSON is the only accepted format for message bodies that need to be
400398
// signed.
401-
private static byte[] getJsonBody(Object body) throws JsonProcessingException {
399+
private static byte[] readBodyBytes(Object body) throws IOException {
402400
// empty body is OK
403401
if (body == null) {
404402
return "".getBytes(StandardCharsets.UTF_8);
405403
}
406404
// if already a string, just use it unchanged
407405
if (body instanceof String) {
408406
return ((String) body).getBytes(StandardCharsets.UTF_8);
407+
} else if (body instanceof InputStream) {
408+
return ByteStreams.toByteArray((InputStream) body);
409409
}
410410

411-
throw new IllegalArgumentException("body must be a String");
411+
throw new IllegalArgumentException("Unexpected body type: " + body.getClass().getName());
412412
}
413413

414414
private static String base64Encode(byte[] bytes) {

bmc-common/src/test/java/com/oracle/bmc/http/signing/internal/RequestSignerImplTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
package com.oracle.bmc.http.signing.internal;
55

66
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import com.google.common.collect.ImmutableMap;
78
import com.google.common.collect.Lists;
89
import com.oracle.bmc.http.internal.RestClientFactory;
910
import com.oracle.bmc.http.signing.RequestSignerException;
11+
import com.oracle.bmc.http.signing.SigningStrategy;
1012
import org.junit.Before;
1113
import org.junit.Test;
1214
import org.junit.runner.RunWith;
@@ -17,7 +19,12 @@
1719
import org.slf4j.Logger;
1820
import org.slf4j.LoggerFactory;
1921

22+
import javax.ws.rs.HttpMethod;
23+
import javax.ws.rs.core.HttpHeaders;
2024
import javax.ws.rs.core.MediaType;
25+
import java.io.ByteArrayInputStream;
26+
import java.io.IOException;
27+
import java.net.URI;
2128
import java.util.Collections;
2229
import java.util.HashMap;
2330
import java.util.List;
@@ -37,6 +44,7 @@
3744
@PrepareForTest({LoggerFactory.class, RestClientFactory.class, RequestSignerImpl.class})
3845
public class RequestSignerImplTest {
3946
private static final String SERIALIZED_MAP_JSON_STRING = "{\"header\":[\"value1\",\"value2\"]}";
47+
private static final byte[] BYTE_BUFFER = new byte[8196];
4048

4149
@Mock private Logger mockLogger;
4250
@Mock private ObjectMapper mockObjectMapper;
@@ -112,4 +120,76 @@ public void ignoreCaseHeaders_shouldThrowRequestSignerException_whenDuplicateHea
112120
actaulLogMessageValue.contains("More than one value for header [{}] found."));
113121
}
114122
}
123+
124+
@Test
125+
public void calculateMissingHeaders_postStringContentAsJson() throws IOException {
126+
calculateAndVerifyMissingHeaders(
127+
MediaType.APPLICATION_JSON,
128+
SERIALIZED_MAP_JSON_STRING,
129+
SERIALIZED_MAP_JSON_STRING.length());
130+
}
131+
132+
@Test
133+
public void calculateMissingHeaders_postStringContentAsPlainText() throws IOException {
134+
calculateAndVerifyMissingHeaders(
135+
MediaType.TEXT_PLAIN,
136+
SERIALIZED_MAP_JSON_STRING,
137+
SERIALIZED_MAP_JSON_STRING.length());
138+
}
139+
140+
@Test
141+
public void calculateMissingHeaders_postInputStreamAsOctetStream() throws IOException {
142+
calculateAndVerifyMissingHeaders(
143+
MediaType.APPLICATION_OCTET_STREAM,
144+
new ByteArrayInputStream(BYTE_BUFFER),
145+
BYTE_BUFFER.length);
146+
}
147+
148+
@Test
149+
public void calculateMissingHeaders_postInputStreamAsPlainText() throws IOException {
150+
calculateAndVerifyMissingHeaders(
151+
MediaType.TEXT_PLAIN, new ByteArrayInputStream(BYTE_BUFFER), BYTE_BUFFER.length);
152+
}
153+
154+
@Test(expected = IllegalArgumentException.class)
155+
public void calculateMissingHeaders_invalidBody() throws IOException {
156+
calculateAndVerifyMissingHeaders(MediaType.TEXT_PLAIN, BYTE_BUFFER, BYTE_BUFFER.length);
157+
}
158+
159+
private void calculateAndVerifyMissingHeaders(
160+
final String contentType, final Object body, final int contentLength)
161+
throws IOException {
162+
final URI uri = URI.create("https://identity.us-phoenix-1.oraclecloud.com/20160918/users");
163+
final Map<String, String> existingHeaders =
164+
ImmutableMap.of(
165+
HttpHeaders.CONTENT_TYPE.toLowerCase(),
166+
contentType,
167+
"opc-request-id",
168+
"2F9BA4A30BB3452397A5BC1BFE447C5D",
169+
HttpHeaders.ACCEPT.toLowerCase(),
170+
MediaType.APPLICATION_JSON);
171+
final RequestSignerImpl.SigningConfiguration signingConfiguration =
172+
new RequestSignerImpl.SigningConfiguration(
173+
SigningStrategy.STANDARD.getHeadersToSign(),
174+
SigningStrategy.STANDARD.isSkipContentHeadersForStreamingPutRequests());
175+
final Map<String, String> missingHeaders =
176+
RequestSignerImpl.calculateMissingHeaders(
177+
HttpMethod.POST.toLowerCase(),
178+
uri,
179+
existingHeaders,
180+
body,
181+
Constants.ALL_HEADERS,
182+
signingConfiguration);
183+
assertNotNull(missingHeaders);
184+
assertEquals(4, missingHeaders.size());
185+
assertTrue(missingHeaders.containsKey(HttpHeaders.DATE.toLowerCase()));
186+
assertTrue(missingHeaders.containsKey(HttpHeaders.CONTENT_LENGTH.toLowerCase()));
187+
assertEquals(
188+
Integer.toString(contentLength),
189+
missingHeaders.get(HttpHeaders.CONTENT_LENGTH.toLowerCase()));
190+
assertTrue(missingHeaders.containsKey("x-content-sha256"));
191+
assertEquals(
192+
"identity.us-phoenix-1.oraclecloud.com",
193+
missingHeaders.get(HttpHeaders.HOST.toLowerCase()));
194+
}
115195
}

0 commit comments

Comments
 (0)