2 * ============LICENSE_START==========================================
\r
3 * ===================================================================
\r
4 * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
\r
5 * ===================================================================
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
17 * ============LICENSE_END============================================
\r
19 * ECOMP and OpenECOMP are trademarks
\r
20 * and service marks of AT&T Intellectual Property.
\r
24 package org.openecomp.mso.cloud.authentication;
\r
26 import java.io.IOException;
\r
27 import java.net.URISyntaxException;
\r
28 import java.util.Map;
\r
29 import java.util.concurrent.ConcurrentHashMap;
\r
31 import org.openecomp.mso.cloud.CloudIdentity;
\r
33 import com.woorea.openstack.keystone.model.Authentication;
\r
36 * This factory manages all the wrappers associated to authentication types.
\r
39 public final class AuthenticationMethodFactory {
\r
41 private static Map<String, AuthenticationWrapper> authWrappers = new ConcurrentHashMap<>();
\r
43 private AuthenticationMethodFactory() {}
\r
46 * Function to be called by classes implementing the abstract {@link AuthenticationWrapper#register(String, Class)}.
\r
48 static final synchronized void register(String authenticationType, Class<? extends AuthenticationWrapper> wrapperClass) throws InstantiationException, IllegalAccessException {
\r
49 if ((authenticationType == null) || ("".equals(authenticationType))) {
\r
50 throw new IllegalArgumentException("Authentication Type to register cannot be null or an empty name string, provided value is " + authenticationType + ".");
\r
52 if (wrapperClass == null) {
\r
53 throw new IllegalArgumentException("Wrapper Class to register for Authentication cannot be null");
\r
56 if (!authWrappers.containsKey(authenticationType)) {
\r
57 authWrappers.put(authenticationType, wrapperClass.newInstance());
\r
61 public static final synchronized Authentication getAuthenticationFor(CloudIdentity cloudIdentity) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, URISyntaxException {
\r
62 if (cloudIdentity == null) {
\r
63 throw new IllegalArgumentException("Cloud identity cannot be null");
\r
65 if ((cloudIdentity.getIdentityAuthenticationType() == null) || ("".equals(cloudIdentity.getIdentityAuthenticationType().toString()))) {
\r
66 throw new IllegalArgumentException("Cloud identity authentication type cannot be null or empty, provided value is " + cloudIdentity.getIdentityAuthenticationType() + ".");
\r
68 String authenticationType = cloudIdentity.getIdentityAuthenticationType().toString();
\r
70 if (authWrappers.containsKey(authenticationType)) {
\r
71 return authWrappers.get(authenticationType).getAuthentication(cloudIdentity);
\r
73 throw new IllegalArgumentException("Provided authentication type (" + authenticationType + ") is not implemented by any wrapper.");
\r