2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.cloud.authentication;
23 import java.util.Collections;
24 import org.onap.so.cloud.authentication.models.RackspaceAuthentication;
25 import org.onap.so.db.catalog.beans.AuthenticationType;
26 import org.onap.so.db.catalog.beans.CloudIdentity;
27 import org.onap.so.utils.CryptoUtils;
28 import org.springframework.stereotype.Component;
29 import com.woorea.openstack.keystone.model.Authentication;
30 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
31 import com.woorea.openstack.keystone.v3.model.Authentication.Identity;
32 import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password;
33 import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.User;
34 import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.User.Domain;
35 import com.woorea.openstack.keystone.v3.model.Authentication.Scope;
36 import com.woorea.openstack.keystone.v3.model.Authentication.Scope.Project;
39 * This factory manages all the wrappers associated to authentication types.
43 public final class AuthenticationMethodFactory {
45 public final Authentication getAuthenticationFor(CloudIdentity cloudIdentity) {
46 if (cloudIdentity == null) {
47 throw new IllegalArgumentException("Cloud identity cannot be null");
49 if ((cloudIdentity.getIdentityAuthenticationType() == null)
50 || ("".equals(cloudIdentity.getIdentityAuthenticationType().toString()))) {
51 throw new IllegalArgumentException(
52 "Cloud identity authentication type cannot be null or empty, provided value is "
53 + cloudIdentity.getIdentityAuthenticationType() + ".");
55 AuthenticationType authenticationType = cloudIdentity.getIdentityAuthenticationType();
56 if (AuthenticationType.RACKSPACE_APIKEY.equals(authenticationType)) {
57 return new RackspaceAuthentication(cloudIdentity.getMsoId(),
58 CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass()));
60 return new UsernamePassword(cloudIdentity.getMsoId(),
61 CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass()));
66 public final com.woorea.openstack.keystone.v3.model.Authentication getAuthenticationForV3(
67 CloudIdentity cloudIdentity, String tenantId) {
68 Identity identity = new Identity();
69 Password password = new Password();
70 User user = new User();
71 Domain userDomain = new Domain();
72 Scope scope = new Scope();
73 Project project = new Project();
74 Project.Domain projectDomain = new Project.Domain();
75 userDomain.setName(cloudIdentity.getUserDomainName());
76 projectDomain.setName(cloudIdentity.getProjectDomainName());
77 user.setName(cloudIdentity.getMsoId());
78 user.setPassword(CryptoUtils.decryptCloudConfigPassword(cloudIdentity.getMsoPass()));
79 user.setDomain(userDomain);
80 password.setUser(user);
81 project.setDomain(projectDomain);
82 project.setId(tenantId);
83 scope.setProject(project);
84 identity.setPassword(password);
85 identity.setMethods(Collections.singletonList("password"));
86 com.woorea.openstack.keystone.v3.model.Authentication v3Auth =
87 new com.woorea.openstack.keystone.v3.model.Authentication();
88 v3Auth.setIdentity(identity);
89 v3Auth.setScope(scope);