1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
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=========================================================
20 *******************************************************************************/
21 package org.onap.dmaap.commonauth.kafka.base.authorization;
23 import java.util.HashMap;
25 import java.util.ServiceLoader;
27 public class AuthorizationProviderFactory<K, V> {
28 private static final Map<String, AuthorizationProvider> AUTHORIZATION_PROVIDER_MAP = new HashMap<String, AuthorizationProvider>();
29 private static final AuthorizationProviderFactory AUTHORIZATION_PROVIDER_FACTORY = new AuthorizationProviderFactory();
31 private AuthorizationProviderFactory() {
33 ServiceLoader<AuthorizationProvider> serviceLoader = ServiceLoader.load(AuthorizationProvider.class);
34 for (AuthorizationProvider authzProvider : serviceLoader) {
35 AUTHORIZATION_PROVIDER_MAP.put(authzProvider.getId(), authzProvider);
38 } catch (Exception ee) {
39 System.out.println(ee);
44 public static AuthorizationProviderFactory getProviderFactory() {
45 return AUTHORIZATION_PROVIDER_FACTORY;
48 public AuthorizationProvider getProvider() {
49 return AUTHORIZATION_PROVIDER_MAP.get(System.getProperty("kafka.authorization.provider", "CADI_AAF_PROVIDER"));