Skip to content

Commit 603163c

Browse files
improvements and session based authentication
1 parent a040cf6 commit 603163c

File tree

32 files changed

+225
-1176
lines changed

32 files changed

+225
-1176
lines changed

docs/src/main/asciidoc/_configprops.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
|spring.cloud.oci.config.profile | `DEFAULT` | Name of the profile in OCI Auth config file
88
|spring.cloud.oci.config.file | NA | Location of the OCI Auth config file
9-
|spring.cloud.oci.config.type | FILE | Config/Auth type to be used. Allowed values are FILE, SIMPLE, INSTANCE_PRINCIPAL and RESOURCE_PRINCIPAL
9+
|spring.cloud.oci.config.type | FILE | Config/Auth type to be used. Allowed values are FILE, SIMPLE, INSTANCE_PRINCIPAL, RESOURCE_PRINCIPAL and SESSION_TOKEN
1010
|spring.cloud.oci.config.userId | NA | OCID of the user used for creating the API key. This is needed only if spring.cloud.oci.config.type is `SIMPLE`
1111
|spring.cloud.oci.config.tenantId | NA | Tenancy OCID where the API key is created. This is needed only if spring.cloud.oci.config.type is `SIMPLE`
1212
|spring.cloud.oci.config.fingerprint | NA | Fingerprint for the public key that was added to the user mentioned in `spring.cloud.oci.config.userId`. This is needed only if spring.cloud.oci.config.type is `SIMPLE`

docs/src/main/asciidoc/core.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ spring.cloud.oci.config.type = RESOURCE_PRINCIPAL
7474

7575
For further details, refer to https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/API/Concepts/sdk_authentication_methods.htm#sdk_authentication_methods_resource_principal[OCI Resource Principal Authentication]
7676

77+
==== Session token Configuration
78+
79+
Set the config.type to `SESSION_TOKEN` as shown here.
80+
81+
----
82+
spring.cloud.oci.config.type = SESSION_TOKEN
83+
----
84+
85+
For further details, refer to https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_authentication_methods.htm#ariaid-title12
86+
7787
=== Region Configuration
7888

7989
OCI services are available in different regions. Based on the custom requirements, you can host the application on different OCI regions. The following configuration allows you to set a specific region for the entire application.

pom.xml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Licensed under the Universal Permissive License v 1.0 as shown at https://oss.or
7676
<slf4j-simple.version>1.7.33</slf4j-simple.version>
7777
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
7878
<checksum-maven-plugin.version>1.11</checksum-maven-plugin.version>
79+
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
80+
<cc.code-coverage-ratio>0.00</cc.code-coverage-ratio>
81+
<!--<dependency-check-maven.version>8.4.0</dependency-check-maven.version> -->
7982
</properties>
8083

