summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorpkaras <piotr.karas@nokia.com>2019-06-05 13:35:01 +0200
committerpkaras <piotr.karas@nokia.com>2019-06-05 13:35:01 +0200
commit740c3a350fef567f61b9dfcb8d516c6c612e97c5 (patch)
tree96b6bc711c7009355abab815a224f0cfc2ce717b /src/main/java/org/onap
parent83c6b7a136bfa598dca073846532aa1cbdccf270 (diff)
AafServiceImpl refactor and sonar fixes
Change-Id: I430f279ea6a1e74607edd629de4e5fc9fad9e1f8 Issue-ID: DMAAP-1217 Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java130
1 files changed, 56 insertions, 74 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
index a01b30c..7d2c018 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
@@ -25,10 +25,6 @@ import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
import org.onap.dmaap.dbcapi.util.DmaapConfig;
public class AafServiceImpl extends BaseLoggingClass implements AafService {
- public enum ServiceType {
- AAF_Admin,
- AAF_TopicMgr
- }
private AafConnection aaf;
private AafService.ServiceType ctype;
@@ -36,71 +32,56 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
private String identity;
private boolean useAAF = false;
-
- public String getIdentity() {
- return identity;
+ public AafServiceImpl(AafService.ServiceType t) {
+ DmaapConfig p = (DmaapConfig) DmaapConfig.getConfig();
+ aafURL = p.getProperty("aaf.URL", "https://authentication.domain.netset.com:8100/proxy/");
+ initAafService(t);
}
+ private void initAafService(AafService.ServiceType t) {
+ DmaapConfig p = (DmaapConfig) DmaapConfig.getConfig();
+ useAAF = "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
+ logger.info("AafService initAafService: useAAF=" + useAAF);
- public void setIdentity(String identity) {
- this.identity = identity;
+ ctype = t;
+ aaf = new AafConnection(getCred(true));
}
-
private String getCred(boolean wPwd) {
- String mechIdProperty = null;
- String pwdProperty = null;
+ String mechIdProperty;
+ String secretProperty;
DmaapConfig p = (DmaapConfig) DmaapConfig.getConfig();
AafDecrypt decryptor = new AafDecrypt();
if (ctype == AafService.ServiceType.AAF_Admin) {
mechIdProperty = "aaf.AdminUser";
- pwdProperty = "aaf.AdminPassword";
+ secretProperty = "aaf.AdminPassword";
} else if (ctype == AafService.ServiceType.AAF_TopicMgr) {
mechIdProperty = "aaf.TopicMgrUser";
- pwdProperty = "aaf.TopicMgrPassword";
+ secretProperty = "aaf.TopicMgrPassword";
} else {
logger.error("Unexpected case for AAF credential type: " + ctype);
return null;
}
identity = p.getProperty(mechIdProperty, "noMechId@domain.netset.com");
- String pwd = "";
- String encPwd = p.getProperty(pwdProperty, "notSet");
+ String encPwd = p.getProperty(secretProperty, "notSet");
-
- pwd = decryptor.decrypt(encPwd);
+ String pwd = decryptor.decrypt(encPwd);
if (wPwd) {
return identity + ":" + pwd;
} else {
return identity;
}
-
-
- }
-
-
- public AafServiceImpl(AafService.ServiceType t) {
- DmaapConfig p = (DmaapConfig) DmaapConfig.getConfig();
- aafURL = p.getProperty("aaf.URL", "https://authentication.domain.netset.com:8100/proxy/");
- initAafService(t);
- }
-
- public AafServiceImpl(AafService.ServiceType t, String url) {
- aafURL = url;
- initAafService(t);
}
- private void initAafService(AafService.ServiceType t) {
- DmaapConfig p = (DmaapConfig) DmaapConfig.getConfig();
- useAAF = "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
- logger.info("AafService initAafService: useAAF=" + useAAF);
-
- ctype = t;
- aaf = new AafConnection(getCred(true));
+ @Override
+ public String getIdentity() {
+ return identity;
}
+ @Override
public int addPerm(DmaapPerm perm) {
logger.info("entry: addPerm() ");
return doPost(perm, "authz/perm", 201);
@@ -111,55 +92,31 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
return 200;
}
+ @Override
public int addGrant(DmaapGrant grant) {
logger.info("entry: addGrant() ");
return doPost(grant, "authz/role/perm", 201);
}
+ @Override
public int addUserRole(AafUserRole ur) {
logger.info("entry: addUserRole() ");
return doPost(ur, "authz/userRole", 201);
}
+ @Override
public int delGrant(DmaapGrant grant) {
- int rc = -1;
logger.info("entry: delGrant() ");
-
- String pURL = aafURL + "authz/role/:" + grant.getRole() + "/perm";
-
- if (useAAF) {
- rc = aaf.delAaf(grant, pURL);
- } else {
- rc = 200;
- }
- switch (rc) {
- case 401:
- case 403:
- errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred(false));
- System.exit(1);
- break;
-
- case 404:
- logger.warn("Perm not found...ignore");
- break;
-
- case 200:
- logger.info("expected response");
- break;
- default:
- logger.error("Unexpected response: " + rc);
- break;
- }
-
- return rc;
+ return doDelete(grant, "authz/role/:" + grant.getRole() + "/perm", 200);
}
+ @Override
public int addRole(AafRole role) {
logger.info("entry: addRole() ");
return doPost(role, "authz/role", 201);
}
-
+ @Override
public int addNamespace(AafNamespace ns) {
logger.info("entry: addNamespace() ");
return doPost(ns, "authz/ns", 201);
@@ -170,9 +127,8 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
return 200;
}
-
private int doPost(AafObject obj, String uri, int expect) {
- int rc = -1;
+ int rc;
logger.info("entry: doPost() ");
String pURL = aafURL + uri;
logger.info("doPost: useAAF=" + useAAF);
@@ -186,12 +142,10 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
case 401:
case 403:
errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred(false));
- System.exit(1);
+ break;
case 409:
logger.warn("Object for " + uri + " already exists. Possible conflict.");
break;
-
-
default:
if (rc == expect) {
logger.info("expected response: " + rc);
@@ -203,4 +157,32 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
return rc;
}
+
+ private int doDelete(AafObject obj, String uri, int expect) {
+ int rc;
+ String pURL = aafURL + uri;
+ if (useAAF) {
+ logger.info("doDelete: " + obj.toJSON());
+ rc = aaf.delAaf(obj, pURL);
+ } else {
+ rc = expect;
+ }
+ switch (rc) {
+ case 401:
+ case 403:
+ errorLogger.error(DmaapbcLogMessageEnum.AAF_CREDENTIAL_ERROR, getCred(false));
+ break;
+ case 404:
+ logger.warn("Object not found...ignore");
+ break;
+ case 200:
+ logger.info("expected response");
+ break;
+ default:
+ logger.error("Unexpected response: " + rc);
+ break;
+ }
+
+ return rc;
+ }
} \ No newline at end of file