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;
26 import static java.lang.String.format;
28 public class AafServiceImpl extends BaseLoggingClass implements AafService {
30 private static final int CREATED = 201;
31 private static final int OK = 200;
32 private static final String FORCE = "?force=true";
33 private final String aafUrl;
34 private final String identity;
35 private final boolean useAAF;
36 private final AafConnection aafConnection;
38 AafServiceImpl(boolean useAaf, String aafUrl, String identity, AafConnection aafConnection) {
41 this.identity = identity;
42 this.aafConnection = aafConnection;
46 public String getIdentity() {
51 public int addPerm(DmaapPerm perm) {
52 logger.info("entry: addPerm() ");
53 return doPost(perm, "authz/perm", CREATED);
57 public int delPerm(DmaapPerm perm, boolean force) {
58 logger.info("entry: delPerm()");
59 return doDelete(new AafEmpty(), format(
60 "authz/perm/%s/%s/%s%s",
61 perm.getPermission(), perm.getPtype(), perm.getAction(), force ? FORCE : ""), OK);
65 public int addGrant(DmaapGrant grant) {
66 logger.info("entry: addGrant() ");
67 return doPost(grant, "authz/role/perm", CREATED);
71 public int addUserRole(AafUserRole ur) {
72 logger.info("entry: addUserRole() ");
73 return doPost(ur, "authz/userRole", CREATED);
77 public int addRole(AafRole role) {
78 logger.info("entry: addRole() ");
79 return doPost(role, "authz/role", CREATED);
83 public int addNamespace(AafNamespace ns) {
84 logger.info("entry: addNamespace() ");
85 return doPost(ns, "authz/ns", CREATED);
89 public int delNamespace(AafNamespace ns, boolean force) {
90 logger.info("entry: delNamespace()");
91 return doDelete(new AafEmpty(), format(
93 ns.getName(), force ? FORCE : ""), OK);
96 private int doPost(AafObject obj, String uri, int expect) {
98 logger.info("entry: doPost() ");
99 String pURL = aafUrl + uri;
100 logger.info("doPost: useAAF=" + useAAF);
102 logger.info("doPost: " + obj.toJSON());
103 rc = aafConnection.postAaf(obj, pURL);
110 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, identity);
113 logger.warn("Object for " + uri + " already exists. Possible conflict.");
117 logger.info("expected response: " + rc);
119 logger.error("Unexpected response: " + rc);
127 private int doDelete(AafObject obj, String uri, int expect) {
129 String pURL = aafUrl + uri;
131 logger.info("doDelete: " + obj.toJSON());
132 rc = aafConnection.delAaf(obj, pURL);
139 errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, identity);
142 logger.warn("Object not found...ignore");
145 logger.info("expected response");
148 logger.error("Unexpected response: " + rc);