2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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
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.logging.BaseLoggingClass;
24 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
25 import org.onap.dmaap.dbcapi.util.DmaapConfig;
28 * this service uses the AAF REST API endpoints to provision values in AAF
30 public class AafService extends BaseLoggingClass {
31 public enum ServiceType {
36 private AafConnection aaf;
37 private ServiceType ctype;
38 private String aafURL ;
39 private boolean useAAF = false;
42 private String getCred( boolean wPwd ) {
43 String mechIdProperty = null;
44 String pwdProperty = null;
45 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
46 AafDecrypt decryptor = new AafDecrypt();
48 if ( ctype == ServiceType.AAF_Admin ) {
49 mechIdProperty = "aaf.AdminUser";
50 pwdProperty = "aaf.AdminPassword";
51 } else if ( ctype == ServiceType.AAF_TopicMgr ){
52 mechIdProperty = "aaf.TopicMgrUser";
53 pwdProperty = "aaf.TopicMgrPassword";
55 logger.error( "Unexpected case for AAF credential type: " + ctype );
58 String user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
61 String encPwd = p.getProperty( pwdProperty, "notSet" );
64 pwd = decryptor.decrypt(encPwd);
67 return user + ":" + pwd;
75 public AafService(ServiceType t ) {
76 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
77 aafURL = p.getProperty( "aaf.URL", "https://authentication.domain.netset.com:8095/proxy/");
80 public AafService( ServiceType t, String url ) {
85 private void initAafService( ServiceType t ) {
86 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
87 useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
88 logger.info( "AafService initAafService: useAAF=" + useAAF);
91 aaf = new AafConnection( getCred( true ) );
94 public int addPerm(DmaapPerm perm) {
97 logger.info( "entry: addPerm() " );
98 String pURL = aafURL + "authz/perm";
99 logger.info( "addPerm=" + useAAF );
101 logger.info( "addPerm: " + perm.toJSON());
102 rc = aaf.postAaf( perm, pURL );
109 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
112 logger.warn( "Perm already exists. Possible conflict.");
116 logger.info( "expected response: " + rc);
119 logger.error( "Unexpected response: " + rc );
125 public int addGrant(DmaapGrant grant ) {
128 logger.info( "entry: addGrant() " );
130 String pURL = aafURL + "authz/role/perm";
131 logger.info( "addGrant: useAAF=" + useAAF );
133 logger.info( "addGrant: " + grant.toJSON() );
134 rc = aaf.postAaf( grant, pURL );
142 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
147 logger.warn( "Perm already exists. Possible conflict.");
151 logger.info( "expected response" );
154 logger.error( "Unexpected response: " + rc );
161 public int delGrant( DmaapGrant grant ) {
163 logger.info( "entry: delGrant() " );
165 String pURL = aafURL + "authz/role/:" + grant.getRole() + "/perm";
168 rc = aaf.delAaf( grant, pURL );
175 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
180 logger.warn( "Perm not found...ignore");
184 logger.info( "expected response" );
187 logger.error( "Unexpected response: " + rc );