2 * ============LICENSE_START==========================================
3 * ===================================================================
4 * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 * ===================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END============================================
19 * ECOMP and OpenECOMP are trademarks
20 * and service marks of AT&T Intellectual Property.
24 package org.openecomp.mso.cloud;
26 import com.woorea.openstack.keystone.model.Authentication;
27 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
28 import java.security.GeneralSecurityException;
29 import org.codehaus.jackson.annotate.JsonProperty;
30 import org.codehaus.jackson.map.annotate.JsonDeserialize;
31 import org.codehaus.jackson.map.annotate.JsonSerialize;
32 import org.openecomp.mso.cloud.authentication.AuthenticationMethodFactory;
33 import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
34 import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
35 import org.openecomp.mso.cloud.authentication.wrappers.UsernamePasswordWrapper;
36 import org.openecomp.mso.logger.MessageEnum;
37 import org.openecomp.mso.logger.MsoLogger;
38 import org.openecomp.mso.openstack.exceptions.MsoException;
39 import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
40 import org.openecomp.mso.openstack.utils.MsoTenantUtils;
41 import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
42 import org.openecomp.mso.utils.CryptoUtils;
45 * JavaBean JSON class for a CloudIdentity. This bean represents a cloud identity
46 * service instance (i.e. a DCP node) in the NVP/AIC cloud. It will be loaded via
47 * CloudConfig object, of which it is a component (a CloudConfig JSON configuration
48 * file may contain multiple CloudIdentity definitions).
50 * Note that this is only used to access Cloud Configurations loaded from a
51 * JSON config file, so there are no explicit setters.
54 public class CloudIdentity {
56 // This block is needed to trigger the class loader so that static initialization
57 // of both inner static classes occur. This is required when the Json Deserializer
58 // gets called and no access to any of these inner classes happened yet.
60 IdentityServerType.bootstrap();
61 IdentityAuthenticationType.bootstrap();
64 private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
66 public final static class IdentityServerType extends IdentityServerTypeAbstract {
68 public static final IdentityServerType KEYSTONE = new IdentityServerType("KEYSTONE", MsoKeystoneUtils.class);
70 public IdentityServerType(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
71 super(serverType, utilsClass);
74 public static final void bootstrap() {}
77 public static final class IdentityAuthenticationType extends IdentityAuthenticationTypeAbstract {
79 public static final IdentityAuthenticationType USERNAME_PASSWORD = new IdentityAuthenticationType("USERNAME_PASSWORD", UsernamePasswordWrapper.class);
81 public static final IdentityAuthenticationType RACKSPACE_APIKEY = new IdentityAuthenticationType("RACKSPACE_APIKEY", RackspaceAPIKeyWrapper.class);
83 public IdentityAuthenticationType(String identityType, Class<? extends AuthenticationWrapper> wrapperClass) {
84 super(identityType, wrapperClass);
87 public static final void bootstrap() {}
92 @JsonProperty("identity_url")
93 private String identityUrl;
94 @JsonProperty("mso_id")
96 @JsonProperty("mso_pass")
97 private String msoPass;
98 @JsonProperty("admin_tenant")
99 private String adminTenant;
100 @JsonProperty("member_role")
101 private String memberRole;
102 @JsonProperty("tenant_metadata")
103 private Boolean tenantMetadata;
104 @JsonProperty("identity_server_type")
105 @JsonSerialize(using=IdentityServerTypeJsonSerializer.class)
106 @JsonDeserialize(using=IdentityServerTypeJsonDeserializer.class)
107 private IdentityServerType identityServerType;
108 @JsonProperty("identity_authentication_type")
109 @JsonSerialize(using=IdentityAuthenticationTypeJsonSerializer.class)
110 @JsonDeserialize(using=IdentityAuthenticationTypeJsonDeserializer.class)
111 private IdentityAuthenticationType identityAuthenticationType;
113 private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f";
115 public CloudIdentity () {
118 public String getId () {
122 public void setId (String id) {
126 public String getKeystoneUrl (String regionId, String msoPropID) throws MsoException {
127 if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
128 return this.identityUrl;
130 if (this.identityServerType == null) {
133 MsoTenantUtils tenantUtils = new MsoTenantUtilsFactory(msoPropID).getTenantUtilsByServerType(this.identityServerType.toString());
134 if (tenantUtils != null) {
135 return tenantUtils.getKeystoneUrl(regionId, msoPropID, this);
142 public Authentication getAuthentication() {
143 if (this.getIdentityAuthenticationType() != null) {
144 return AuthenticationMethodFactory.getAuthenticationFor(this);
146 return new UsernamePassword(this.getMsoId(), this.getMsoPass());
150 public void setKeystoneUrl (String url) {
151 if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
152 this.identityUrl = url;
156 public String getIdentityUrl() {
157 return this.identityUrl;
159 public void setIdentityUrl(String url) {
160 this.identityUrl = url;
163 public String getMsoId () {
167 public void setMsoId (String id) {
171 public String getMsoPass () {
173 return CryptoUtils.decrypt (msoPass, cloudKey);
174 } catch (GeneralSecurityException e) {
175 LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in getMsoPass", e);
180 public void setMsoPass (String pwd) {
184 public String getAdminTenant () {
188 public void setAdminTenant (String tenant) {
189 this.adminTenant = tenant;
192 public String getMemberRole () {
196 public void setMemberRole (String role) {
197 this.memberRole = role;
200 public boolean hasTenantMetadata () {
201 return tenantMetadata;
204 public void setTenantMetadata (boolean meta) {
205 this.tenantMetadata = meta;
208 public IdentityServerType getIdentityServerType() {
209 return this.identityServerType;
211 public void setIdentityServerType(IdentityServerType ist) {
212 this.identityServerType = ist;
214 public String getIdentityServerTypeAsString() {
215 return this.identityServerType.toString();
218 * @return the identityAuthenticationType
220 public IdentityAuthenticationType getIdentityAuthenticationType() {
221 return identityAuthenticationType;
225 * @param identityAuthenticationType the identityAuthenticationType to set
227 public void setIdentityAuthenticationType(IdentityAuthenticationType identityAuthenticationType) {
228 this.identityAuthenticationType = identityAuthenticationType;
232 public String toString () {
233 return "Cloud Identity Service: id=" + id +
234 ", identityUrl=" + this.identityUrl +
236 ", adminTenant=" + adminTenant +
237 ", memberRole=" + memberRole +
238 ", tenantMetadata=" + tenantMetadata +
239 ", identityServerType=" + (identityServerType == null ? "null" : identityServerType.toString()) +
240 ", identityAuthenticationType=" + (identityAuthenticationType == null ? "null" : identityAuthenticationType.toString());
243 public static String encryptPassword (String msoPass) {
245 return CryptoUtils.encrypt (msoPass, cloudKey);
246 } catch (GeneralSecurityException e) {
247 LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
254 public CloudIdentity clone() {
255 CloudIdentity cloudIdentityCopy = new CloudIdentity();
257 cloudIdentityCopy.id = this.id;
258 cloudIdentityCopy.identityUrl = this.identityUrl;
259 cloudIdentityCopy.msoId = this.msoId;
260 cloudIdentityCopy.msoPass = this.msoPass;
261 cloudIdentityCopy.adminTenant = this.adminTenant;
262 cloudIdentityCopy.memberRole = this.memberRole;
263 cloudIdentityCopy.tenantMetadata = this.tenantMetadata;
264 cloudIdentityCopy.identityServerType = this.identityServerType;
265 cloudIdentityCopy.identityAuthenticationType = this.identityAuthenticationType;
267 return cloudIdentityCopy;
271 public int hashCode() {
272 final int prime = 31;
274 result = prime * result + ((adminTenant == null) ? 0 : adminTenant.hashCode());
275 result = prime * result + ((id == null) ? 0 : id.hashCode());
276 result = prime * result + ((identityUrl == null) ? 0 : identityUrl.hashCode());
277 result = prime * result + ((memberRole == null) ? 0 : memberRole.hashCode());
278 result = prime * result + ((msoId == null) ? 0 : msoId.hashCode());
279 result = prime * result + ((msoPass == null) ? 0 : msoPass.hashCode());
280 result = prime * result + ((tenantMetadata == null) ? 0 : tenantMetadata.hashCode());
281 result = prime * result + ((identityServerType == null) ? 0 : identityServerType.hashCode());
282 result = prime * result + ((identityAuthenticationType == null) ? 0 : identityAuthenticationType.hashCode());
287 public boolean equals(Object obj) {
292 if (getClass() != obj.getClass())
294 CloudIdentity other = (CloudIdentity) obj;
295 if (adminTenant == null) {
296 if (other.adminTenant != null)
298 } else if (!adminTenant.equals(other.adminTenant))
301 if (other.id != null)
303 } else if (!id.equals(other.id))
305 if (identityUrl == null) {
306 if (other.identityUrl != null)
308 } else if (!identityUrl.equals(other.identityUrl))
310 if (memberRole == null) {
311 if (other.memberRole != null)
313 } else if (!memberRole.equals(other.memberRole))
316 if (other.msoId != null)
318 } else if (!msoId.equals(other.msoId))
320 if (msoPass == null) {
321 if (other.msoPass != null)
323 } else if (!msoPass.equals(other.msoPass))
325 if (tenantMetadata == null) {
326 if (other.tenantMetadata != null)
328 } else if (!tenantMetadata.equals(other.tenantMetadata))
330 if (identityServerType == null) {
331 if (other.getIdentityServerType() != null)
333 } else if (!identityServerType.equals(other.getIdentityServerType()))
335 if (identityAuthenticationType == null) {
336 if (other.getIdentityAuthenticationType() != null)
338 } else if (!identityAuthenticationType.equals(other.getIdentityAuthenticationType()))