From 72e273685919b77fe16768dcf8076bf5caf01f52 Mon Sep 17 00:00:00 2001
From: Aman Verma <amaverma@microsoft.com>
Date: Wed, 10 Feb 2021 11:01:49 +0530
Subject: [PATCH] removing primary bean

---
 .../azure/config/AzureBootstrapConfig.java    |  18 +++
 .../azure/di/EntitlementsFactoryAzure.java    |  30 -----
 .../azure/di/EntitlementsServiceAzure.java    | 110 ------------------
 3 files changed, 18 insertions(+), 140 deletions(-)
 delete mode 100644 provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java
 delete mode 100644 provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java

diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java
index 09f69ecde..570b932a2 100644
--- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java
+++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java
@@ -16,6 +16,9 @@ package org.opengroup.osdu.indexer.azure.config;
 
 import com.azure.security.keyvault.secrets.SecretClient;
 import org.opengroup.osdu.azure.KeyVaultFacade;
+import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig;
+import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory;
+import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
@@ -37,6 +40,12 @@ public class AzureBootstrapConfig {
     @Value("${MAX_CACHE_VALUE_SIZE}")
     private Integer maxCacheValueSize;
 
+    @Value("${AUTHORIZE_API_KEY}")
+    private String entitlementsAPIKey;
+
+    @Value("${AUTHORIZE_API}")
+    private String entitlementsAPIEndpoint;
+
     @Bean
     @Named("KEY_VAULT_URL")
     public String getKeyVaultURL() {
@@ -80,4 +89,13 @@ public class AzureBootstrapConfig {
         String tenant = KeyVaultFacade.getSecretWithValidation(sc, "app-dev-sp-tenant-id");
         return String.format(urlFormat, tenant);
     }
+
+    @Bean
+    public IEntitlementsFactory entitlementsFactory() {
+        EntitlementsAPIConfig apiConfig = EntitlementsAPIConfig.builder()
+                .apiKey(entitlementsAPIKey)
+                .rootUrl(entitlementsAPIEndpoint)
+                .build();
+        return new EntitlementsFactory(apiConfig);
+    }
 }
diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java
deleted file mode 100644
index 63e268a87..000000000
--- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright © Microsoft Corporation
-//
-// 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.indexer.azure.di;
-
-import org.opengroup.osdu.core.common.model.http.DpsHeaders;
-import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
-import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
-import org.springframework.context.annotation.Primary;
-import org.springframework.stereotype.Component;
-
-@Component
-@Primary
-public class EntitlementsFactoryAzure implements IEntitlementsFactory {
-    @Override
-    public IEntitlementsService create(DpsHeaders dpsHeaders) {
-        return new EntitlementsServiceAzure(dpsHeaders);
-    }
-}
diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java
deleted file mode 100644
index 05370bd83..000000000
--- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java
+++ /dev/null
@@ -1,110 +0,0 @@
-//  Copyright © Microsoft Corporation
-//
-//  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.indexer.azure.di;
-
-import com.microsoft.azure.spring.autoconfigure.aad.UserPrincipal;
-import org.apache.http.HttpStatus;
-
-import org.opengroup.osdu.core.common.model.entitlements.*;
-import org.opengroup.osdu.core.common.model.http.DpsHeaders;
-import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
-import org.opengroup.osdu.core.common.http.HttpResponse;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class EntitlementsServiceAzure implements IEntitlementsService {
-    //service principals don't have UPN or email
-    static final String INTEGRATION_TEST_ADMIN_ROLE = "data.test.admin@opendes.onmicrosoft.com";
-    public static final String PREFIX = "ROLE_";
-    DpsHeaders headers;
-
-    public EntitlementsServiceAzure(DpsHeaders headers){
-        this.headers = headers;
-    }
-
-    @Override
-    public MemberInfo addMember(GroupEmail groupEmail, MemberInfo memberInfo) throws EntitlementsException {
-        return null;
-    }
-
-    @Override
-    public Members getMembers(GroupEmail groupEmail, GetMembers getMembers) throws EntitlementsException {
-        return null;
-    }
-
-    @Override
-    public Groups getGroups() throws EntitlementsException {
-        final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
-        final UserPrincipal current = (UserPrincipal) auth.getPrincipal();
-        String email = current.getUpn();
-
-        List<GroupInfo> giList = new ArrayList();
-        Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
-        for(GrantedAuthority authority : authorities)
-        {
-            GroupInfo gi = new GroupInfo();
-            String role = authority.getAuthority();
-            if (role.startsWith(PREFIX)){
-                role = role.substring(PREFIX.length());
-            }
-            gi.setName(role);
-            if ((email == null || email.isEmpty()) && role.equalsIgnoreCase(INTEGRATION_TEST_ADMIN_ROLE)) {
-                email = INTEGRATION_TEST_ADMIN_ROLE;
-                gi.setEmail(email);
-                giList.add(0, gi);
-            }
-            else {
-                gi.setEmail(email);
-                giList.add(gi);
-            }
-        }
-        if (giList.size() > 0)
-        {
-            Groups groups = new Groups();
-            groups.setGroups(giList);
-            groups.setDesId(email);
-            return groups;
-        }
-
-        HttpResponse response = new HttpResponse();
-        response.setResponseCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
-        throw new EntitlementsException("no authorities found", response);
-    }
-
-    @Override
-    public GroupInfo createGroup(CreateGroup createGroup) throws EntitlementsException {
-        return null;
-    }
-
-    @Override
-    public void deleteMember(String s, String s1) throws EntitlementsException {
-
-    }
-
-    @Override
-    public Groups authorizeAny(String... strings) throws EntitlementsException {
-        return null;
-    }
-
-    @Override
-    public void authenticate() throws EntitlementsException {
-
-    }
-}
-- 
GitLab