updates for keystone V3 auth 96/111696/1
authorBoslet, Cory <cory.boslet@att.com>
Tue, 25 Aug 2020 15:41:22 +0000 (11:41 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Tue, 25 Aug 2020 15:41:23 +0000 (11:41 -0400)
Added additional support, refactored, fixed issues.

Issue-ID: SO-3200
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I7961453598fabd5f68516ad90e20ff848b1a49ba

adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java
adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java
adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoKeystoneV3Utils.java
adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java

index 59c6bec..fa5c57f 100644 (file)
@@ -89,4 +89,23 @@ public final class AuthenticationMethodFactory {
         v3Auth.setScope(scope);
         return v3Auth;
     }
+
+    public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3(
+            CloudIdentity cloudIdentity) {
+        Identity identity = new Identity();
+        Password password = new Password();
+        User user = new User();
+        Domain userDomain = new Domain();
+        userDomain.setName(cloudIdentity.getUserDomainName());
+        user.setName(cloudIdentity.getMsoId());
+        user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass()));
+        user.setDomain(userDomain);
+        password.setUser(user);
+        identity.setPassword(password);
+        identity.setMethods(Collections.singletonList("password"));
+        com.woorea.openstack.keystone.v3.model.Authentication v3Auth =
+                new com.woorea.openstack.keystone.v3.model.Authentication();
+        v3Auth.setIdentity(identity);
+        return v3Auth;
+    }
 }
index 1690695..3564b8f 100644 (file)
@@ -107,7 +107,7 @@ public class KeystoneV3Authentication {
         return policy;
     }
 
-    protected String findEndpointURL(List<Service> serviceCatalog, String type, String region, String facing) {
+    public String findEndpointURL(List<Service> serviceCatalog, String type, String region, String facing) {
         for (Service service : serviceCatalog) {
             if (type.equals(service.getType())) {
                 for (Service.Endpoint endpoint : service.getEndpoints()) {
index 63bc235..072ab5a 100644 (file)
 package org.onap.so.openstack.utils;
 
 import java.util.Map;
+import org.onap.so.cloud.authentication.AuthenticationMethodFactory;
 import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.CloudSite;
 import org.onap.so.openstack.beans.MsoTenant;
 import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
 import org.onap.so.openstack.exceptions.MsoException;
+import org.onap.so.utils.CryptoUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import com.woorea.openstack.keystone.v3.model.Token;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.keystone.v3.Keystone;
+import com.woorea.openstack.keystone.v3.api.TokensResource.Authenticate;
+import com.woorea.openstack.keystone.v3.model.Authentication;
+import com.woorea.openstack.keystone.v3.model.Authentication.Identity;
 
 @Component
 public class MsoKeystoneV3Utils extends MsoTenantUtils {
 
+    @Autowired
+    private AuthenticationMethodFactory authenticationMethodFactory;
+
     @Override
     public String createTenant(String tenantName, String cloudSiteId, Map<String, String> metadata, boolean backout)
             throws MsoException {
@@ -57,4 +71,22 @@ public class MsoKeystoneV3Utils extends MsoTenantUtils {
         return cloudIdentity.getIdentityUrl();
     }
 
+    public Token getKeystoneToken(CloudSite cloudSite) throws MsoException {
+        try {
+            CloudIdentity cloudIdentity = cloudSite.getIdentityService();
+
+            Keystone keystone = new Keystone(cloudIdentity.getIdentityUrl());
+
+            Authentication auth = authenticationMethodFactory.getAuthenticationForV3(cloudIdentity);
+
+            Authenticate authenticate = keystone.tokens().authenticate(auth);
+            return executeAndRecordOpenstackRequest(authenticate);
+
+        } catch (OpenStackResponseException e) {
+            throw keystoneErrorToMsoException(e, "TokenAuth");
+        } catch (OpenStackConnectException e) {
+            throw keystoneErrorToMsoException(e, "TokenAuth");
+        }
+    }
+
 }