8184
<dependencyManagement>
@@ -267,7 +270,72 @@ Licensed under the Universal Permissive License v 1.0 as shown at https://oss.or
267270
<groupId>org.apache.maven.plugins</groupId>
268271
<artifactId>maven-surefire-plugin</artifactId>
269272
<version>${maven-surefire-plugin.version}</version>
273+
<configuration>
274+
<argLine>${argLine} -Xmx2048m</argLine>
275+
</configuration>
270276
</plugin>
277+
<plugin>
278+
<groupId>org.jacoco</groupId>
279+
<artifactId>jacoco-maven-plugin</artifactId>
280+
<version>${jacoco-maven-plugin.version}</version>
281+
<configuration>
282+
<outputDirectory>${project.build.directory}/jacoco-reports</outputDirectory>
283+
<excludes>
284+
<exclude>com/oracle/cloud/spring/sample/**</exclude>
285+
</excludes>
286+
</configuration>
287+
<executions>
288+
<execution>
289+
<id>default-prepare-agent</id>
290+
<goals>
291+
<goal>prepare-agent</goal>
292+
</goals>
293+
</execution>
294+
<execution>
295+
<id>default-report</id>
296+
<goals>
297+
<goal>report</goal>
298+
</goals>
299+
</execution>
300+
<execution>
301+
<id>default-check</id>
302+
<goals>
303+
<goal>check</goal>
304+
</goals>
305+
<configuration>
306+
<rules>
307+
<rule implementation="org.jacoco.maven.RuleConfiguration">
308+
<element>BUNDLE</element>
309+
<limits>
310+
<limit implementation="org.jacoco.report.check.Limit">
311+
<counter>INSTRUCTION</counter>
312+
<value>COVEREDRATIO</value>
313+
<minimum>${cc.code-coverage-ratio}</minimum>
314+
</limit>
315+
</limits>
316+
</rule>
317+
</rules>
318+
</configuration>
319+
</execution>
320+
</executions>
321+
</plugin>
322+
<!-- Plugin for dependency check -->
323+
<!--<plugin>
324+
<groupId>org.owasp</groupId>
325+
<artifactId>dependency-check-maven</artifactId>
326+
<version>${dependency-check-maven.version}</version>
327+
<configuration>
328+
<failBuildOnCVSS>8</failBuildOnCVSS>
329+
<skipProvidedScope>true</skipProvidedScope>
330+
</configuration>
331+
<executions>
332+
<execution>
333+
<goals>
334+
<goal>check</goal>
335+
</goals>
336+
</execution>
337+
</executions>
338+
</plugin> -->
271339
</plugins>
272340
</build>
273341
<profiles>
@@ -286,4 +354,4 @@ Licensed under the Universal Permissive License v 1.0 as shown at https://oss.or
286354
</build>
287355
</profile>
288356
</profiles>
289-
</project>
357+
</project>

spring-cloud-oci-autoconfigure/src/main/java/com/oracle/cloud/spring/autoconfigure/core/CredentialsProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public enum ConfigType {
2222
FILE,
2323
INSTANCE_PRINCIPAL,
2424
RESOURCE_PRINCIPAL,
25-
SIMPLE
25+
SIMPLE,
26+
SESSION_TOKEN
2627
}
2728

2829
@Nullable

spring-cloud-oci-autoconfigure/src/main/java/com/oracle/cloud/spring/autoconfigure/core/CredentialsProviderAutoConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.oracle.bmc.auth.ResourcePrincipalAuthenticationDetailsProvider;
1515
import com.oracle.bmc.auth.SimpleAuthenticationDetailsProvider;
1616
import com.oracle.bmc.auth.SimplePrivateKeySupplier;
17+
import com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider;
1718
import org.springframework.boot.autoconfigure.AutoConfiguration;
1819
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1920
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -76,6 +77,15 @@ public static BasicAuthenticationDetailsProvider createCredentialsProvider(Crede
7677
}
7778
authenticationDetailsProvider = builder.build();
7879
break;
80+
case SESSION_TOKEN:
81+
String configProfile = properties.hasProfile() ? properties.getProfile() : PROFILE_DEFAULT;
82+
83+
if (properties.hasFile()) {
84+
authenticationDetailsProvider = new SessionTokenAuthenticationDetailsProvider(properties.getFile(), configProfile);
85+
} else {
86+
authenticationDetailsProvider = new SessionTokenAuthenticationDetailsProvider(configProfile);
87+
}
88+
break;
7989
default:
8090
String profile = properties.hasProfile() ? properties.getProfile() : PROFILE_DEFAULT;
8191

spring-cloud-oci-autoconfigure/src/test/java/com/oracle/cloud/spring/autoconfigure/core/CompartmentProviderAutoConfigurationTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import org.junit.jupiter.api.Test;
99
import org.springframework.boot.autoconfigure.AutoConfigurations;
1010
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
11-
import org.springframework.util.Assert;
11+
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
1214

1315
class CompartmentProviderAutoConfigurationTests {
1416
private final ApplicationContextRunner contextRunner =
@@ -21,8 +23,8 @@ void testConfigurationValueDefaultsAreAsExpected() {
2123
.run(
2224
context -> {
2325
CompartmentProperties config = context.getBean(CompartmentProperties.class);
24-
Assert.isTrue(config.getStatic() == null);
25-
Assert.isTrue(!config.isStatic());
26+
assertEquals(config.getStatic(), null);
27+
assertEquals(config.isStatic(), false);
2628
});
2729
}
2830

@@ -33,8 +35,8 @@ void testConfigurationValueConfiguredAreAsExpected() {
3335
.run(
3436
context -> {
3537
CompartmentProperties config = context.getBean(CompartmentProperties.class);
36-
Assert.isTrue(config.getStatic().equals("demoCompartment"));
37-
Assert.isTrue(config.isStatic());
38+
assertEquals(config.getStatic(), "demoCompartment");
39+
assertEquals(config.isStatic(), true);
3840
});
3941
}
4042
}

spring-cloud-oci-autoconfigure/src/test/java/com/oracle/cloud/spring/autoconfigure/core/CredentialsProviderAutoConfigurationTests.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
1212
import org.springframework.context.annotation.Bean;
1313
import org.springframework.context.annotation.Configuration;
14-
import org.springframework.util.Assert;
1514

1615
import static org.mockito.Mockito.mock;
17-
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
1819
class CredentialsProviderAutoConfigurationTests {
1920
private final ApplicationContextRunner contextRunner =
2021
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(
@@ -26,9 +27,9 @@ void testConfigurationValueDefaultsAreAsExpected() {
2627
.run(
2728
context -> {
2829
CredentialsProperties config = context.getBean(CredentialsProperties.class);
29-
Assert.isTrue(config.getTenantId() == null);
30-
Assert.isTrue(config.getType() != null);
31-
Assert.isTrue(config.getType() == CredentialsProperties.ConfigType.FILE);
30+
assertNull(config.getTenantId());
31+
assertNotNull(config.getType());
32+
assertEquals(config.getType(), CredentialsProperties.ConfigType.FILE);
3233
});
3334
}
3435

@@ -47,15 +48,15 @@ void testConfigurationValueConfiguredAreAsExpected() {
4748
.run(
4849
context -> {
4950
CredentialsProperties config = context.getBean(CredentialsProperties.class);
50-
Assert.isTrue(config.getType() == CredentialsProperties.ConfigType.SIMPLE);
51-
Assert.isTrue(config.getUserId().equals("userId"));
52-
Assert.isTrue(config.getTenantId().equals("tenantId"));
53-
Assert.isTrue(config.getFingerprint().equals("fingerprint"));
54-
Assert.isTrue(config.getPrivateKey().equals("privateKey"));
55-
Assert.isTrue(config.getProfile().equals("profile"));
56-
Assert.isTrue(config.getFile().equals("file"));
57-
Assert.isTrue(config.getPassPhrase().equals("passPhrase"));
58-
Assert.isTrue(config.getRegion().equals("region"));
51+
assertEquals(config.getType(), CredentialsProperties.ConfigType.SIMPLE);
52+
assertEquals(config.getUserId(), "userId");
53+
assertEquals(config.getTenantId(), "tenantId");
54+
assertEquals(config.getFingerprint(), "fingerprint");
55+
assertEquals(config.getPrivateKey(), "privateKey");
56+
assertEquals(config.getProfile(), "profile");
57+
assertEquals(config.getFile(), "file");
58+
assertEquals(config.getPassPhrase(), "passPhrase");
59+
assertEquals(config.getRegion(), "region");
5960
});
6061
}
6162

spring-cloud-oci-autoconfigure/src/test/java/com/oracle/cloud/spring/autoconfigure/core/RegionProviderAutoConfigurationTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import org.junit.jupiter.api.Test;
99
import org.springframework.boot.autoconfigure.AutoConfigurations;
1010
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
11-
import org.springframework.util.Assert;
1211

12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertNull;
1315
class RegionProviderAutoConfigurationTests {
1416
private final ApplicationContextRunner contextRunner =
1517
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(
@@ -21,8 +23,8 @@ void testConfigurationValueDefaultsAreAsExpected() {
2123
.run(
2224
context -> {
2325
RegionProperties config = context.getBean(RegionProperties.class);
24-
Assert.isTrue(!config.isStatic());
25-
Assert.isTrue(config.getStatic() == null);
26+
assertEquals(config.isStatic(), false);
27+
assertNull(config.getStatic());
2628
});
2729
}
2830

@@ -33,8 +35,8 @@ void testConfigurationValueConfiguredAreAsExpected() {
3335
.run(
3436
context -> {
3537
RegionProperties config = context.getBean(RegionProperties.class);
36-
Assert.isTrue(config.getStatic().equals("us-phoenix-1"));
37-
Assert.isTrue(config.isStatic());
38+
assertEquals(config.getStatic(), "us-phoenix-1");
39+
assertEquals(config.isStatic(), true);
3840
});
3941
}
4042
}

spring-cloud-oci-autoconfigure/src/test/java/com/oracle/cloud/spring/logging/LoggingAutoConfigurationTests.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
1313
import org.springframework.context.annotation.Bean;
1414
import org.springframework.context.annotation.Configuration;
15-
import org.springframework.util.Assert;
15+
1616

1717
import static org.mockito.Mockito.mock;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
1822

1923
class LoggingAutoConfigurationTests {
2024
private final ApplicationContextRunner contextRunner =
@@ -28,7 +32,7 @@ void testConfigurationValueDefaultsAreAsExpected() {
2832
.run(
2933
context -> {
3034
LoggingProperties config = context.getBean(LoggingProperties.class);
31-
Assert.isTrue(config.getLogId() == null);
35+
assertNull(config.getLogId());
3236
});
3337
}
3438

@@ -39,7 +43,7 @@ void testConfigurationValueConfiguredAreAsExpected() {
3943
.run(
4044
context -> {
4145
LoggingProperties config = context.getBean(LoggingProperties.class);
42-
Assert.isTrue(config.getLogId().equals("demoLogId"));
46+
assertEquals(config.getLogId(), "demoLogId");
4347
});
4448
}
4549

@@ -49,9 +53,9 @@ void testConfigurationDefaultsAreAsExpected() {
4953
.run(
5054
context -> {
5155
String[] logServiceBeanNames = context.getBeanNamesForType(LogService.class);
52-
Assert.isTrue(logServiceBeanNames.length > 0);
56+
assertTrue(logServiceBeanNames.length > 0);
5357
LogService logService = context.getBean(LogService.class);
54-
Assert.isTrue(logService != null);
58+
assertNotNull(logService);
5559
});
5660
}
5761

@@ -62,7 +66,7 @@ void testConfigurationConfiguredAreAsExpected() {
6266
.run(
6367
context -> {
6468
String[] logServiceBeanNames = context.getBeanNamesForType(LogService.class);
65-
Assert.isTrue(logServiceBeanNames.length == 0);
69+
assertEquals(logServiceBeanNames.length, 0);
6670
});
6771
}
6872

spring-cloud-oci-autoconfigure/src/test/java/com/oracle/cloud/spring/notification/NotificationAutoConfigurationTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
1414
import org.springframework.context.annotation.Bean;
1515
import org.springframework.context.annotation.Configuration;
16-
import org.springframework.util.Assert;
16+
1717

1818
import static org.mockito.Mockito.mock;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
1922

2023
class NotificationAutoConfigurationTests {
2124
private final ApplicationContextRunner contextRunner =
@@ -29,9 +32,9 @@ void testConfigurationDefaultsAreAsExpected() {
2932
.run(
3033
context -> {
3134
String[] notificationBeanNames = context.getBeanNamesForType(Notification.class);
32-
Assert.isTrue(notificationBeanNames.length > 0);
35+
assertTrue(notificationBeanNames.length > 0);
3336
Notification notification = context.getBean(Notification.class);
34-
Assert.isTrue(notification != null);
37+
assertNotNull(notification);
3538
});
3639
}
3740

@@ -42,7 +45,7 @@ void testConfigurationConfiguredAreAsExpected() {
4245
.run(
4346
context -> {
4447
String[] notificationBeanNames = context.getBeanNamesForType(Notification.class);
45-
Assert.isTrue(notificationBeanNames.length == 0);
48+
assertEquals(notificationBeanNames.length, 0);
4649
});
4750
}
4851

0 commit comments

Comments
 (0)