2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia 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.dmaap.dbcapi.aaf;
23 import org.onap.dmaap.dbcapi.aaf.AafService.ServiceType;
24 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
25 import org.onap.dmaap.dbcapi.util.DmaapConfig;
27 public class AafServiceFactory extends BaseLoggingClass {
29 private final DmaapConfig dmaapConfig;
31 public AafServiceFactory() {
32 this((DmaapConfig) DmaapConfig.getConfig());
35 AafServiceFactory(DmaapConfig dmaapConfig) {
36 this.dmaapConfig = dmaapConfig;
39 public AafService initAafService(ServiceType serviceType) {
40 boolean useAaf = "true".equalsIgnoreCase(dmaapConfig.getProperty("UseAAF", "false"));
41 String aafUrl = dmaapConfig.getProperty("aaf.URL", "https://authentication.domain.netset.com:8100/proxy/");
42 logger.info("AafService initAafService: useAaf={}, aafUrl={}", useAaf, aafUrl);
44 AafCred cred = getCred(serviceType);
45 return new AafServiceImpl(useAaf, aafUrl, cred.getIdentity(), new AafConnection(cred.toString()));
48 AafCred getCred(ServiceType ctype) {
49 String mechIdProperty;
50 String secretProperty;
51 AafDecrypt decryptor = new AafDecrypt();
53 if (ctype == ServiceType.AAF_Admin) {
54 mechIdProperty = "aaf.AdminUser";
55 secretProperty = "aaf.AdminPassword";
56 } else if (ctype == ServiceType.AAF_TopicMgr) {
57 mechIdProperty = "aaf.TopicMgrUser";
58 secretProperty = "aaf.TopicMgrPassword";
60 logger.error("Unexpected case for AAF credential type: " + ctype);
63 String identity = dmaapConfig.getProperty(mechIdProperty, "noMechId@domain.netset.com");
64 String pwd = decryptor.decrypt(dmaapConfig.getProperty(secretProperty, "notSet"));
66 return new AafCred(identity, pwd);
70 private final String identity;
71 private final String pwd;
73 AafCred(String identity, String pwd) {
74 this.identity = identity;
78 public String getIdentity() {
82 public String toString() {
83 return identity + ":" + pwd;