Skip to content
Snippets Groups Projects
Commit 8eab48b6 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Fixed GcpServiceAccountJwtClient to use it in GC.

parent f3a70c6b
No related branches found
No related tags found
1 merge request!7Fixed GcpServiceAccountJwtClient to use it in GC (GONRG-10278)
Pipeline #293692 passed
......@@ -17,111 +17,104 @@
-->
<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">
<modelVersion>4.0.0</modelVersion>
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>gc-apd</artifactId>
<version>${revision}</version>
</parent>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>gc-apd</artifactId>
<version>${revision}</version>
</parent>
<artifactId>gc-apd-acc</artifactId>
<version>${revision}</version>
<artifactId>gc-apd-acc</artifactId>
<version>${revision}</version>
<properties>
<revision>development-SNAPSHOT</revision>
</properties>
<properties>
<revision>development-SNAPSHOT</revision>
</properties>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>apd-core</artifactId>
<version>0.27.0-rc2</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
<scope>provided</scope>
<version>1.18.28</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>1.24.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>apd-core</artifactId>
<version>0.27.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
<scope>provided</scope>
<version>1.18.28</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>1.24.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- do not deploy reduced pom -->
<createDependencyReducedPom>false</createDependencyReducedPom>
<!-- deploy plugin jar -->
<shadedArtifactAttached>true</shadedArtifactAttached>
<!-- use the classifier to distinct plugin jar and original jar -->
<shadedClassifierName>plugin</shadedClassifierName>
<!-- filter out signatures from signed jars, to prevent SecurityException -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.</pattern>
<shadedPattern>shaded.apd.com.</shadedPattern>
</relocation>
<relocation>
<pattern>io.</pattern>
<shadedPattern>shaded.apd.io.</shadedPattern>
</relocation>
<relocation>
<pattern>org.</pattern>
<shadedPattern>shaded.apd.org.</shadedPattern>
<excludes>
<exclude>org.opengroup.osdu.gc.apd.acc.*</exclude>
</excludes>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- do not deploy reduced pom -->
<createDependencyReducedPom>false</createDependencyReducedPom>
<!-- deploy plugin jar -->
<shadedArtifactAttached>true</shadedArtifactAttached>
<!-- use the classifier to distinct plugin jar and original jar -->
<shadedClassifierName>plugin</shadedClassifierName>
<!-- filter out signatures from signed jars, to prevent SecurityException -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.</pattern>
<shadedPattern>shaded.apd.com.</shadedPattern>
</relocation>
<relocation>
<pattern>io.</pattern>
<shadedPattern>shaded.apd.io.</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -29,7 +29,12 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.auth.TokenProvider;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.gc.apd.acc.config.GcpClientConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class GcpServiceAccountJwtClient implements TokenProvider {
......@@ -48,8 +53,9 @@ public class GcpServiceAccountJwtClient implements TokenProvider {
.build();
}
public GcpServiceAccountJwtClient(String targetAudience) {
this.targetAudience = targetAudience;
@Autowired
public GcpServiceAccountJwtClient(GcpClientConfigurationProperties configurationProperties) {
this.targetAudience = configurationProperties.getGoogleAudiences();
this.setUpDefaultTokenProvider();
this.tokenCredential = IdTokenCredentials.newBuilder()
.setIdTokenProvider(this.idTokenProvider)
......
package org.opengroup.osdu.gc.apd.acc.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Data
@Configuration
@ConfigurationProperties
public class GcpClientConfigurationProperties {
private String googleAudiences;
}
......@@ -17,7 +17,6 @@
package org.opengroup.osdu.gc.apd.acc;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mockStatic;
......@@ -33,6 +32,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.gc.apd.acc.config.GcpClientConfigurationProperties;
@RunWith(MockitoJUnitRunner.class)
public class GcpServiceAccountJwtClientTest {
......@@ -40,14 +40,13 @@ public class GcpServiceAccountJwtClientTest {
private static final String TEST_AUDIENCE = "test-audience";
private static final String TOKEN = "token-value";
@Mock
private CloudShellCredentials userCredentials;
@Mock private CloudShellCredentials userCredentials;
@Mock private IdToken idToken;
@Mock
private IdToken idToken;
@Mock private IdTokenProvider idTokenProvider;
@Mock
private IdTokenProvider idTokenProvider;
@Mock private GcpClientConfigurationProperties configurationProperties;
private GcpServiceAccountJwtClient serviceAccountJwtClient;
......@@ -55,7 +54,10 @@ public class GcpServiceAccountJwtClientTest {
public void shouldThrowExceptionWhenMisconfiguredCredentials() throws IOException {
mockStatic(GoogleCredentials.class);
when(GoogleCredentials.getApplicationDefault()).thenReturn(userCredentials);
serviceAccountJwtClient = new GcpServiceAccountJwtClient(TEST_AUDIENCE);
when(configurationProperties.getGoogleAudiences()).thenReturn(TEST_AUDIENCE);
serviceAccountJwtClient = new GcpServiceAccountJwtClient(configurationProperties);
serviceAccountJwtClient.getDefaultOrInjectedServiceAccountIdToken();
}
......@@ -69,4 +71,4 @@ public class GcpServiceAccountJwtClientTest {
assertEquals(TOKEN, idToken);
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment