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 java.io.IOException;
25 import org.apache.log4j.Logger;
26 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
27 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
28 import org.onap.dmaap.dbcapi.util.DmaapConfig;
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 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
43 useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
47 private String getCred( boolean wPwd ) {
48 String mechIdProperty = null;
49 String pwdProperty = null;
50 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
51 AafDecrypt decryptor = new AafDecrypt();
53 if ( ctype == ServiceType.AAF_Admin ) {
54 mechIdProperty = "aaf.AdminUser";
55 pwdProperty = "aaf.AdminPassword";
56 } else if ( ctype == ServiceType.AAF_TopicMgr ){
57 mechIdProperty = "aaf.TopicMgrUser";
58 pwdProperty = "aaf.TopicMgrPassword";
60 logger.error( "Unexpected case for AAF credential type: " + ctype );
63 String user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
66 String encPwd = p.getProperty( pwdProperty, "notSet" );
69 pwd = decryptor.decrypt(encPwd);
72 return user + ":" + pwd;
80 public AafService(ServiceType t ) {
81 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
82 aafURL = p.getProperty( "aaf.URL", "https://authentication.domain.netset.com:8095/proxy/");
85 public AafService( ServiceType t, String url ) {
90 private void initAafService( ServiceType t ) {
92 aaf = new AafConnection( getCred( true ) );
95 public int addPerm(DmaapPerm perm) {
98 logger.info( "entry: addPerm() " );
99 String pURL = aafURL + "authz/perm";
101 rc = aaf.postAaf( perm, pURL );
108 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
111 logger.warn( "Perm already exists. Possible conflict.");
115 logger.info( "expected response" );
118 logger.error( "Unexpected response: " + rc );
124 public int addGrant(DmaapGrant grant ) {
127 logger.info( "entry: addGrant() " );
129 String pURL = aafURL + "authz/role/perm";
131 rc = aaf.postAaf( grant, pURL );
139 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
144 logger.warn( "Perm already exists. Possible conflict.");
148 logger.info( "expected response" );
151 logger.error( "Unexpected response: " + rc );
158 public int delGrant( DmaapGrant grant ) {
160 logger.info( "entry: delGrant() " );
162 String pURL = aafURL + "authz/role/:" + grant.getRole() + "/perm";
165 rc = aaf.delAaf( grant, pURL );
172 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
177 logger.warn( "Perm not found...ignore");
181 logger.info( "expected response" );
184 logger.error( "Unexpected response: " + rc );