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 ;
40 private String getCred( boolean wPwd ) {
41 String mechIdProperty = null;
42 String pwdProperty = null;
43 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
44 AafDecrypt decryptor = new AafDecrypt();
46 if ( ctype == ServiceType.AAF_Admin ) {
47 mechIdProperty = "aaf.AdminUser";
48 pwdProperty = "aaf.AdminPassword";
49 } else if ( ctype == ServiceType.AAF_TopicMgr ){
50 mechIdProperty = "aaf.TopicMgrUser";
51 pwdProperty = "aaf.TopicMgrPassword";
53 logger.error( "Unexpected case for AAF credential type: " + ctype );
56 String user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
57 //String dClass = p.getProperty( "AafDecryption.Class", "org.openecomp.dmaapbc.aaf.ClearDecrypt");
59 String encPwd = p.getProperty( pwdProperty, "notSet" );
60 //DecryptionInterface dec = null;
62 // dec = (DecryptionInterface) (Class.forName(dClass).newInstance());
63 // dec.init( p.getProperty("CredentialCodecKeyfile", "LocalKey"));
64 //} catch (Exception ee ) {
65 // errorLogger.error(DmaapbcLogMessageEnum.UNEXPECTED_CONDITION, "attempting to use " + dClass + " to decrypt " + encPwd );
68 // pwd = dec.decrypt( encPwd );
69 //} catch( IOException io ) {
70 // errorLogger.error(DmaapbcLogMessageEnum.DECRYPT_IO_ERROR, dClass, encPwd );
73 pwd = decryptor.decrypt(encPwd);
76 return user + ":" + pwd;
84 public AafService(ServiceType t ) {
85 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
86 aafURL = p.getProperty( "aaf.URL", "https://authentication.domain.netset.com:8095/proxy/");
89 public AafService( ServiceType t, String url ) {
94 private void initAafService( ServiceType t ) {
96 aaf = new AafConnection( getCred( true ) );
99 public int addPerm(DmaapPerm perm) {
102 logger.info( "entry: addPerm() " );
103 String pURL = aafURL + "authz/perm";
104 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";
130 rc = aaf.postAaf( grant, pURL );
134 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
139 logger.warn( "Perm already exists. Possible conflict.");
143 logger.info( "expected response" );
146 logger.error( "Unexpected response: " + rc );
153 public int delGrant( DmaapGrant grant ) {
155 logger.info( "entry: delGrant() " );
157 String pURL = aafURL + "authz/role/:" + grant.getRole() + "/perm";
158 rc = aaf.delAaf( grant, pURL );
162 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
167 logger.warn( "Perm not found...ignore");
171 logger.info( "expected response" );
174 logger.error( "Unexpected response: " + rc );