diff --git a/provider/partition-gcp/README.md b/provider/partition-gcp/README.md index db161a0bc44fa982e6e0d00676422e97880aa907..ad2876091436f8940b11e3a338e9013cc954c5ca 100644 --- a/provider/partition-gcp/README.md +++ b/provider/partition-gcp/README.md @@ -81,6 +81,7 @@ In order to run the service locally or remotely, you will need to have the follo | `osm.postgres.url` | ex `jdbc:postgresql://127.0.0.1:5432/postgres` | Postgres server URL | no | - | | `osm.postgres.username` | ex `postgres` | Postgres admin username | no | - | | `osm.postgres.password` | ex `postgres` | Postgres admin password | yes | - | +| `ENVIRONMENT` | `gcp` or `anthos` | If `anthos` then authorization is disabled | no | - | ## Configuring mappers' Datasources diff --git a/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AnthosAuthorizationService.java b/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AnthosAuthorizationService.java new file mode 100644 index 0000000000000000000000000000000000000000..68913008c21e8ba1ad564a2ea5c5667be3359b3a --- /dev/null +++ b/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AnthosAuthorizationService.java @@ -0,0 +1,34 @@ +/* + Copyright 2002-2022 Google LLC + Copyright 2002-2022 EPAM Systems, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License 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 org.opengroup.osdu.partition.provider.gcp.security; + +import org.opengroup.osdu.partition.provider.interfaces.IAuthorizationService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +@Component +@RequestScope +@ConditionalOnProperty(name = "environment", havingValue = "anthos") +public class AnthosAuthorizationService implements IAuthorizationService { + + @Override + public boolean isDomainAdminServiceAccount() { + return true; + } +} diff --git a/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationService.java b/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/GcpAuthorizationService.java similarity index 94% rename from provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationService.java rename to provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/GcpAuthorizationService.java index 7c60fad2c8d1ffb11d914653b23cce9a4cd6a0bc..0c2a1398c86a1af2dd0b96562d66eed158be2d08 100644 --- a/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationService.java +++ b/provider/partition-gcp/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/GcpAuthorizationService.java @@ -28,6 +28,7 @@ import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; import org.opengroup.osdu.partition.provider.interfaces.IAuthorizationService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -35,7 +36,8 @@ import org.springframework.web.context.annotation.RequestScope; @Component @RequestScope @RequiredArgsConstructor -public class AuthorizationService implements IAuthorizationService { +@ConditionalOnProperty(name = "environment", havingValue = "gcp") +public class GcpAuthorizationService implements IAuthorizationService { private final PropertiesConfiguration configuration; diff --git a/provider/partition-gcp/src/main/resources/application-osm-postgres.properties b/provider/partition-gcp/src/main/resources/application-osm-postgres.properties index dfc7d8e39d858c746f9b7cc05fa2915f79659f1f..b700407e265a30eab092e0e4118e8c5c40bcfb3f 100644 --- a/provider/partition-gcp/src/main/resources/application-osm-postgres.properties +++ b/provider/partition-gcp/src/main/resources/application-osm-postgres.properties @@ -24,6 +24,7 @@ springfox.documentation.swagger.v2.path=/api-docs authorize-api=https://os-entitlements-gcp-jvmvia5dea-uc.a.run.app/entitlements/v1 spring.cloud.gcp.datastore.namespace=${partition-namespace} #ACCEPT_HTTP=true +environment=gcp cache-expiration=1 cache-maxSize=1000 diff --git a/provider/partition-gcp/src/main/resources/application.properties b/provider/partition-gcp/src/main/resources/application.properties index 096e70d775213022750d7ae00f20f2f3ee051c6a..bce9e7f120286f42f4b2d68458f1d5b0cb8c7a20 100644 --- a/provider/partition-gcp/src/main/resources/application.properties +++ b/provider/partition-gcp/src/main/resources/application.properties @@ -24,6 +24,7 @@ springfox.documentation.swagger.v2.path=/api-docs authorize-api=https://os-entitlements-gcp-jvmvia5dea-uc.a.run.app/entitlements/v1 spring.cloud.gcp.datastore.namespace=${partition-namespace} #ACCEPT_HTTP=true +environment=gcp cache-expiration=1 cache-maxSize=1000 diff --git a/provider/partition-gcp/src/test/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationServiceTest.java b/provider/partition-gcp/src/test/java/org/opengroup/osdu/partition/provider/gcp/security/GcpAuthorizationServiceTest.java similarity index 92% rename from provider/partition-gcp/src/test/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationServiceTest.java rename to provider/partition-gcp/src/test/java/org/opengroup/osdu/partition/provider/gcp/security/GcpAuthorizationServiceTest.java index 93fbdd643d512eb88f47ba9e87f0129d63f79ff5..fc22d404cdce119c110b8833df1b16d23cfae466 100644 --- a/provider/partition-gcp/src/test/java/org/opengroup/osdu/partition/provider/gcp/security/AuthorizationServiceTest.java +++ b/provider/partition-gcp/src/test/java/org/opengroup/osdu/partition/provider/gcp/security/GcpAuthorizationServiceTest.java @@ -44,7 +44,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; @RunWith(Theories.class) -public class AuthorizationServiceTest { +public class GcpAuthorizationServiceTest { private final String token = "abc"; @@ -87,7 +87,7 @@ public class AuthorizationServiceTest { private Payload payload = new Payload(); @InjectMocks - private AuthorizationService authorizationService; + private GcpAuthorizationService gcpAuthorizationService; @Before public void setUp() throws GeneralSecurityException, IOException { @@ -103,25 +103,25 @@ public class AuthorizationServiceTest { @Test public void testProvidedInConfigAdminAccountShouldReturnTrue() { payload.setEmail("service.account@project-id.iam.gserviceaccount.com"); - assertTrue(authorizationService.isDomainAdminServiceAccount()); + assertTrue(gcpAuthorizationService.isDomainAdminServiceAccount()); } @Test(expected = AppException.class) public void testNotProvidedInConfigAdminAccountShouldThrowException() { payload.setEmail("user@google.com"); - authorizationService.isDomainAdminServiceAccount(); + gcpAuthorizationService.isDomainAdminServiceAccount(); } @Theory public void testProvidedInConfigPatternShouldReturnTrue(@FromDataPoints("VALID_ACCOUNTS") String account) { payload.setEmail(account); - assertTrue(authorizationService.isDomainAdminServiceAccount()); + assertTrue(gcpAuthorizationService.isDomainAdminServiceAccount()); } @Theory public void testNotProvidedInConfigPatternShouldReturnTrue(@FromDataPoints("NOT_VALID_ACCOUNTS") String account) { exceptionRule.expect(AppException.class); payload.setEmail(account); - authorizationService.isDomainAdminServiceAccount(); + gcpAuthorizationService.isDomainAdminServiceAccount(); } } \ No newline at end of file