diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java')
-rw-r--r-- | adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java index 49c80b44b5..59c6becfbd 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/AuthenticationMethodFactory.java @@ -21,13 +21,11 @@ package org.onap.so.cloud.authentication; import java.util.Collections; - import org.onap.so.cloud.authentication.models.RackspaceAuthentication; import org.onap.so.db.catalog.beans.AuthenticationType; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.utils.CryptoUtils; import org.springframework.stereotype.Component; - import com.woorea.openstack.keystone.model.Authentication; import com.woorea.openstack.keystone.model.authentication.UsernamePassword; import com.woorea.openstack.keystone.v3.model.Authentication.Identity; @@ -44,44 +42,51 @@ import com.woorea.openstack.keystone.v3.model.Authentication.Scope.Project; @Component public final class AuthenticationMethodFactory { - public final Authentication getAuthenticationFor(CloudIdentity cloudIdentity) { - if (cloudIdentity == null) { - throw new IllegalArgumentException("Cloud identity cannot be null"); - } - if ((cloudIdentity.getIdentityAuthenticationType() == null)|| ("".equals(cloudIdentity.getIdentityAuthenticationType().toString()))) { - throw new IllegalArgumentException("Cloud identity authentication type cannot be null or empty, provided value is " + cloudIdentity.getIdentityAuthenticationType() + "."); - } - AuthenticationType authenticationType = cloudIdentity.getIdentityAuthenticationType(); - if (AuthenticationType.RACKSPACE_APIKEY.equals(authenticationType)) { - return new RackspaceAuthentication (cloudIdentity.getMsoId (), CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass ())); - } else { - return new UsernamePassword (cloudIdentity.getMsoId (), CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass ())); - } - } - - - public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3(CloudIdentity cloudIdentity, String tenantId) { - Identity identity = new Identity(); - Password password = new Password(); - User user = new User(); - Domain userDomain = new Domain(); - Scope scope = new Scope(); - Project project = new Project(); - Project.Domain projectDomain = new Project.Domain(); - userDomain.setName(cloudIdentity.getUserDomainName()); - projectDomain.setName(cloudIdentity.getProjectDomainName()); - user.setName(cloudIdentity.getMsoId()); - user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); - user.setDomain(userDomain); - password.setUser(user); - project.setDomain(projectDomain); - project.setId(tenantId); - scope.setProject(project); - 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); - v3Auth.setScope(scope); - return v3Auth; - } + public final Authentication getAuthenticationFor(CloudIdentity cloudIdentity) { + if (cloudIdentity == null) { + throw new IllegalArgumentException("Cloud identity cannot be null"); + } + if ((cloudIdentity.getIdentityAuthenticationType() == null) + || ("".equals(cloudIdentity.getIdentityAuthenticationType().toString()))) { + throw new IllegalArgumentException( + "Cloud identity authentication type cannot be null or empty, provided value is " + + cloudIdentity.getIdentityAuthenticationType() + "."); + } + AuthenticationType authenticationType = cloudIdentity.getIdentityAuthenticationType(); + if (AuthenticationType.RACKSPACE_APIKEY.equals(authenticationType)) { + return new RackspaceAuthentication(cloudIdentity.getMsoId(), + CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); + } else { + return new UsernamePassword(cloudIdentity.getMsoId(), + CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); + } + } + + + public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3( + CloudIdentity cloudIdentity, String tenantId) { + Identity identity = new Identity(); + Password password = new Password(); + User user = new User(); + Domain userDomain = new Domain(); + Scope scope = new Scope(); + Project project = new Project(); + Project.Domain projectDomain = new Project.Domain(); + userDomain.setName(cloudIdentity.getUserDomainName()); + projectDomain.setName(cloudIdentity.getProjectDomainName()); + user.setName(cloudIdentity.getMsoId()); + user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass())); + user.setDomain(userDomain); + password.setUser(user); + project.setDomain(projectDomain); + project.setId(tenantId); + scope.setProject(project); + 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); + v3Auth.setScope(scope); + return v3Auth; + } } |