Added AAF plugin
[dmaap/kafka11aaf.git] / src / main / java / org / onap / dmaap / commonauth / kafka / base / authorization / AuthorizationProviderFactory.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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
11 *  
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=========================================================
18  *  
19  *  
20  *******************************************************************************/
21 package org.onap.dmaap.commonauth.kafka.base.authorization;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.ServiceLoader;
26
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();
30
31         private AuthorizationProviderFactory() {
32                 try {
33                         ServiceLoader<AuthorizationProvider> serviceLoader = ServiceLoader.load(AuthorizationProvider.class);
34                         for (AuthorizationProvider authzProvider : serviceLoader) {
35                                 AUTHORIZATION_PROVIDER_MAP.put(authzProvider.getId(), authzProvider);
36
37                         }
38                 } catch (Exception ee) {
39                         System.out.println(ee);
40                         System.exit(0);
41                 }
42         }
43
44         public static AuthorizationProviderFactory getProviderFactory() {
45                 return AUTHORIZATION_PROVIDER_FACTORY;
46         }
47
48         public AuthorizationProvider getProvider() {
49                 return AUTHORIZATION_PROVIDER_MAP.get(System.getProperty("kafka.authorization.provider", "CADI_AAF_PROVIDER"));
50         }
51 }