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 String identity;
40 private boolean useAAF = false;
44 public String getIdentity() {
49 public void setIdentity(String identity) {
50 this.identity = identity;
54 private String getCred( boolean wPwd ) {
55 String mechIdProperty = null;
56 String pwdProperty = null;
57 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
58 AafDecrypt decryptor = new AafDecrypt();
60 if ( ctype == ServiceType.AAF_Admin ) {
61 mechIdProperty = "aaf.AdminUser";
62 pwdProperty = "aaf.AdminPassword";
63 } else if ( ctype == ServiceType.AAF_TopicMgr ){
64 mechIdProperty = "aaf.TopicMgrUser";
65 pwdProperty = "aaf.TopicMgrPassword";
67 logger.error( "Unexpected case for AAF credential type: " + ctype );
70 identity = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
73 String encPwd = p.getProperty( pwdProperty, "notSet" );
76 pwd = decryptor.decrypt(encPwd);
79 return identity + ":" + pwd;
88 public AafService(ServiceType t ) {
89 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
90 aafURL = p.getProperty( "aaf.URL", "https://authentication.domain.netset.com:8095/proxy/");
93 public AafService( ServiceType t, String url ) {
98 private void initAafService( ServiceType t ) {
99 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
100 useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
101 logger.info( "AafService initAafService: useAAF=" + useAAF);
104 aaf = new AafConnection( getCred( true ) );
107 public int addPerm(DmaapPerm perm) {
108 logger.info( "entry: addPerm() " );
109 return doPost( perm, "authz/perm", 201);
111 public int addGrant(DmaapGrant grant ) {
112 logger.info( "entry: addGrant() " );
113 return doPost( grant, "authz/role/perm", 201 );
115 public int addUserRole( AafUserRole ur ) {
116 logger.info( "entry: addUserRole() " );
117 return doPost( ur, "authz/userRole", 201 );
120 public int delGrant( DmaapGrant grant ) {
122 logger.info( "entry: delGrant() " );
124 String pURL = aafURL + "authz/role/:" + grant.getRole() + "/perm";
127 rc = aaf.delAaf( grant, pURL );
134 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
139 logger.warn( "Perm not found...ignore");
143 logger.info( "expected response" );
146 logger.error( "Unexpected response: " + rc );
153 public int addRole(AafRole role) {
154 logger.info( "entry: addRole() " );
155 return doPost( role, "authz/role", 201 );
160 public int addNamespace(AafNamespace ns) {
161 logger.info( "entry: addNamespace() " );
162 return doPost( ns, "authz/ns", 201 );
166 private int doPost( AafObject obj, String uri, int expect ) {
168 logger.info( "entry: doPost() " );
169 String pURL = aafURL + uri;
170 logger.info( "doPost: useAAF=" + useAAF );
172 logger.info( "doPost: " + obj.toJSON());
173 rc = aaf.postAaf( obj, pURL );
180 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred( false ) );
183 logger.warn( "Object for " + uri + " already exists. Possible conflict.");
188 if ( rc == expect ) {
189 logger.info( "expected response: " + rc);
191 logger.error( "Unexpected response: " + rc );