From ff1417ff60baee231a28272f9a16ef2c9c8ea0a2 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Wed, 29 May 2019 04:58:50 -0500 Subject: Post Init Service Starter minor fixes Remove JU generated garbage files Issue-ID: AAF-835 Change-Id: I476291f1f1140f0640ed49452f8a5dabb28d9c30 Signed-off-by: Instrumental --- auth-client/src/main/xsd/aaf_2_0.xsd | 2 + .../org/onap/aaf/auth/batch/helpers/Creator.java | 14 +- .../main/java/org/onap/aaf/auth/dao/Cached.java | 2 +- .../org/onap/aaf/auth/dao/cass/CacheInfoDAO.java | 2 +- .../java/org/onap/aaf/auth/dao/cass/CredDAO.java | 2 +- .../org/onap/aaf/auth/dao/cass/HistoryDAO.java | 2 +- .../java/org/onap/aaf/auth/dao/cass/Status.java | 2 +- .../org/onap/aaf/auth/dao/hl/CassExecutor.java | 2 +- .../java/org/onap/aaf/auth/dao/hl/Function.java | 194 ++-- .../java/org/onap/aaf/auth/dao/hl/PermLookup.java | 6 +- .../java/org/onap/aaf/auth/dao/hl/Question.java | 97 +- .../test/java/org/onap/aaf/auth/dao/JU_Cached.java | 5 +- .../onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java | 6 +- .../onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java | 19 +- .../org/onap/aaf/auth/dao/cass/JU_LocateDAO.java | 14 +- .../java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java | 13 +- .../onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java | 13 +- .../org/onap/aaf/auth/dao/cass/JU_PermDAO.java | 22 +- .../org/onap/aaf/auth/dao/cass/JU_RoleDAO.java | 14 +- .../org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java | 18 +- .../org/onap/aaf/auth/dao/hl/JU_CassExecutor.java | 14 +- .../java/org/onap/aaf/auth/dao/hl/JU_Function.java | 1127 +++++--------------- .../org/onap/aaf/auth/dao/hl/JU_PermLookup.java | 77 +- .../main/java/org/onap/aaf/auth/cm/ca/JscepCA.java | 4 +- .../org/onap/aaf/auth/cm/mapper/Mapper2_0.java | 51 +- .../aaf/auth/cm/validation/CertmanValidator.java | 3 + .../src/main/java/org/onap/aaf/auth/cmd/Cmd.java | 1 + .../java/org/onap/aaf/auth/cmd/perm/Grant.java | 104 +- .../main/java/org/onap/aaf/auth/cmd/role/User.java | 140 +-- .../main/java/org/onap/aaf/auth/cmd/user/List.java | 14 +- .../main/java/org/onap/aaf/auth/cmd/user/Role.java | 121 +-- .../org/onap/aaf/auth/cmd/test/perm/JU_Grant.java | 24 +- .../java/org/onap/aaf/auth/env/AuthzTrans.java | 2 + .../java/org/onap/aaf/auth/env/AuthzTransImpl.java | 28 +- .../main/java/org/onap/aaf/auth/env/NullTrans.java | 5 + .../org/onap/aaf/auth/rserv/CachingFileAccess.java | 8 +- .../java/org/onap/aaf/auth/rserv/RServlet.java | 12 + .../java/org/onap/aaf/auth/rserv/TransFilter.java | 3 +- .../onap/aaf/auth/server/AbsServiceStarter.java | 7 +- .../onap/aaf/auth/server/JettyServiceStarter.java | 3 +- .../java/org/onap/aaf/auth/server/Log4JLogIt.java | 22 +- .../src/main/java/org/onap/aaf/auth/fs/AAF_FS.java | 3 +- .../src/main/java/org/onap/aaf/auth/cui/CUI.java | 8 +- .../main/java/org/onap/aaf/auth/gui/AAF_GUI.java | 15 +- .../java/org/onap/aaf/auth/gui/BreadCrumbs.java | 2 +- .../main/java/org/onap/aaf/auth/gui/Display.java | 1 - .../src/main/java/org/onap/aaf/auth/gui/Page.java | 176 ++- .../java/org/onap/aaf/auth/gui/pages/Home.java | 42 +- .../org/onap/aaf/auth/gui/pages/WebCommand.java | 26 +- auth/auth-gui/theme/onap/images/AAF_details.png | Bin 0 -> 650 bytes auth/auth-gui/theme/onap/images/AAF_font_size.png | Bin 0 -> 1280 bytes auth/auth-gui/theme/onap/images/AAF_maximize.png | Bin 0 -> 593 bytes auth/auth-gui/theme/onap/images/AAFdownload.png | Bin 0 -> 1834 bytes auth/auth-gui/theme/onap/images/AAFemail.png | Bin 0 -> 2277 bytes .../theme/onap/images/LF_Collab_footer_gray.png | Bin 0 -> 47307 bytes .../onap/images/LF_Collab_footer_gray_stripe.png | Bin 0 -> 1374 bytes .../theme/onap/images/LF_Collab_header_gray.png | Bin 0 -> 21018 bytes auth/auth-gui/theme/onap/images/ONAP_LOGO.png | Bin 0 -> 24268 bytes auth/auth-gui/theme/onap/images/logo_onap.png | Bin 0 -> 11349 bytes .../onap/aaf/auth/locate/mapper/Mapper_1_1.java | 2 +- .../java/org/onap/aaf/auth/oauth/AAF_OAuth.java | 4 +- .../onap/aaf/auth/oauth/service/OAuthService.java | 2 +- .../org/onap/aaf/auth/service/AAF_Service.java | 17 +- .../aaf/auth/service/AuthzCassServiceImpl.java | 384 ++----- .../org/onap/aaf/auth/service/AuthzService.java | 17 +- .../org/onap/aaf/auth/service/api/API_Creds.java | 1 - .../onap/aaf/auth/service/api/API_UserRole.java | 28 +- .../onap/aaf/auth/service/facade/AuthzFacade.java | 6 +- .../aaf/auth/service/facade/AuthzFacadeImpl.java | 75 +- .../onap/aaf/auth/service/mapper/Mapper_2_0.java | 1 + auth/helm/aaf-hello/Chart.yaml | 2 +- auth/helm/aaf-hello/values.yaml | 2 +- auth/helm/aaf/Chart.yaml | 2 +- .../java/org/onap/aaf/cadi/register/Registrar.java | 1 + .../aaf/cadi/register/RegistrationCreator.java | 26 +- .../main/java/org/onap/aaf/cadi/sso/AAFSSO.java | 2 +- .../main/java/org/onap/aaf/cadi/PropAccess.java | 49 +- .../main/java/org/onap/aaf/cadi/config/Config.java | 8 + .../main/java/org/onap/aaf/misc/env/TimeTaken.java | 4 +- .../java/org/onap/aaf/misc/env/impl/AbsTrans.java | 25 +- .../java/org/onap/aaf/misc/env/impl/BasicEnv.java | 2 +- .../aaf/misc/env/impl/JU_Log4JLogTargetTest.java | 2 +- .../org/onap/aaf/misc/env/log4j/LogFileNamer.java | 25 +- .../aaf/misc/env/log4j/JU_LogFileNamerTest.java | 92 +- .../java/org/onap/aaf/misc/xgen/html/Imports.java | 1 - 85 files changed, 1360 insertions(+), 1912 deletions(-) create mode 100644 auth/auth-gui/theme/onap/images/AAF_details.png create mode 100644 auth/auth-gui/theme/onap/images/AAF_font_size.png create mode 100644 auth/auth-gui/theme/onap/images/AAF_maximize.png create mode 100644 auth/auth-gui/theme/onap/images/AAFdownload.png create mode 100644 auth/auth-gui/theme/onap/images/AAFemail.png create mode 100644 auth/auth-gui/theme/onap/images/LF_Collab_footer_gray.png create mode 100644 auth/auth-gui/theme/onap/images/LF_Collab_footer_gray_stripe.png create mode 100644 auth/auth-gui/theme/onap/images/LF_Collab_header_gray.png create mode 100644 auth/auth-gui/theme/onap/images/ONAP_LOGO.png create mode 100644 auth/auth-gui/theme/onap/images/logo_onap.png diff --git a/auth-client/src/main/xsd/aaf_2_0.xsd b/auth-client/src/main/xsd/aaf_2_0.xsd index b4b1ba9c..0cf39f1d 100644 --- a/auth-client/src/main/xsd/aaf_2_0.xsd +++ b/auth-client/src/main/xsd/aaf_2_0.xsd @@ -355,6 +355,8 @@ Type is not returned for "UserRole", but only "Cred" --> + + diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java index 152c6331..9d0cfa7f 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Creator.java @@ -27,11 +27,23 @@ public abstract class Creator { public abstract T create(Row row); public abstract String select(); + public String suffix() { + return ""; + } + public String query(String where) { StringBuilder sb = new StringBuilder(select()); if (where!=null) { sb.append(" WHERE "); - sb.append(where); + int index = where.indexOf(" ALLOW FILTERING"); + if(index< 0 ) { + sb.append(where); + sb.append(suffix()); + } else { + sb.append(where.substring(0, index)); + sb.append(suffix()); + sb.append(" ALLOW FILTERING"); + } } sb.append(';'); return sb.toString(); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java index 1bda405c..1888b3ac 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java @@ -118,7 +118,7 @@ public class Cached extends Cache)cached.data; rld = Result.ok(ld); } else { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java index 4aa94866..8cb25ac7 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java @@ -137,7 +137,7 @@ public class CacheInfoDAO extends CassDAOImpl impl } } - public static void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter ss, String ip, int port) { + public static synchronized void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter ss, String ip, int port) { if (cacheUpdate==null) { Thread t= new Thread(cacheUpdate = new CacheUpdate(env,hman,ss, ip,port),"CacheInfo Update Thread"); t.setDaemon(true); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java index 01cc9237..9c57d200 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java @@ -112,7 +112,7 @@ public class CredDAO extends CassDAOImpl { } } - private static class CredLoader extends Loader implements Streamer{ + public static class CredLoader extends Loader implements Streamer{ public static final int MAGIC=153323443; public static final int VERSION=2; public static final int BUFF_SIZE=48; // Note: diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java index 69d1d26e..73ab343b 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java @@ -85,7 +85,7 @@ public class HistoryDAO extends CassDAOImpl { public ByteBuffer reconstruct; } - private static class HistLoader extends Loader { + public static class HistLoader extends Loader { public HistLoader(int keylimit) { super(keylimit); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java index 8a617b94..a4d0bf4d 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java @@ -58,7 +58,7 @@ public class Status extends Result { * @param status */ private Status(RV value, int status, String details, String[] variables ) { - super(value,status,details,variables); + super(value,status,details,(Object[])variables); } public static String name(int status) { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java index 0bc23c92..a92de21c 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java @@ -48,7 +48,7 @@ public class CassExecutor implements Executor { public boolean inRole(String name) { Result nss = q.deriveNsSplit(trans, name); if (nss.notOK())return false; - return q.roleDAO.read(trans, nss.value.ns,nss.value.name).isOKhasData(); + return q.roleDAO().read(trans, nss.value.ns,nss.value.name).isOKhasData(); } public boolean isGranted(String user, String ns, String type, String instance, String action) { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java index 51bf594a..690ffa08 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java @@ -227,6 +227,7 @@ public class Function { if (rparent.notOK()) { return Result.err(rparent); } + parent = rparent.value.parent; if (!fromApproval) { rparent = q.mayUser(trans, user, rparent.value, Access.write); if (rparent.notOK()) { @@ -234,12 +235,25 @@ public class Function { } } parent = namespace.parent = rparent.value.name; // Correct Namespace from real data + String cname = parent.length()<1 || namespace.name.equals(parent)?null:namespace.name.substring(parent.length()+1); // 2) Does requested NS exist - if (q.nsDAO.read(trans, namespace.name).isOKhasData()) { + if (q.nsDAO().read(trans, namespace.name).isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, "Target Namespace already exists"); } + + // 2.1) Does role exist with that name + if(cname!=null && q.roleDAO().read(trans, parent, cname).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Role exists with that name"); + } + + // 2.2) Do perms exist with that name + if(cname!=null && q.permDAO().readByType(trans, parent, cname).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Perms exist with that name"); + } // Someone must be responsible. if (namespace.owner == null || namespace.owner.isEmpty()) { @@ -283,7 +297,7 @@ public class Function { } // VALIDATIONS done... Add NS - if ((rq = q.nsDAO.create(trans, namespace.data())).notOK()) { + if ((rq = q.nsDAO().create(trans, namespace.data())).notOK()) { return Result.err(rq); } @@ -296,12 +310,12 @@ public class Function { urdd.role(namespace.name, Question.ADMIN); for (String admin : namespace.admin) { urdd.user = admin; - eb.log(q.userRoleDAO.create(trans, urdd)); + eb.log(q.userRoleDAO().create(trans, urdd)); } urdd.role(namespace.name,Question.OWNER); for (String owner : namespace.owner) { urdd.user = owner; - eb.log(q.userRoleDAO.create(trans, urdd)); + eb.log(q.userRoleDAO().create(trans, urdd)); } addNSAdminRolesPerms(trans, eb, namespace.name); @@ -318,7 +332,7 @@ public class Function { int targetNameDot = targetName.length() + 1; // 4) Change any roles with children matching this NS, and - Result> rrdc = q.roleDAO.readChildren(trans, targetNs, targetName); + Result> rrdc = q.roleDAO().readChildren(trans, targetNs, targetName); if (rrdc.isOKhasData()) { for (RoleDAO.Data rdd : rrdc.value) { // Remove old Role from Perms, save them off @@ -328,7 +342,7 @@ public class Function { if (rpdd.isOKhasData()) { PermDAO.Data pdd = rpdd.value; lpdd.add(pdd); - q.permDAO.delRole(trans, pdd, rdd); + q.permDAO().delRole(trans, pdd, rdd); } else{ trans.error().log(rpdd.errorString()); } @@ -345,24 +359,24 @@ public class Function { // Need to use non-cached, because switching namespaces, not // "create" per se - if ((rq = q.roleDAO.create(trans, rdd)).isOK()) { + if ((rq = q.roleDAO().create(trans, rdd)).isOK()) { // Put Role back into Perm, with correct info for (PermDAO.Data pdd : lpdd) { - q.permDAO.addRole(trans, pdd, rdd); + q.permDAO().addRole(trans, pdd, rdd); } // Change data for User Roles - Result> rurd = q.userRoleDAO.readByRole(trans, rdd.fullName()); + Result> rurd = q.userRoleDAO().readByRole(trans, rdd.fullName()); if (rurd.isOKhasData()) { for (UserRoleDAO.Data urd : rurd.value) { urd.ns = rdd.ns; urd.rname = rdd.name; - q.userRoleDAO.update(trans, urd); + q.userRoleDAO().update(trans, urd); } } // Now delete old one rdd.ns = delP1; rdd.name = delP2; - if ((rq = q.roleDAO.delete(trans, rdd, false)).notOK()) { + if ((rq = q.roleDAO().delete(trans, rdd, false)).notOK()) { eb.log(rq); } } else { @@ -372,7 +386,7 @@ public class Function { } // 4) Change any Permissions with children matching this NS, and - Result> rpdc = q.permDAO.readChildren(trans,targetNs, targetName); + Result> rpdc = q.permDAO().readChildren(trans,targetNs, targetName); if (rpdc.isOKhasData()) { for (PermDAO.Data pdd : rpdc.value) { // Remove old Perm from Roles, save them off @@ -383,7 +397,7 @@ public class Function { if (rrdd.isOKhasData()) { RoleDAO.Data rdd = rrdd.value; lrdd.add(rdd); - q.roleDAO.delPerm(trans, rdd, pdd); + q.roleDAO().delPerm(trans, rdd, pdd); } else{ trans.error().log(rrdd.errorString()); } @@ -395,15 +409,15 @@ public class Function { pdd.ns = namespace.name; pdd.type = (delP2.length() > targetNameDot) ? delP2 .substring(targetNameDot) : ""; - if ((rq = q.permDAO.create(trans, pdd)).isOK()) { + if ((rq = q.permDAO().create(trans, pdd)).isOK()) { // Put Role back into Perm, with correct info for (RoleDAO.Data rdd : lrdd) { - q.roleDAO.addPerm(trans, rdd, pdd); + q.roleDAO().addPerm(trans, rdd, pdd); } pdd.ns = delP1; pdd.type = delP2; - if ((rq = q.permDAO.delete(trans, pdd, false)).notOK()) { + if ((rq = q.permDAO().delete(trans, pdd, false)).notOK()) { eb.log(rq); // Need to invalidate directly, because we're // switching places in NS, not normal cache behavior @@ -414,7 +428,7 @@ public class Function { } } if (eb.hasErr()) { - return Result.err(Status.ERR_ActionNotCompleted,eb.sb.toString(), eb.vars()); + return Result.err(Status.ERR_ActionNotCompleted,eb.sb.toString(), (Object[])eb.vars()); } } return Result.ok(); @@ -436,11 +450,11 @@ public class Function { rd.perms = new HashSet<>(); rd.perms.add(pd.encode()); - eb.log(q.roleDAO.create(trans, rd)); + eb.log(q.roleDAO().create(trans, rd)); pd.roles = new HashSet<>(); pd.roles.add(rd.encode()); - eb.log(q.permDAO.create(trans, pd)); + eb.log(q.permDAO().create(trans, pd)); } private void addNSOwnerRolesPerms(AuthzTrans trans, ErrBuilder eb, String ns) { @@ -458,11 +472,11 @@ public class Function { rd.perms = new HashSet<>(); rd.perms.add(pd.encode()); - eb.log(q.roleDAO.create(trans, rd)); + eb.log(q.roleDAO().create(trans, rd)); pd.roles = new HashSet<>(); pd.roles.add(rd.encode()); - eb.log(q.permDAO.create(trans, pd)); + eb.log(q.permDAO().create(trans, pd)); } /** @@ -491,7 +505,7 @@ public class Function { boolean move = trans.requested(REQD_TYPE.move); // 1) Validate Result> nsl; - if ((nsl = q.nsDAO.read(trans, ns)).notOKorIsEmpty()) { + if ((nsl = q.nsDAO().read(trans, ns)).notOKorIsEmpty()) { return Result.err(Status.ERR_NsNotFound, "%s does not exist", ns); } NsDAO.Data nsd = nsl.value.get(0); @@ -529,18 +543,18 @@ public class Function { ErrBuilder er = new ErrBuilder(); // 2a) Deny if any IDs on Namespace - Result> creds = q.credDAO.readNS(trans, ns); + Result> creds = q.credDAO().readNS(trans, ns); if (creds.isOKhasData()) { if (force || move) { for (CredDAO.Data cd : creds.value) { - er.log(q.credDAO.delete(trans, cd, false)); + er.log(q.credDAO().delete(trans, cd, false)); // Since we're deleting all the creds, we should delete all // the user Roles for that Cred - Result> rlurd = q.userRoleDAO + Result> rlurd = q.userRoleDAO() .readByUser(trans, cd.id); if (rlurd.isOK()) { for (UserRoleDAO.Data data : rlurd.value) { - q.userRoleDAO.delete(trans, data, false); + q.userRoleDAO().delete(trans, data, false); } } @@ -556,7 +570,7 @@ public class Function { // 2b) Find (or delete if forced flag is set) dependencies // First, find if NS Perms are the only ones - Result> rpdc = q.permDAO.readNS(trans, ns); + Result> rpdc = q.permDAO().readNS(trans, ns); if (rpdc.isOKhasData()) { // Since there are now NS perms, we have to count NON-NS perms. // FYI, if we delete them now, and the NS is not deleted, it is in @@ -581,7 +595,7 @@ public class Function { } } - Result> rrdc = q.roleDAO.readNS(trans, ns); + Result> rrdc = q.roleDAO().readNS(trans, ns); if (rrdc.isOKhasData()) { // Since there are now NS roles, we have to count NON-NS roles. // FYI, if we delete th)em now, and the NS is not deleted, it is in @@ -652,7 +666,7 @@ public class Function { } } - return q.nsDAO.delete(trans, nsd, false); + return q.nsDAO().delete(trans, nsd, false); } public Result> getOwners(AuthzTrans trans, String ns, @@ -712,7 +726,7 @@ public class Function { rq = q.mayUser(trans, trans.user(), rq.value, Access.write); if (rq.notOK()) { - Result> ruinr = q.userRoleDAO.readUserInRole(trans, trans.user(),ns+".owner"); + Result> ruinr = q.userRoleDAO().readUserInRole(trans, trans.user(),ns+".owner"); if (!(ruinr.isOKhasData() && ruinr.value.get(0).expires.after(new Date()))) { return Result.err(rq); } @@ -726,7 +740,7 @@ public class Function { try { if (org.getIdentity(trans, user) == null) { return Result.err(Status.ERR_Denied, - "%s reports that %s is a faulty ID", org.getName(), + "%s reports that %s is an invalid ID", org.getName(), user); } return Result.ok(); @@ -738,7 +752,7 @@ public class Function { // } else if (user.endsWith(ALTERNATE OAUTH DOMAIN)) { // return Result.ok(); } else { - Result> cdr = q.credDAO.readID(trans, user); + Result> cdr = q.credDAO().readID(trans, user); if (cdr.notOKorIsEmpty()) { return Result.err(Status.ERR_Security, "%s is not a valid AAF Credential", user); @@ -780,7 +794,7 @@ public class Function { rq = q.mayUser(trans, trans.user(), rq.value, Access.write); if (rq.notOK()) { // Even though not a "writer", Owners still determine who gets to be an Admin - Result> ruinr = q.userRoleDAO.readUserInRole(trans, trans.user(),ns+".owner"); + Result> ruinr = q.userRoleDAO().readUserInRole(trans, trans.user(),ns+".owner"); if (!(ruinr.isOKhasData() && ruinr.value.get(0).expires.after(new Date()))) { return Result.err(rq); } @@ -819,7 +833,7 @@ public class Function { if (rrdd.isOKhasData()) { RoleDAO.Data rdd = rrdd.value; lrdd.add(rdd); - q.roleDAO.delPerm(trans, rdd, pdd); + q.roleDAO().delPerm(trans, rdd, pdd); } else{ trans.error().log(rrdd.errorString()); } @@ -831,21 +845,21 @@ public class Function { pdd.ns = nss.ns; pdd.type = nss.name; // Use direct Create/Delete, because switching namespaces - if ((pd = q.permDAO.create(trans, pdd)).isOK()) { + if ((pd = q.permDAO().create(trans, pdd)).isOK()) { // Put Role back into Perm, with correct info for (RoleDAO.Data rdd : lrdd) { - q.roleDAO.addPerm(trans, rdd, pdd); + q.roleDAO().addPerm(trans, rdd, pdd); } pdd.ns = delP1; pdd.type = delP2; - if ((rv = q.permDAO.delete(trans, pdd, false)).notOK()) { + if ((rv = q.permDAO().delete(trans, pdd, false)).notOK()) { sb.append(rv.details); sb.append('\n'); // } else { // Need to invalidate directly, because we're switching // places in NS, not normal cache behavior - // q.permDAO.invalidate(trans,pdd); + // q.permDAO().invalidate(trans,pdd); } } else { sb.append(pd.details); @@ -884,7 +898,7 @@ public class Function { if (rpdd.isOKhasData()) { PermDAO.Data pdd = rpdd.value; lpdd.add(pdd); - q.permDAO.delRole(trans, pdd, rdd); + q.permDAO().delRole(trans, pdd, rdd); } else{ trans.error().log(rpdd.errorString()); } @@ -897,21 +911,21 @@ public class Function { rdd.ns = nss.ns; rdd.name = nss.name; // Use direct Create/Delete, because switching namespaces - if ((rd = q.roleDAO.create(trans, rdd)).isOK()) { + if ((rd = q.roleDAO().create(trans, rdd)).isOK()) { // Put Role back into Perm, with correct info for (PermDAO.Data pdd : lpdd) { - q.permDAO.addRole(trans, pdd, rdd); + q.permDAO().addRole(trans, pdd, rdd); } rdd.ns = delP1; rdd.name = delP2; - if ((rv = q.roleDAO.delete(trans, rdd, true)).notOK()) { + if ((rv = q.roleDAO().delete(trans, rdd, true)).notOK()) { sb.append(rv.details); sb.append('\n'); // } else { // Need to invalidate directly, because we're switching // places in NS, not normal cache behavior - // q.roleDAO.invalidate(trans,rdd); + // q.roleDAO().invalidate(trans,rdd); } } else { sb.append(rd.details); @@ -946,7 +960,7 @@ public class Function { // Does Child exist? if (!trans.requested(REQD_TYPE.force)) { - if (q.permDAO.read(trans, perm).isOKhasData()) { + if (q.permDAO().read(trans, perm).isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, "Permission [%s.%s|%s|%s] already exists.", perm.ns, perm.type, perm.instance, perm.action); @@ -976,22 +990,22 @@ public class Function { } Result> rlrd; - if ((rlrd = q.roleDAO.read(trans, rd)).notOKorIsEmpty()) { + if ((rlrd = q.roleDAO().read(trans, rd)).notOKorIsEmpty()) { rd.perms(true).add(pstring); - if (q.roleDAO.create(trans, rd).notOK()) { + if (q.roleDAO().create(trans, rd).notOK()) { roles.remove(role); // Role doesn't exist, and can't be // created } } else { rd = rlrd.value.get(0); if (!rd.perms.contains(pstring)) { - q.roleDAO.addPerm(trans, rd, perm); + q.roleDAO().addPerm(trans, rd, perm); } } } } - Result pdr = q.permDAO.create(trans, perm); + Result pdr = q.permDAO().create(trans, perm); if (pdr.isOK()) { return Result.ok(); } else { @@ -1011,7 +1025,7 @@ public class Function { } } // Does Perm exist? - Result> pdr = q.permDAO.read(trans, perm); + Result> pdr = q.permDAO().read(trans, perm); if (pdr.notOKorIsEmpty()) { return Result.err(Status.ERR_PermissionNotFound,"Permission [%s.%s|%s|%s] does not exist.", perm.ns,perm.type, perm.instance, perm.action); @@ -1027,7 +1041,7 @@ public class Function { Result rrdd = RoleDAO.Data.decode(trans, q, role); if (rrdd.isOKhasData()) { trans.debug().log("Removing", role, "from", fullperm, "on Perm Delete"); - if ((rv = q.roleDAO.delPerm(trans, rrdd.value, fullperm)).notOK()) { + if ((rv = q.roleDAO().delPerm(trans, rrdd.value, fullperm)).notOK()) { if (rv.notOK()) { trans.error().log("Error removing Role during delFromPermRole: ", trans.getUserPrincipal(), @@ -1046,7 +1060,7 @@ public class Function { } } - return q.permDAO.delete(trans, fullperm, false); + return q.permDAO().delete(trans, fullperm, false); } public Result deleteRole(final AuthzTrans trans, final RoleDAO.Data role, boolean force, boolean fromApproval) { @@ -1062,11 +1076,11 @@ public class Function { } // Are there any Users Attached to Role? - Result> urdr = q.userRoleDAO.readByRole(trans,role.fullName()); + Result> urdr = q.userRoleDAO().readByRole(trans,role.fullName()); if (force) { if (urdr.isOKhasData()) { for (UserRoleDAO.Data urd : urdr.value) { - q.userRoleDAO.delete(trans, urd, false); + q.userRoleDAO().delete(trans, urd, false); } } } else if (urdr.isOKhasData()) { @@ -1076,7 +1090,7 @@ public class Function { } // Does Role exist? - Result> rdr = q.roleDAO.read(trans, role); + Result> rdr = q.roleDAO().read(trans, role); if (rdr.notOKorIsEmpty()) { return Result.err(Status.ERR_RoleNotFound, "Role [%s.%s] does not exist", role.ns, role.name); @@ -1090,7 +1104,7 @@ public class Function { if (rpd.isOK()) { trans.debug().log("Removing", perm, "from", fullrole,"on Role Delete"); - Result r = q.permDAO.delRole(trans, rpd.value, fullrole); + Result r = q.permDAO().delRole(trans, rpd.value, fullrole); if (r.notOK()) { trans.error().log("ERR_FDR1 unable to remove",fullrole,"from",perm,':',r.status,'-',r.details); } @@ -1099,7 +1113,7 @@ public class Function { } } } - return q.roleDAO.delete(trans, fullrole, false); + return q.roleDAO().delete(trans, fullrole, false); } /** @@ -1149,7 +1163,7 @@ public class Function { } // Final Check... Don't allow Grantees to add to Roles they are // part of - Result> rlurd = q.userRoleDAO + Result> rlurd = q.userRoleDAO() .readByUser(trans, trans.user()); if (rlurd.isOK()) { for (UserRoleDAO.Data ur : rlurd.value) { @@ -1161,13 +1175,13 @@ public class Function { } } - Result> rlpd = q.permDAO.read(trans, pd); + Result> rlpd = q.permDAO().read(trans, pd); if (rlpd.notOKorIsEmpty()) { return Result.err(Status.ERR_PermissionNotFound, "Permission must exist to add to Role"); } - Result> rlrd = q.roleDAO.read(trans, role); // Already + Result> rlrd = q.roleDAO().read(trans, role); // Already // Checked // for // can @@ -1187,7 +1201,7 @@ public class Function { } role.perms(true).add(pd.encode()); - Result rdd = q.roleDAO.create(trans, role); + Result rdd = q.roleDAO().create(trans, role); if (rdd.isOK()) { rv = Result.ok(); } else { @@ -1207,10 +1221,10 @@ public class Function { role.perms(true).add(pd.encode()); // this is added for Caching // access purposes... doesn't // affect addPerm - rv = q.roleDAO.addPerm(trans, role, pd); + rv = q.roleDAO().addPerm(trans, role, pd); } if (rv.status == Status.OK) { - return q.permDAO.addRole(trans, pd, role); + return q.permDAO().addRole(trans, pd, role); // exploring how to add information message to successful http // request } @@ -1241,13 +1255,13 @@ public class Function { } } - Result> rlr = q.roleDAO.read(trans, role); + Result> rlr = q.roleDAO().read(trans, role); if (rlr.notOKorIsEmpty()) { // If Bad Data, clean out - Result> rlp = q.permDAO.read(trans, pd); + Result> rlp = q.permDAO().read(trans, pd); if (rlp.isOKhasData()) { for (PermDAO.Data pv : rlp.value) { - q.permDAO.delRole(trans, pv, role); + q.permDAO().delRole(trans, pv, role); } } return Result.err(rlr); @@ -1279,12 +1293,12 @@ public class Function { } // Read Perm for full data - Result> rlp = q.permDAO.read(trans, pd); + Result> rlp = q.permDAO().read(trans, pd); Result rv = null; if (rlp.isOKhasData()) { for (PermDAO.Data pv : rlp.value) { - if ((rv = q.permDAO.delRole(trans, pv, role)).isOK()) { - if ((rv = q.roleDAO.delPerm(trans, role, pv)).notOK()) { + if ((rv = q.permDAO().delRole(trans, pv, role)).isOK()) { + if ((rv = q.roleDAO().delPerm(trans, role, pv)).notOK()) { trans.error().log( "Error removing Perm during delFromPermRole:", trans.getUserPrincipal(), rv.errorString()); @@ -1296,7 +1310,7 @@ public class Function { } } } else { - rv = q.roleDAO.delPerm(trans, role, pd); + rv = q.roleDAO().delPerm(trans, role, pd); if (rv.notOK()) { trans.error().log("Error removing Role during delFromPermRole", rv.errorString()); @@ -1342,11 +1356,11 @@ public class Function { } // Check if record exists - if (q.userRoleDAO.read(trans, urData).isOKhasData()) { + if (q.userRoleDAO().read(trans, urData).isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, "User Role exists"); } - if (q.roleDAO.read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { + if (q.roleDAO().read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { return Result.err(Status.ERR_RoleNotFound, "Role [%s.%s] does not exist", urData.ns, urData.rname); } @@ -1354,7 +1368,7 @@ public class Function { urData.expires = trans.org().expiration(null, Expiration.UserInRole, urData.user).getTime(); - Result udr = q.userRoleDAO.create(trans, urData); + Result udr = q.userRoleDAO().create(trans, urData); if (udr.status == OK) { return Result.ok(); } @@ -1388,12 +1402,12 @@ public class Function { */ public Result extendUserRole(AuthzTrans trans, UserRoleDAO.Data urData, boolean checkForExist) { // Check if record still exists - if (checkForExist && q.userRoleDAO.read(trans, urData).notOKorIsEmpty()) { + if (checkForExist && q.userRoleDAO().read(trans, urData).notOKorIsEmpty()) { return Result.err(Status.ERR_UserRoleNotFound, "User Role does not exist"); } - if (q.roleDAO.read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { + if (q.roleDAO().read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { return Result.err(Status.ERR_RoleNotFound, "Role [%s.%s] does not exist", urData.ns,urData.rname); } @@ -1407,7 +1421,7 @@ public class Function { // time // starting // today - return q.userRoleDAO.update(trans, urData); + return q.userRoleDAO().update(trans, urData); } // //////////////////////////////////////////////////// @@ -1418,7 +1432,7 @@ public class Function { // Roles // //////////////////////////////////////////////////// public Result> getUsersByRole(AuthzTrans trans, String role, boolean includeExpired) { - Result> rurdd = q.userRoleDAO.readByRole(trans,role); + Result> rurdd = q.userRoleDAO().readByRole(trans,role); if (rurdd.notOK()) { return Result.err(rurdd); } @@ -1437,7 +1451,7 @@ public class Function { UserRoleDAO.Data urdd = new UserRoleDAO.Data(); urdd.user = user; urdd.role(ns,rname); - Result> r = q.userRoleDAO.read(trans, urdd); + Result> r = q.userRoleDAO().read(trans, urdd); if (r.status == 404 || r.isEmpty()) { return Result.err(Status.ERR_UserRoleNotFound, "UserRole [%s] [%s.%s]", user, ns, rname); @@ -1446,7 +1460,7 @@ public class Function { return Result.err(r); } - return q.userRoleDAO.delete(trans, urdd, false); + return q.userRoleDAO().delete(trans, urdd, false); } public Result createFuture(AuthzTrans trans, FutureDAO.Data data, String id, String user, @@ -1458,7 +1472,7 @@ public class Function { List approvers = op.equals(FUTURE_OP.A)?NO_ADDL_APPROVE:org.getApprovers(trans, user); List owners = new ArrayList<>(); if (nsd != null) { - Result> rrbr = q.userRoleDAO + Result> rrbr = q.userRoleDAO() .readByRole(trans, nsd.name + Question.DOT_OWNER); if (rrbr.isOKhasData()) { for (UserRoleDAO.Data urd : rrbr.value) { @@ -1478,7 +1492,7 @@ public class Function { // Create Future Object - Result fr = q.futureDAO.create(trans, data, id); + Result fr = q.futureDAO().create(trans, data, id); if (fr.isOK()) { sb.append("Created Future: "); sb.append(data.id); @@ -1518,7 +1532,7 @@ public class Function { public Lookup urDBLookup = new Lookup() { @Override public UserRoleDAO.Data get(AuthzTrans trans, Object ... keys) { - Result> r = q.userRoleDAO.read(trans, keys); + Result> r = q.userRoleDAO().read(trans, keys); if (r.isOKhasData()) { return r.value.get(0); } else { @@ -1549,11 +1563,11 @@ public class Function { // Get Current UserRole from lookup UserRoleDAO.Data lurdd = lur.get(trans, urdd.user,urdd.role); if (lurdd==null) { - q.futureDAO.delete(trans, curr, false); + q.futureDAO().delete(trans, curr, false); return OP_STATUS.RL; } else { if (curr.expires.compareTo(lurdd.expires)<0) { - q.futureDAO.delete(trans, curr, false); + q.futureDAO().delete(trans, curr, false); return OP_STATUS.RL; } } @@ -1593,7 +1607,7 @@ public class Function { Result ros=null; if (aDenial) { ros = OP_STATUS.RD; - if (q.futureDAO.delete(trans, curr, false).notOK()) { + if (q.futureDAO().delete(trans, curr, false).notOK()) { trans.info().printf("Future %s could not be deleted", curr.id.toString()); } else { if (FOP_USER_ROLE.equalsIgnoreCase(curr.target)) { @@ -1623,7 +1637,7 @@ public class Function { data.reconstitute(curr.construct); switch(fop) { case C: - ros = set(OP_STATUS.RE,q.roleDAO.dao().create(trans, data)); + ros = set(OP_STATUS.RE,q.roleDAO().dao().create(trans, data)); break; case D: ros = set(OP_STATUS.RE,deleteRole(trans, data, true, true)); @@ -1693,10 +1707,10 @@ public class Function { data.reconstitute(curr.construct); switch(fop) { case C: - ros = set(OP_STATUS.RE,q.delegateDAO.create(trans, data)); + ros = set(OP_STATUS.RE,q.delegateDAO().create(trans, data)); break; case U: - ros = set(OP_STATUS.RE,q.delegateDAO.update(trans, data)); + ros = set(OP_STATUS.RE,q.delegateDAO().update(trans, data)); break; default: } @@ -1704,7 +1718,7 @@ public class Function { CredDAO.Data data = new CredDAO.Data(); data.reconstitute(curr.construct); if (fop == FUTURE_OP.C) { - ros = set(OP_STATUS.RE, q.credDAO.dao().create(trans, data)); + ros = set(OP_STATUS.RE, q.credDAO().dao().create(trans, data)); } } } catch (Exception e) { @@ -1712,7 +1726,7 @@ public class Function { " \n occurred while performing", curr.memo, " from Ticket ", curr.id.toString()); } - q.futureDAO.delete(trans, curr, false); + q.futureDAO().delete(trans, curr, false); } // end for goDecision if (ros==null) { //return Result.err(Status.ACC_Future, "Full Approvals not obtained: No action taken"); @@ -1743,7 +1757,7 @@ public class Function { ad.type = type; ad.operation = op.name(); // Note ad.updated is created in System - Result r = q.approvalDAO.create(trans,ad); + Result r = q.approvalDAO().create(trans,ad); if (r.isOK()) { if (first[0]) { first[0] = false; diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java index 98621457..8d15c958 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java @@ -76,7 +76,7 @@ class PermLookup { public Result> getUserRoles() { if (userRoles==null) { - userRoles = q.userRoleDAO.readByUser(trans,user); + userRoles = q.userRoleDAO().readByUser(trans,user); if (userRoles.isOKhasData()) { List lurdd = new ArrayList<>(); Date now = new Date(); @@ -110,7 +110,7 @@ class PermLookup { if (urdata.ns==null || urdata.rname==null) { return Result.err(Status.ERR_BadData,"DB Content Error: nulls in User Role %s %s", urdata.user,urdata.role); } else { - Result> rlrd = q.roleDAO.read( + Result> rlrd = q.roleDAO().read( trans, urdata.ns, urdata.rname); if (rlrd.isOK()) { lrdd.addAll(rlrd.value); @@ -155,7 +155,7 @@ class PermLookup { Result ap = PermDAO.Data.decodeToArray(trans, q, perm); if (ap.isOK()) { - Result> rlpd = q.permDAO.read(perm,trans,ap.value); + Result> rlpd = q.permDAO().read(perm,trans,ap.value); if (rlpd.isOKhasData()) { for (PermDAO.Data pData : rlpd.value) { lpdd.add(pData); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java index 7201958d..bd0c8355 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java @@ -61,6 +61,7 @@ import org.onap.aaf.auth.dao.cass.PermDAO; import org.onap.aaf.auth.dao.cass.RoleDAO; import org.onap.aaf.auth.dao.cass.Status; import org.onap.aaf.auth.dao.cass.UserRoleDAO; +import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.env.AuthzTrans.REQD_TYPE; import org.onap.aaf.auth.env.AuthzTransFilter; @@ -129,20 +130,65 @@ public class Question { private static Slot transIDSlot = null; - public final HistoryDAO historyDAO; - public final CachedNSDAO nsDAO; - public CachedRoleDAO roleDAO; - public final CachedPermDAO permDAO; - public CachedUserRoleDAO userRoleDAO; - public final CachedCredDAO credDAO; - public final CachedCertDAO certDAO; - public final DelegateDAO delegateDAO; - public final FutureDAO futureDAO; - public final ApprovalDAO approvalDAO; - private final CacheInfoDAO cacheInfoDAO; + private final HistoryDAO historyDAO; + public HistoryDAO historyDAO() { + return historyDAO; + } + + private final CachedNSDAO nsDAO; + public CachedNSDAO nsDAO() { + return nsDAO; + } + + private final CachedRoleDAO roleDAO; + public CachedRoleDAO roleDAO() { + return roleDAO; + } + + private final CachedPermDAO permDAO; + public CachedPermDAO permDAO() { + return permDAO; + } + + private final CachedUserRoleDAO userRoleDAO; + public CachedUserRoleDAO userRoleDAO() { + return userRoleDAO; + } + + private final CachedCredDAO credDAO; + public CachedCredDAO credDAO() { + return credDAO; + } + + private final CachedCertDAO certDAO; + public CachedCertDAO certDAO() { + return certDAO; + } + + private final DelegateDAO delegateDAO; + public DelegateDAO delegateDAO() { + return delegateDAO; + } + + private final FutureDAO futureDAO; + public FutureDAO futureDAO() { + return futureDAO; + } + + private final ApprovalDAO approvalDAO; + public ApprovalDAO approvalDAO() { + return approvalDAO; + } + public final LocateDAO locateDAO; + public LocateDAO locateDAO() { + return locateDAO; + } + + private final CacheInfoDAO cacheInfoDAO; + private final int cldays; - public Question(AuthzTrans trans, Cluster cluster, String keyspace, boolean startClean) throws APIException, IOException { + public Question(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { PERMS = trans.slot("USER_PERMS"); trans.init().log("Instantiating DAOs"); long expiresIn = Long.parseLong(trans.getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF)); @@ -163,14 +209,6 @@ public class Question { delegateDAO = new DelegateDAO(trans, historyDAO); approvalDAO = new ApprovalDAO(trans, historyDAO); - // Only want to aggressively cleanse User related Caches... The others, - // just normal refresh - if (startClean) { - CachedDAO.startCleansing(trans.env(), credDAO, userRoleDAO); - CachedDAO.startRefresh(trans.env(), cacheInfoDAO); - } - // Set a Timer to Check Caches to send messages for Caching changes - if (specialLogSlot==null) { specialLogSlot = trans.slot(AuthzTransFilter.SPECIAL_LOG_SLOT); } @@ -180,9 +218,17 @@ public class Question { } AbsCassDAO.primePSIs(trans); + + cldays = Integer.parseInt(trans.getProperty(Config.AAF_CRED_WARN_DAYS, Config.AAF_CRED_WARN_DAYS_DFT)); } - + public void startTimers(AuthzEnv env) { + // Only want to aggressively cleanse User related Caches... The others, + // just normal refresh + CachedDAO.startCleansing(env, credDAO, userRoleDAO); + CachedDAO.startRefresh(env, cacheInfoDAO); + } + public void close(AuthzTrans trans) { historyDAO.close(trans); cacheInfoDAO.close(trans); @@ -784,7 +830,7 @@ public class Question { case CredDAO.BASIC_AUTH: byte[] md5=Hash.hashMD5(cred); if (Hash.compareTo(md5,dbcred)==0) { - checkLessThanDays(trans,7,now,cdd); + checkLessThanDays(trans,cldays,now,cdd); return Result.ok(cdd.expires); } else if (debug!=null) { load(debug, cdd); @@ -797,7 +843,7 @@ public class Question { byte[] hash = Hash.hashSHA256(bb.array()); if (Hash.compareTo(hash,dbcred)==0) { - checkLessThanDays(trans,7,now,cdd); + checkLessThanDays(trans,cldays,now,cdd); return Result.ok(cdd.expires); } else if (debug!=null) { load(debug, cdd); @@ -849,8 +895,9 @@ public class Question { long cexp=cdd.expires.getTime(); if (cexp retVal1 = new Result(null,1,"",new String[0]); + Result retVal1 = new Result(null,1,"",NO_PARAM); Mockito.doReturn(retVal1).when(q).deriveNsSplit(trans, "test"); boolean retVal = cassExecutorObj.inRole("test"); @@ -99,7 +101,7 @@ public class JU_CassExecutor { public void testNamespace() { f =new Function(trans, q); CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Result retVal1 = new Result(null,1,"",new String[0]); + Result retVal1 = new Result(null,1,"",NO_PARAM); Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); String retVal=""; @@ -123,7 +125,7 @@ public class JU_CassExecutor { @Test public void testNamespaceSuccess() { - Mockito.doAnswer(new Answer() { + Mockito.doAnswer(new Answer() { private int count = 0; public Object answer(InvocationOnMock invocation) { @@ -135,13 +137,13 @@ public class JU_CassExecutor { }).when(trans).user(); f =new Function(trans, q); CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Result retVal1 = new Result(null,0,"",new String[0]); + Result retVal1 = new Result(null,0,"",NO_PARAM); Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); - String retVal=""; +// String retVal=""; try { - retVal = cassExecutorObj.namespace(); + /*retVal =*/ cassExecutorObj.namespace(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java index 1f2727ce..ab7b2e59 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java @@ -27,11 +27,8 @@ import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; import java.io.IOException; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.nio.ByteBuffer; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -83,6 +80,8 @@ import org.onap.aaf.misc.env.LogTarget; public class JU_Function { + private static final Object NO_PARAM = new Object[0]; + @Mock AuthzTrans trans; @Mock @@ -91,40 +90,72 @@ public class JU_Function { @Mock Question ques; + @Mock + Organization org; + + @Mock + CachedNSDAO nsDAO; + + @Mock + CachedRoleDAO roleDAO; + + @Mock + CachedPermDAO permDAO; + + @Mock + CachedCredDAO credDAO; + + @Mock + CachedUserRoleDAO userRoleDAO; + + @Mock + ApprovalDAO approvalDAO; + + @Mock + FutureDAO futureDAO; + @Before public void setUp() throws APIException, IOException { initMocks(this); - } + Mockito.doReturn(org).when(trans).org(); + Mockito.doReturn(nsDAO).when(ques).nsDAO(); + Mockito.doReturn(roleDAO).when(ques).roleDAO(); + Mockito.doReturn(permDAO).when(ques).permDAO(); + Mockito.doReturn(credDAO).when(ques).credDAO(); + Mockito.doReturn(userRoleDAO).when(ques).userRoleDAO(); + Mockito.doReturn(approvalDAO).when(ques).approvalDAO(); + Mockito.doReturn(futureDAO).when(ques).futureDAO(); - @Test - public void testCreateNs() { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); + try { Define.set(access); } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } + } + + @Test + public void testCreateNs() { Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List owner = new ArrayList(); namespace.owner = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - + + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result retVal = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result retVal = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + //setQuestion(ques, cachedNS); Function funcObj = new Function(trans, ques); Result result = funcObj.createNS(trans, namespace, true); @@ -133,16 +164,6 @@ public class JU_Function { @Test public void testCreateNsReadSuccess() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List owner = new ArrayList(); @@ -157,13 +178,11 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result retVal = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result retVal = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Function funcObj = new Function(trans, ques); Result result = funcObj.createNS(trans, namespace, true); @@ -172,16 +191,6 @@ public class JU_Function { @Test public void testCreateNsFromApprovaFalse() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List owner = new ArrayList(); @@ -192,9 +201,9 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result retVal2 = new Result(data,1,"test",new String[0]); + Result retVal2 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); Function funcObj = new Function(trans, ques); @@ -209,16 +218,6 @@ public class JU_Function { @Test public void testCreateNsownerLoop() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List owner = new ArrayList(); @@ -265,16 +264,6 @@ public class JU_Function { @Test public void testCreateNsownerLoopException() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test"; List owner = new ArrayList(); @@ -297,7 +286,7 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,1,"test",new String[0]); + Result retVal1 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Result result = funcObj.createNS(trans, namespace, true); @@ -305,195 +294,19 @@ public class JU_Function { assertTrue(result.details.contains("may not create Root Namespaces")); Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - retVal1 = new Result(data,0,"test",new String[0]); + retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, null); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result retVal = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result retVal = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); result = funcObj.createNS(trans, namespace, true); assertTrue(24 == result.status); } - - public void setQuestion(Question ques, CachedNSDAO userRoleDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("nsDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, userRoleDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setQuestionCredDao(Question ques, CachedCredDAO credDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("credDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, credDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setQuestionUserRoleDao(Question ques, CachedUserRoleDAO credDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("userRoleDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, credDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public void setQuestionCachedRoleDao(Question ques, CachedRoleDAO credDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("roleDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, credDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setQuestionCachedPermDao(Question ques, CachedPermDAO credDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("permDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, credDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public void setQuestionFutureDao(Question ques, FutureDAO futureDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("futureDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, futureDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public void setQuestionApprovalDao(Question ques, ApprovalDAO approvalDaoObj) { - Field nsDaoField; - try { - nsDaoField = Question.class.getDeclaredField("approvalDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ques, approvalDaoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + @Test public void testCreateNsAdminLoop() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List owner = new ArrayList(); @@ -506,14 +319,12 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); - Result retVal = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(nsDaoObj).create(Mockito.any(), Mockito.any()); + Result retVal = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); List dataObj = new ArrayList<>(); CredDAO.Data indData = new CredDAO.Data(); indData.id = "test"; @@ -526,10 +337,8 @@ public class JU_Function { e1.printStackTrace(); } dataObj.add(indData); - Result> retVal2 = new Result>(dataObj,0,"test",new String[0]); + Result> retVal2 = new Result>(dataObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); - setQuestionCredDao(ques, credDAO); Identity iden=Mockito.mock(Identity.class); try { @@ -541,6 +350,9 @@ public class JU_Function { e.printStackTrace(); } + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + Function funcObj = new Function(trans, ques); Result result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == 1); @@ -571,17 +383,12 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); - Result retVal = new Result(null,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(nsDaoObj).create(Mockito.any(), Mockito.any()); + Result retVal = new Result(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); List dataObj = new ArrayList<>(); CredDAO.Data indData = new CredDAO.Data(); indData.id = "test"; @@ -615,25 +422,20 @@ public class JU_Function { indData5.type = "test"; dataObj5.add(indData5); - Result> retVal2 = new Result>(dataObj,0,"test",new String[0]); - Result> retVal6 = new Result>(dataObj,1,"test",new String[0]); - Result> retVal3 = new Result>(dataObj1,0,"test",new String[0]); - Result> retVal4 = new Result>(dataObj4,0,"test",new String[0]); - Result> retVal5 = new Result>(dataObj5,0,"test",new String[0]); + Result> retVal2 = new Result>(dataObj,0,"test",NO_PARAM); + Result> retVal6 = new Result>(dataObj,1,"test",NO_PARAM); + Result> retVal3 = new Result>(dataObj1,0,"test",NO_PARAM); + Result> retVal4 = new Result>(dataObj4,0,"test",NO_PARAM); + Result> retVal5 = new Result>(dataObj5,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal6).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal6).when(cachedRoleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal2).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal5).when(cachedPermDAO).readChildren(trans, "test", "test"); - Mockito.doReturn(retVal5).when(cachedPermDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readChildren(trans, "test", "test"); - setQuestion(ques, nsDaoObj); - setQuestionCredDao(ques, credDAO); - setQuestionUserRoleDao(ques, userRoleDAO); - setQuestionCachedRoleDao(ques, cachedRoleDAO); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal6).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal6).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); + Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); Identity iden=Mockito.mock(Identity.class); try { @@ -647,6 +449,9 @@ public class JU_Function { } Function funcObj = new Function(trans, ques); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + Result result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == Status.ERR_ActionNotCompleted); @@ -654,16 +459,6 @@ public class JU_Function { @Test public void testCreateNsAdminLoopCreateSuc() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List owner = new ArrayList(); @@ -676,17 +471,12 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); - Result retVal = new Result(null,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(nsDaoObj).create(Mockito.any(), Mockito.any()); + Result retVal = new Result(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); List dataObj = new ArrayList<>(); CredDAO.Data indData = new CredDAO.Data(); indData.id = "test"; @@ -723,24 +513,19 @@ public class JU_Function { indData5.roles = rolesSet; dataObj5.add(indData5); - Result> retVal2 = new Result>(dataObj,0,"test",new String[0]); - Result> retVal3 = new Result>(dataObj1,0,"test",new String[0]); - Result> retVal4 = new Result>(dataObj4,0,"test",new String[0]); - Result> retVal5 = new Result>(dataObj5,0,"test",new String[0]); + Result> retVal2 = new Result>(dataObj,0,"test",NO_PARAM); + Result> retVal3 = new Result>(dataObj1,0,"test",NO_PARAM); + Result> retVal4 = new Result>(dataObj4,0,"test",NO_PARAM); + Result> retVal5 = new Result>(dataObj5,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal2).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal2).when(cachedRoleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal2).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal5).when(cachedPermDAO).readChildren(trans, "test", "test"); - Mockito.doReturn(retVal5).when(cachedPermDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readChildren(trans, "test", "test"); - setQuestion(ques, nsDaoObj); - setQuestionCredDao(ques, credDAO); - setQuestionUserRoleDao(ques, userRoleDAO); - setQuestionCachedRoleDao(ques, cachedRoleDAO); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal2).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); + Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); Identity iden=Mockito.mock(Identity.class); try { @@ -753,6 +538,9 @@ public class JU_Function { e.printStackTrace(); } + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + Function funcObj = new Function(trans, ques); Result result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == 0); @@ -761,77 +549,43 @@ public class JU_Function { @Test public void test4DeleteNs() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result retVal = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result retVal = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Function funcObj = new Function(trans, ques); Result result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == Status.ERR_NsNotFound); } + @Test - public void test4DeleteCanMOveFail() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.move); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); + public void test4DeleteCanMoveFail() { List dataAl = new ArrayList(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result> retVal = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result> retVal = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Mockito.doReturn(false).when(ques).canMove(Mockito.any()); + Mockito.doReturn(retVal).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); Function funcObj = new Function(trans, ques); Result result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == Status.ERR_Denied); + assertTrue(result.status == Status.ERR_Security); } + @Test public void test4DeleteNsReadSuc() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); List dataAl = new ArrayList(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result> retVal = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result> retVal = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Result retVal2 = new Result(null,1,"test",new String[0]); + Result retVal2 = new Result(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); Function funcObj = new Function(trans, ques); @@ -839,28 +593,17 @@ public class JU_Function { assertTrue(result.status == 1); } + @Test public void test4DeleteNsMayUserSuc() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); List dataAl = new ArrayList(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result> retVal = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result> retVal = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Result retVal2 = new Result(null,0,"test",new String[0]); + Result retVal2 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); Function funcObj = new Function(trans, ques); @@ -869,26 +612,19 @@ public class JU_Function { Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); - setQuestionCredDao(ques, credDAO); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); - Result> retVal5 = new Result>(null,0,"test",new String[0]); - Mockito.doReturn(retVal5).when(cachedPermDAO).readNS(trans, "test"); - setQuestionCachedPermDao(ques, cachedPermDAO); + Result> retVal5 = new Result>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); - CachedUserRoleDAO cachedUserRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; indData4.rname = "test"; dataObj4.add(indData4); - Result> retVal4 = new Result>(dataObj4,0,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedUserRoleDAO).readByRole(trans, "test"); - setQuestionUserRoleDao(ques, cachedUserRoleDAO); + Result> retVal4 = new Result>(dataObj4,0,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(trans, "test"); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); List dataObj1 = new ArrayList<>(); RoleDAO.Data indData1 = new RoleDAO.Data(); indData1.ns = "test"; @@ -897,17 +633,14 @@ public class JU_Function { permsSet.add("test|test"); indData1.perms = permsSet; dataObj1.add(indData1); - Result> retVal3 = new Result>(dataObj1,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(cachedRoleDAO).read(trans, indData1); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Result> retVal3 = new Result>(dataObj1,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == Status.ERR_DependencyExists); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - setQuestionUserRoleDao(ques, userRoleDAO); Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); @@ -917,26 +650,14 @@ public class JU_Function { } @Test public void test4DeleteNsDrivensFailure() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); List dataAl = new ArrayList(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result> retVal = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result> retVal = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Result retVal2 = new Result(null,0,"test",new String[0]); + Result retVal2 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); Function funcObj = new Function(trans, ques); @@ -945,24 +666,19 @@ public class JU_Function { Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); - setQuestionCredDao(ques, credDAO); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); List dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; indData5.type = "test"; dataObj5.add(indData5); - Result> retVal5 = new Result>(dataObj5,0,"test",new String[0]); - Mockito.doReturn(retVal5).when(cachedPermDAO).readNS(trans, "test"); - Mockito.doReturn(retVal5).when(cachedPermDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal5).when(cachedPermDAO).read(trans, indData5); - setQuestionCachedPermDao(ques, cachedPermDAO); + Result> retVal5 = new Result>(dataObj5,0,"test",NO_PARAM); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); List dataObj1 = new ArrayList<>(); RoleDAO.Data indData1 = new RoleDAO.Data(); indData1.ns = "test"; @@ -971,11 +687,10 @@ public class JU_Function { permsSet.add("test|test"); indData1.perms = permsSet; dataObj1.add(indData1); - Result> retVal3 = new Result>(dataObj1,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal3).when(cachedRoleDAO).read(trans, indData1); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Result> retVal3 = new Result>(dataObj1,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); @@ -983,7 +698,7 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,1,"test",new String[0]); + Result retVal1 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); @@ -991,33 +706,22 @@ public class JU_Function { result = funcObj.deleteNS(trans, "test.test"); assertTrue(result.status == 1); } + @Test public void test4DeleteNsWithDot() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); List dataAl = new ArrayList(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result> retVal = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result> retVal = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); List nsDataList = new ArrayList(); CredDAO.Data nsData = new CredDAO.Data(); nsData.id="test"; nsDataList.add(nsData); - Result> retVal21 = new Result>(nsDataList,0,"test",new String[0]); - Result retVal2 = new Result(null,0,"test",new String[0]); + Result> retVal21 = new Result>(nsDataList,0,"test",NO_PARAM); + Result retVal2 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); Function funcObj = new Function(trans, ques); @@ -1026,35 +730,28 @@ public class JU_Function { Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); Mockito.doReturn(retVal21).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal21).when(credDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - setQuestionCredDao(ques, credDAO); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); List dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; indData5.type = "test"; dataObj5.add(indData5); - Result> retVal5 = new Result>(dataObj5,0,"test",new String[0]); - Mockito.doReturn(retVal5).when(cachedPermDAO).readNS(trans, "test"); - Mockito.doReturn(retVal5).when(cachedPermDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal5).when(cachedPermDAO).read(trans, indData5); - setQuestionCachedPermDao(ques, cachedPermDAO); + Result> retVal5 = new Result>(dataObj5,0,"test",new Object[0]); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); - CachedUserRoleDAO cachedUserRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; indData4.rname = "test"; dataObj4.add(indData4); - Result> retVal4 = new Result>(dataObj4,0,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedUserRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal4).when(cachedUserRoleDAO).readByUser(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, cachedUserRoleDAO); + Result> retVal4 = new Result>(dataObj4,0,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal4).when(userRoleDAO).readByUser(Mockito.any(), Mockito.anyString()); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); List dataObj1 = new ArrayList<>(); RoleDAO.Data indData1 = new RoleDAO.Data(); indData1.ns = "test"; @@ -1063,11 +760,10 @@ public class JU_Function { permsSet.add("test|test"); indData1.perms = permsSet; dataObj1.add(indData1); - Result> retVal3 = new Result>(dataObj1,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(cachedRoleDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal3).when(cachedRoleDAO).read(trans, indData1); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Result> retVal3 = new Result>(dataObj1,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); @@ -1075,7 +771,7 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); @@ -1083,28 +779,17 @@ public class JU_Function { result = funcObj.deleteNS(trans, "test.test"); assertNull(result); } + @Test public void testGetOwners() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result retVal2 = new Result(null,0,"test",new String[0]); +// Result retVal2 = new Result(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); // Function funcObj = new Function(trans, ques); @@ -1115,43 +800,31 @@ public class JU_Function { @Test public void testDelOwner() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - setQuestionUserRoleDao(ques, userRoleDAO); NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result retVal2 = new Result(data,1,"test",new String[0]); + Result retVal2 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); Function funcObj = new Function(trans, ques); Result result = funcObj.delOwner(trans, "test", "test"); assertTrue(result.status == 1); - retVal1 = new Result(data,1,"test",new String[0]); + retVal1 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); assertTrue(result.status == 1); - retVal1 = new Result(data,0,"test",new String[0]); + retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); - retVal2 = new Result(data,0,"test",new String[0]); + retVal2 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); result = funcObj.delOwner(trans, "test", "test"); // @@ -1159,26 +832,14 @@ public class JU_Function { @Test public void testGetAdmins() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result retVal2 = new Result(null,0,"test",new String[0]); +// Result retVal2 = new Result(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); // Function funcObj = new Function(trans, ques); @@ -1189,43 +850,31 @@ public class JU_Function { @Test public void testDelAdmin() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readUserInRole(Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - setQuestionUserRoleDao(ques, userRoleDAO); NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result retVal2 = new Result(data,1,"test",new String[0]); + Result retVal2 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); Function funcObj = new Function(trans, ques); Result result = funcObj.delAdmin(trans, "test", "test"); assertTrue(result.status == 1); - retVal1 = new Result(data,1,"test",new String[0]); + retVal1 = new Result(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delAdmin(trans, "test", "test"); assertTrue(result.status == 1); - retVal1 = new Result(data,0,"test",new String[0]); + retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); - retVal2 = new Result(data,0,"test",new String[0]); + retVal2 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); result = funcObj.delAdmin(trans, "test", "test"); // @@ -1233,37 +882,21 @@ public class JU_Function { @Test public void testMovePerms() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - Mockito.doReturn(retVal).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); - Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); NsDAO.Data nsDataObj = new NsDAO.Data(); nsDataObj.name="test"; StringBuilder sb = new StringBuilder(); - Result> retVal1 = new Result>(null,1,"test",new String[0]); + Result> retVal1 = new Result>(null,1,"test",NO_PARAM); invokeMovePerms(nsDataObj, sb, retVal1); @@ -1279,24 +912,24 @@ public class JU_Function { indData5.ns = "test"; indData5.type = "access"; dataObj5.add(indData5); - retVal1 = new Result>(dataObj5,0,"test",new String[0]); + retVal1 = new Result>(dataObj5,0,"test",NO_PARAM); - Result> retVal3 = new Result>(null,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal3).when(cachedPermDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Result> retVal3 = new Result>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal3).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); NsSplit splitObj = new NsSplit("test", "test"); - Result retVal2 = new Result(splitObj,0,"test",new String[0]); + Result retVal2 = new Result(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); invokeMovePerms(nsDataObj, sb, retVal1); - Result> retVal4 = new Result>(null,1,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); + Result> retVal4 = new Result>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(permDAO).create(Mockito.any(), Mockito.any()); invokeMovePerms(nsDataObj, sb, retVal1); - Mockito.doReturn(retVal3).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal4).when(cachedPermDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); invokeMovePerms(nsDataObj, sb, retVal1); } @@ -1325,35 +958,21 @@ public class JU_Function { @Test public void testMoveRoles() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - Mockito.doReturn(retVal).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal).when(roleDAO).create(Mockito.any(), Mockito.any()); NsDAO.Data nsDataObj = new NsDAO.Data(); nsDataObj.name="test"; StringBuilder sb = new StringBuilder(); - Result> retVal1 = new Result>(null,1,"test",new String[0]); + Result> retVal1 = new Result>(null,1,"test",NO_PARAM); invokeMoveRoles(nsDataObj, sb, retVal1); @@ -1369,24 +988,24 @@ public class JU_Function { indData5.ns = "test"; indData5.name = "admin"; dataObj5.add(indData5); - retVal1 = new Result>(dataObj5,0,"test",new String[0]); + retVal1 = new Result>(dataObj5,0,"test",NO_PARAM); - Result> retVal3 = new Result>(null,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal3).when(cachedRoleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Result> retVal3 = new Result>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal3).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); NsSplit splitObj = new NsSplit("test", "test"); - Result retVal2 = new Result(splitObj,0,"test",new String[0]); + Result retVal2 = new Result(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); invokeMoveRoles(nsDataObj, sb, retVal1); - Result> retVal4 = new Result>(null,1,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); + Result> retVal4 = new Result>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(), Mockito.any()); invokeMoveRoles(nsDataObj, sb, retVal1); - Mockito.doReturn(retVal3).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal4).when(cachedRoleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); invokeMoveRoles(nsDataObj, sb, retVal1); } @@ -1415,11 +1034,6 @@ public class JU_Function { @Test public void testCreatePerm() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); try { Define.set(access); } catch (CadiException e) { @@ -1433,58 +1047,54 @@ public class JU_Function { perm.roles = rolesSet; // perm.type=1 dataAl.add(perm); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - CachedRoleDAO userRoleDAO = Mockito.mock(CachedRoleDAO.class); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - setQuestionCachedRoleDao(ques, userRoleDAO); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); - Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(cachedPermDAO).read(trans, perm); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); - Result retVal2 = new Result(null,1,"test",new String[0]); + Result retVal2 = new Result(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); Function funcObj = new Function(trans, ques); Result result = funcObj.createPerm(trans, perm, false); assertTrue(result.status == 1); - retVal2 = new Result(null,0,"test",new String[0]); + retVal2 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); result = funcObj.createPerm(trans, perm, false); assertTrue(result.status == 1); NsSplit nsObj = new NsSplit("test","test"); - Result retValNs = new Result(nsObj,0,"test",new String[0]); + Result retValNs = new Result(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal2).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(RoleDAO.Data.class), Mockito.any()); + Result> retVal3 = Result.ok(new ArrayList<>()); + Mockito.doReturn(retVal3).when(roleDAO).read(Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Result> retVal4 = Result.err(Result.ERR_NotFound,""); + Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(),Mockito.any(RoleDAO.Data.class)); result = funcObj.createPerm(trans, perm, false); - Mockito.doReturn(retVal).when(cachedPermDAO).read(trans, perm); + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); result = funcObj.createPerm(trans, perm, true); assertTrue(result.status == 1); - Mockito.doReturn(retVal2).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); result = funcObj.createPerm(trans, perm, true); assertTrue(result.status == 0); Mockito.doReturn(false).when(trans).requested(REQD_TYPE.force); - Result> retVal1 = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal1).when(cachedPermDAO).read(trans, perm); + Result> retVal1 = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(permDAO).read(trans, perm); result = funcObj.createPerm(trans, perm, true); assertTrue(result.status == Status.ERR_ConflictAlreadyExists); } @Test public void testDeletePerm() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); try { Define.set(access); } catch (CadiException e) { @@ -1499,47 +1109,41 @@ public class JU_Function { // perm.type=1 dataAl.add(perm); - Result retVal2 = new Result(null,1,"test",new String[0]); + Result retVal2 = new Result(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(dataAl,1,"test",new String[0]); + Result> retVal = new Result>(dataAl,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); Function funcObj = new Function(trans, ques); Result result = funcObj.deletePerm(trans, perm, true,false); assertTrue(result.status == 1); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); // Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(cachedPermDAO).read(trans, perm); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); result = funcObj.deletePerm(trans, perm, true,true); assertTrue(result.status == Status.ERR_PermissionNotFound); - retVal2 = new Result(null,0,"test",new String[0]); + retVal2 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - Result> retVal3 = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedPermDAO).read(trans, perm); + Result> retVal3 = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(permDAO).read(trans, perm); NsSplit nsObj = new NsSplit("test","test"); - Result retValNs = new Result(nsObj,0,"test",new String[0]); + Result retValNs = new Result(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - Mockito.doReturn(retVal).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); result = funcObj.deletePerm(trans, perm, true,false); assertNull(result); - Mockito.doReturn(retVal2).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); result = funcObj.deletePerm(trans, perm, true,false); assertNull(result); @@ -1549,10 +1153,6 @@ public class JU_Function { @Test public void testDeleteRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); try { Define.set(access); } catch (CadiException e) { @@ -1577,48 +1177,42 @@ public class JU_Function { // perm.type=1 dataAl.add(role); - Result retVal2 = new Result(null,1,"test",new String[0]); + Result retVal2 = new Result(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,role, Access.write); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result retVal2 = new Result(null,0,"test",new String[0]); +// Result retVal2 = new Result(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); // Function funcObj = new Function(trans, ques); Result result = funcObj.deleteRole(trans, role, true, false); assertTrue(result.status == 1); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - setQuestionCachedRoleDao(ques, cachedRoleDAO); - Result> retVal1 = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal1).when(cachedRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Result> retVal1 = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); NsSplit splitObj = new NsSplit("test", "test"); - Result retVal3 = new Result(splitObj,0,"test",new String[0]); + Result retVal3 = new Result(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); // Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(cachedPermDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); result = funcObj.deleteRole(trans, role, true, true); assertNull(result); - Mockito.doReturn(retVal1).when(cachedPermDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); + Mockito.doReturn(retVal1).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); result = funcObj.deleteRole(trans, role, true, true); assertNull(result); - Mockito.doReturn(retVal).when(cachedRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); result = funcObj.deleteRole(trans, role, true, true); assertTrue(result.status == Status.ERR_RoleNotFound); - retVal = new Result>(dataAlUser,0,"test",new String[0]); + retVal = new Result>(dataAlUser,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); result = funcObj.deleteRole(trans, role, false, true); assertTrue(result.status == Status.ERR_DependencyExists); @@ -1626,16 +1220,6 @@ public class JU_Function { @Test public void testAddPermToRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } List dataAlPerm = new ArrayList(); PermDAO.Data rolePerm = new PermDAO.Data(); Set rolesSetUser = new HashSet<>(); @@ -1658,20 +1242,18 @@ public class JU_Function { NsDAO.Data nsObj1 = new NsDAO.Data(); nsObj1.name="test12"; - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - Result retVal2 = new Result(nsObj,0,"test",new String[0]); + Result retVal2 = new Result(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - Result retVal3 = new Result(null,1,"test",new String[0]); + Result retVal3 = new Result(null,1,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); @@ -1679,45 +1261,41 @@ public class JU_Function { Result result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - retVal2 = new Result(nsObj,1,"test",new String[0]); + retVal2 = new Result(nsObj,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); role.ns="test2"; - retVal2 = new Result(nsObj,0,"test",new String[0]); + retVal2 = new Result(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - retVal2 = new Result(nsObj,0,"test1",new String[0]); + retVal2 = new Result(nsObj,0,"test1",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - Result retVal21 = new Result(nsObj1,0,"test1",new String[0]); + Result retVal21 = new Result(nsObj1,0,"test1",NO_PARAM); Mockito.doReturn(retVal21).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - retVal3 = new Result(null,0,"test",new String[0]); + retVal3 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); - retVal2 = new Result(nsObj,0,"test1",new String[0]); + retVal2 = new Result(nsObj,0,"test1",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); // Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == Status.ERR_PermissionNotFound); - Result> retValPerm= new Result>(dataAlPerm,0,"test1",new String[0]); - Mockito.doReturn(retValPerm).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Result> retValPerm= new Result>(dataAlPerm,0,"test1",NO_PARAM); + Mockito.doReturn(retValPerm).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - Mockito.doReturn(retVal3).when(cachedRoleDAO).read(trans, role); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 22); @@ -1726,36 +1304,26 @@ public class JU_Function { result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 2); - retVal3 = new Result(null,0,"test",new String[0]); + retVal3 = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); - Mockito.doReturn(retVal3).when(cachedRoleDAO).create(trans, role); + Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); // System.out.println(result.status); assertNull(result); - retVal3 = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedRoleDAO).create(trans, role); + retVal3 = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - Result> retVal31 = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal31).when(cachedRoleDAO).read(trans, role); + Result> retVal31 = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal31).when(roleDAO).read(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 7); } @Test public void testDelPermFromRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } List dataAlPerm = new ArrayList(); PermDAO.Data rolePerm = new PermDAO.Data(); Set rolesSetUser = new HashSet<>(); @@ -1771,17 +1339,15 @@ public class JU_Function { role.perms = rolesSet; dataAl.add(role); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - Result retValFail = new Result(null,1,"test",new String[0]); - Result retValSuc = new Result(null,0,"test",new String[0]); + Result retValFail = new Result(null,1,"test",NO_PARAM); + Result retValSuc = new Result(null,0,"test",NO_PARAM); Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,role, Access.write); @@ -1792,24 +1358,20 @@ public class JU_Function { Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); Mockito.doReturn(retValSuc).when(ques).mayUser(trans, null,role, Access.write); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - Mockito.doReturn(retValFail).when(cachedRoleDAO).read(trans, role); - setQuestionCachedRoleDao(ques, cachedRoleDAO); + Mockito.doReturn(retValFail).when(roleDAO).read(trans, role); - CachedPermDAO cachedPermDAO = Mockito.mock(CachedPermDAO.class); - Mockito.doReturn(retVal).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - setQuestionCachedPermDao(ques, cachedPermDAO); + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - Result> retValPermSuc = new Result>(dataAlPerm,0,"test",new String[0]); - Mockito.doReturn(retValPermSuc).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Result> retValPermSuc = new Result>(dataAlPerm,0,"test",NO_PARAM); + Mockito.doReturn(retValPermSuc).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - Result> retValRoleSuc = new Result>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retValRoleSuc).when(cachedRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Result> retValRoleSuc = new Result>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == Status.ERR_PermissionNotFound); @@ -1818,8 +1380,8 @@ public class JU_Function { rolesSet.add("null|null|null|null"); role.perms = rolesSet; dataAl.add(role); - Mockito.doReturn(retValRoleSuc).when(cachedRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(cachedPermDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); @@ -1827,48 +1389,38 @@ public class JU_Function { result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - Mockito.doReturn(retValRoleSuc).when(cachedPermDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retValRoleSuc).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - Mockito.doReturn(retValPermSuc).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retValPermSuc).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 0); - Mockito.doReturn(retVal).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 0); - Mockito.doReturn(retVal).when(cachedRoleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); NsSplit splitObj = new NsSplit("test", "test"); - Result retVal3 = new Result(splitObj,0,"test",new String[0]); + Result retVal3 = new Result(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(RoleDAO.Data.class), Mockito.any()); Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(PermDAO.Data.class), Mockito.any()); result = funcObj.delPermFromRole(trans, "test", rolePerm); assertTrue(result.status == 2); - retVal3 = new Result(null,1,"test",new String[0]); + retVal3 = new Result(null,1,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); result = funcObj.delPermFromRole(trans, "test", rolePerm); assertTrue(result.status == 1); } @Test public void testAddUserRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } List urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -1880,21 +1432,15 @@ public class JU_Function { Mockito.doReturn(org).when(trans).org(); Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any(), Mockito.anyString()); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - CachedRoleDAO roleDAO = Mockito.mock(CachedRoleDAO.class); - Result> retVal = new Result>(null,1,"test",new String[0]); - Result> retValSuc = new Result>(urDataAl,0,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); + Result> retValSuc = new Result>(urDataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - setQuestionCachedRoleDao(ques, roleDAO); - - CachedCredDAO credDAO = Mockito.mock(CachedCredDAO.class); - Result> retVal2 = new Result>(null,1,"test",new String[0]); + + Result> retVal2 = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - setQuestionCredDao(ques, credDAO); Function funcObj = new Function(trans, ques); Result result = funcObj.addUserRole(trans, urData); @@ -1906,7 +1452,7 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result retVal1 = new Result(data,0,"test",new String[0]); + Result retVal1 = new Result(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).mayUser(trans, null,retVal1.value, Access.write); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); try { @@ -1952,18 +1498,9 @@ public class JU_Function { result = funcObj.addUserRole(trans, "test", "test", "test"); assertTrue(result.status == 20); } + @Test public void testExtendUserRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } List urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -1972,18 +1509,14 @@ public class JU_Function { urData.expires=new Date(); urDataAl.add(urData); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - CachedRoleDAO roleDAO = Mockito.mock(CachedRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); - Result> retValSuc = new Result>(urDataAl,0,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); + Result> retValSuc = new Result>(urDataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - setQuestionCachedRoleDao(ques, roleDAO); Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); @@ -2003,19 +1536,9 @@ public class JU_Function { assertTrue(result.status == Status.ERR_UserRoleNotFound); } + @SuppressWarnings("deprecation") @Test public void testGetUsersByRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -2023,9 +1546,8 @@ public class JU_Function { urData.user="test"; urData.expires=new Date(); urDataAl.add(urData); - Result> retVal = new Result>(urDataAl,0,"test",new String[0]); + Result> retVal = new Result>(urDataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); Function funcObj = new Function(trans, ques); Result> result = funcObj.getUsersByRole(trans, "test", false); @@ -2041,17 +1563,6 @@ public class JU_Function { } @Test public void testDelUserRole() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -2059,15 +1570,14 @@ public class JU_Function { urData.user="test"; urData.expires=new Date(); urDataAl.add(urData); - Result> retVal = new Result>(urDataAl,0,"test",new String[0]); + Result> retVal = new Result>(urDataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - setQuestionUserRoleDao(ques, userRoleDAO); Function funcObj = new Function(trans, ques); Result result = funcObj.delUserRole(trans, "test", "test", "test"); assertNull(result); - retVal = new Result>(urDataAl,1,"test",new String[0]); + retVal = new Result>(urDataAl,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); result = funcObj.delUserRole(trans, "test", "test", "test"); // assertTrue(result.status ==1); @@ -2076,22 +1586,11 @@ public class JU_Function { @Test public void testCreateFuture() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } FutureDAO.Data data = new FutureDAO.Data(); data.memo = "test"; NsDAO.Data nsd = new NsDAO.Data(); nsd.name = "test"; - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -2099,17 +1598,14 @@ public class JU_Function { urData.user="test"; urData.expires=new Date(); urDataAl.add(urData); - Result> retVal = new Result>(urDataAl,0,"test",new String[0]); - Result> retValFail = new Result>(urDataAl,1,"test",new String[0]); + Result> retVal = new Result>(urDataAl,0,"test",NO_PARAM); + Result> retValFail = new Result>(urDataAl,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - setQuestionUserRoleDao(ques, userRoleDAO); Function funcObj = new Function(trans, ques); Result result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); assertTrue(result.status == 20); - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); Identity iden=Mockito.mock(Identity.class); try { Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); @@ -2120,17 +1616,13 @@ public class JU_Function { } FutureDAO.Data futureData = new FutureDAO.Data(); data.memo = "test"; - FutureDAO futureDaoObj = Mockito.mock(FutureDAO.class); - Result retValFuture = new Result(futureData,0,"test",new String[0]); - Mockito.doReturn(retValFuture).when(futureDaoObj).create(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyString()); - setQuestionFutureDao(ques, futureDaoObj); + Result retValFuture = new Result(futureData,0,"test",NO_PARAM); + Mockito.doReturn(retValFuture).when(futureDAO).create(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyString()); ApprovalDAO.Data approvalData = new ApprovalDAO.Data(); data.memo = "test"; - ApprovalDAO approvalDaoObj = Mockito.mock(ApprovalDAO.class); - Result retValApproval = new Result(approvalData,0,"test",new String[0]); - Mockito.doReturn(retValApproval).when(approvalDaoObj).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); - setQuestionApprovalDao(ques, approvalDaoObj); + Result retValApproval = new Result(approvalData,0,"test",NO_PARAM); + Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); @@ -2162,25 +1654,14 @@ public class JU_Function { result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.C); assertTrue(result.status == 0); - retValApproval = new Result(null,1,"test",new String[0]); - Mockito.doReturn(retValApproval).when(approvalDaoObj).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); + retValApproval = new Result(null,1,"test",NO_PARAM); + Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); assertTrue(result.status == 8); } @Test public void testUbLookup() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } Object[] objArr = new Object[10]; - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -2188,10 +1669,9 @@ public class JU_Function { urData.user="test"; urData.expires=new Date(); urDataAl.add(urData); - Result> retVal = new Result>(urDataAl,0,"test",new String[0]); - Result> retValFail = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(urDataAl,0,"test",NO_PARAM); + Result> retValFail = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).read(trans, objArr); - setQuestionUserRoleDao(ques, userRoleDAO); Function funcObj = new Function(trans, ques); funcObj.urDBLookup.get(trans, objArr); @@ -2202,17 +1682,6 @@ public class JU_Function { @Test public void testPerformFutureOp() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } FutureDAO.Data futureDataDaoObj = new FutureDAO.Data(); futureDataDaoObj.memo="test"; futureDataDaoObj.target = "test"; @@ -2240,21 +1709,17 @@ public class JU_Function { FutureDAO.Data futureData = new FutureDAO.Data(); // data.memo = "test"; - FutureDAO futureDaoObj = Mockito.mock(FutureDAO.class); - Result retValFuture = new Result(futureData,0,"test",new String[0]); - Mockito.doReturn(retValFuture).when(futureDaoObj).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); - setQuestionFutureDao(ques, futureDaoObj); + Result retValFuture = new Result(futureData,0,"test",NO_PARAM); + Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List dataAl = new ArrayList(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result> retVal = new Result>(null,1,"test",new String[0]); + Result> retVal = new Result>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result retVal2 = new Result(null,0,"test",new String[0]); +// Result retVal2 = new Result(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); // Function funcObj = new Function(trans, ques); @@ -2291,8 +1756,8 @@ public class JU_Function { result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - retValFuture = new Result(futureData,1,"test",new String[0]); - Mockito.doReturn(retValFuture).when(futureDaoObj).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); + retValFuture = new Result(futureData,1,"test",NO_PARAM); + Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); System.out.println(result); assertTrue(result.status == 0); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java index e63d4b52..9313af7a 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java @@ -64,12 +64,21 @@ public class JU_PermLookup { @Mock Access access; + + @Mock + CachedRoleDAO roleDAO; + + @Mock + CachedUserRoleDAO userRoleDAO; Function f; @Before public void setUp() throws Exception { initMocks(this); + Mockito.doReturn(userRoleDAO).when(q).userRoleDAO(); + Mockito.doReturn(roleDAO).when(q).roleDAO(); + try { Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf"); Mockito.doReturn(new Properties()).when(access).getProperties(); @@ -106,18 +115,18 @@ public class JU_PermLookup { } - @Test - public void testPerm() { - - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - -// System.out.println(cassExecutorObj); -// assertFalse(retVal); - } +// @Test +// public void testPerm() { +// +// PermLookup cassExecutorObj =PermLookup.get(trans, q,""); +// +//// System.out.println(cassExecutorObj); +//// assertFalse(retVal); +// } @Test public void testGetUserRole() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); @@ -126,7 +135,7 @@ public class JU_PermLookup { retVal1.value.add(dataObj); Mockito.doReturn(true).when(retVal1).isOKhasData(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getUserRoles(); @@ -136,12 +145,12 @@ public class JU_PermLookup { @Test public void testGetUserRolesFirstIf() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getUserRoles(); @@ -151,7 +160,7 @@ public class JU_PermLookup { @Test public void testGetUserRolesSecondIf() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); @@ -164,7 +173,7 @@ public class JU_PermLookup { retVal1.value.add(dataObj); Mockito.doReturn(true).when(retVal1).isOKhasData(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getUserRoles(); @@ -178,7 +187,7 @@ public class JU_PermLookup { @Test public void testGetRole() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); @@ -188,7 +197,7 @@ public class JU_PermLookup { retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getRoles(); @@ -198,8 +207,7 @@ public class JU_PermLookup { @Test public void testGetRoleFirstIf() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - q.roleDAO = Mockito.mock(CachedRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); @@ -211,8 +219,8 @@ public class JU_PermLookup { retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(false).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal1).when(q.roleDAO).read(trans,"",""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getRoles(); @@ -222,8 +230,7 @@ public class JU_PermLookup { @Test public void testGetRoleSecondIf() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - q.roleDAO = Mockito.mock(CachedRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); @@ -235,8 +242,8 @@ public class JU_PermLookup { retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal1).when(q.roleDAO).read(trans,"",""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getRoles(); userRoles = cassExecutorObj.getRoles(); @@ -246,12 +253,12 @@ public class JU_PermLookup { } @Test public void testGetPerms() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getPermNames(); userRoles = cassExecutorObj.getPermNames(); @@ -261,7 +268,7 @@ public class JU_PermLookup { } @Test public void testGetPermsRrldOk() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); @@ -271,7 +278,7 @@ public class JU_PermLookup { retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result> userRoles = cassExecutorObj.getPermNames(); @@ -280,10 +287,9 @@ public class JU_PermLookup { } + @SuppressWarnings("unchecked") @Test public void testGetPerm() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - q.roleDAO = Mockito.mock(CachedRoleDAO.class); Result> retVal1 = Mockito.mock(Result.class); Result> retVal2 = Mockito.mock(Result.class); @@ -316,8 +322,8 @@ public class JU_PermLookup { Mockito.doReturn(true).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); Mockito.doReturn(true).when(retVal2).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal2).when(q.roleDAO).read(trans,"",""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); @@ -330,10 +336,9 @@ public class JU_PermLookup { assertEquals(0,userRoles.status); } + @SuppressWarnings("unchecked") @Test public void testGetPermFalse() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); - q.roleDAO = Mockito.mock(CachedRoleDAO.class); Result> retVal1 = Mockito.mock(Result.class); Result> retVal2 = Mockito.mock(Result.class); @@ -366,8 +371,8 @@ public class JU_PermLookup { Mockito.doReturn(true).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); Mockito.doReturn(true).when(retVal2).isOK(); - Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal2).when(q.roleDAO).read(trans,"",""); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/ca/JscepCA.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/ca/JscepCA.java index b7dd069d..a0a97241 100644 --- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/ca/JscepCA.java +++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/ca/JscepCA.java @@ -35,18 +35,16 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.jscep.client.Client; import org.jscep.client.ClientException; import org.jscep.client.EnrollmentResponse; -import org.jscep.client.verification.CertificateVerifier; import org.onap.aaf.auth.cm.cert.BCFactory; import org.onap.aaf.auth.cm.cert.CSRMeta; import org.onap.aaf.cadi.Access; -import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.Locator.Item; +import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.configure.CertException; import org.onap.aaf.cadi.locator.HotPeerLocator; import org.onap.aaf.misc.env.Env; diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/mapper/Mapper2_0.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/mapper/Mapper2_0.java index 3ff88d27..2b9204c9 100644 --- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/mapper/Mapper2_0.java +++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/mapper/Mapper2_0.java @@ -24,6 +24,7 @@ package org.onap.aaf.auth.cm.mapper; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.onap.aaf.auth.cm.data.CertDrop; import org.onap.aaf.auth.cm.data.CertRenew; @@ -35,7 +36,6 @@ import org.onap.aaf.auth.dao.cass.ArtiDAO.Data; import org.onap.aaf.auth.dao.cass.CertDAO; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; -import org.onap.aaf.cadi.util.FQI; import org.onap.aaf.cadi.util.Vars; import aaf.v2_0.Error; @@ -208,39 +208,46 @@ public class Mapper2_0 implements Mapper { List ladd = new ArrayList<>(); for (Artifact arti : artifacts.getArtifact()) { ArtiDAO.Data data = new ArtiDAO.Data(); - data.mechid = arti.getMechid(); - data.machine = arti.getMachine(); + data.mechid = trim(arti.getMechid()); + data.machine = trim(arti.getMachine()); + Set ss = data.type(true); + if(arti.getType()!=null) { + for(String t : arti.getType()) { + ss.add(t.trim()); + } + } data.type(true).addAll(arti.getType()); - data.ca = arti.getCa(); - data.dir = arti.getDir(); - data.os_user = arti.getOsUser(); + data.ca = trim(arti.getCa()); + data.dir = trim(arti.getDir()); + data.os_user = trim(arti.getOsUser()); // Optional (on way in) - data.ns = arti.getNs(); + data.ns = trim(arti.getNs()); data.renewDays = arti.getRenewDays(); - data.notify = arti.getNotification(); + data.notify = trim(arti.getNotification()); // Ignored on way in for create/update - data.sponsor = arti.getSponsor(); + data.sponsor = trim(arti.getSponsor()); data.expires = null; - - // Derive Optional Data from Machine (Domain) if exists - if (data.machine!=null) { - if (data.ca==null) { - if (data.machine.endsWith(".att.com")) { - data.ca = "aaf"; // default - } - } - if (data.ns==null ) { - data.ns=FQI.reverseDomain(data.machine); - } + ss = data.sans(true); + if(arti.getSans()!=null) { + for(String s : arti.getSans()) { + ss.add(s.trim()); + } } - data.sans(true).addAll(arti.getSans()); ladd.add(data); } return ladd; } - /* (non-Javadoc) + private String trim(String s) { + if(s==null) { + return s; + } else { + return s.trim(); + } + } + + /* (non-Javadoc) * @see org.onap.aaf.auth.cm.mapper.Mapper#fromArtifacts(org.onap.aaf.auth.layer.test.Result) */ @Override diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/validation/CertmanValidator.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/validation/CertmanValidator.java index bb157a2e..f85eb44e 100644 --- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/validation/CertmanValidator.java +++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/validation/CertmanValidator.java @@ -72,6 +72,9 @@ public class CertmanValidator extends Validator{ } else { for (ArtiDAO.Data a : list) { allRequired(a); + if(a.dir!=null && a.dir.startsWith("/tmp")) { + msg("Certificates may not be deployed into /tmp directory (they will be removed at a random time by O/S)"); + } } } } diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/Cmd.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/Cmd.java index 49fd4869..6ca09213 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/Cmd.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/Cmd.java @@ -406,6 +406,7 @@ public abstract class Cmd { return i; } } + pw().printf("%s is not a valid cmd\n",test); throw new CadiException(build(new StringBuilder("Invalid Option: "),null).toString()); } diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Grant.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Grant.java index ca958c20..f27a2609 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Grant.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Grant.java @@ -43,7 +43,7 @@ import aaf.v2_0.RolePermRequest; * */ public class Grant extends Cmd { - private static final String[] options = {"grant","ungrant","setTo"}; + private static final String[] options = {"grant","ungrant"}; public Grant(Perm parent) { super(parent,null, @@ -51,7 +51,7 @@ public class Grant extends Cmd { new Param("type",true), new Param("instance",true), new Param("action",true), - new Param("role[,role]* (!REQ S)",false) + new Param("role[,role]*",false) ); } @@ -74,63 +74,46 @@ public class Grant extends Cmd { Future frpr = null; - if (option != 2) { - String[] roles = args[idx++].split(","); - String strA; - String strB; - for (String role : roles) { - rpr.setRole(role); - if (option==0) { - // You can request to Grant Permission to a Role - setQueryParamsOn(client); - frpr = client.create( - "/authz/role/perm", - getDF(RolePermRequest.class), - rpr - ); - strA = "Granted Permission ["; - strB = "] to Role ["; - } else { - // You can request to UnGrant Permission to a Role - setQueryParamsOn(client); - frpr = client.delete( - "/authz/role/" + role + "/perm", - getDF(RolePermRequest.class), - rpr - ); - strA = "UnGranted Permission ["; - strB = "] from Role ["; - } - if (frpr.get(AAFcli.timeout())) { - pw().println(strA + pk.getType() + '|' + pk.getInstance() + '|' + pk.getAction() - + strB + role +']'); - } else { - if (frpr.code()==202) { - pw().print("Permission Role "); - pw().print(option==0?"Granted":"Ungranted"); - pw().println(" Accepted, but requires Approvals before actualizing"); - } else { - error(frpr); - idx=Integer.MAX_VALUE; - } - } + String[] roles = args[idx++].split(","); + String strA; + String strB; + for (String role : roles) { + rpr.setRole(role); + if (option==0) { + // You can request to Grant Permission to a Role + setQueryParamsOn(client); + frpr = client.create( + "/authz/role/perm", + getDF(RolePermRequest.class), + rpr + ); + strA = "Granted Permission ["; + strB = "] to Role ["; + } else { + // You can request to UnGrant Permission to a Role + setQueryParamsOn(client); + frpr = client.delete( + "/authz/role/" + role + "/perm", + getDF(RolePermRequest.class), + rpr + ); + strA = "UnGranted Permission ["; + strB = "] from Role ["; } - } else { - String allRoles = ""; - if (idx < args.length) - allRoles = args[idx++]; - - rpr.setRole(allRoles); - frpr = client.update( - "/authz/role/perm", - getDF(RolePermRequest.class), - rpr); if (frpr.get(AAFcli.timeout())) { - pw().println("Set Permission's Roles to [" + allRoles + "]"); + pw().println(strA + pk.getType() + '|' + pk.getInstance() + '|' + pk.getAction() + + strB + role +']'); } else { - error(frpr); - } - } + if (frpr.code()==202) { + pw().print("Permission Role "); + pw().print(option==0?"Granted":"Ungranted"); + pw().println(" Accepted, but requires Approvals before actualizing"); + } else { + error(frpr); + idx=Integer.MAX_VALUE; + } + } + } return frpr==null?0:frpr.code(); } }); @@ -138,16 +121,11 @@ public class Grant extends Cmd { @Override public void detailedHelp(int indent, StringBuilder sb) { - detailLine(sb,indent,"Grant a Permission to a Role or Roles OR"); - detailLine(sb,indent,"Ungrant a Permission from a Role or Roles OR"); - detailLine(sb,indent,"Set a Permission's roles to roles supplied."); - detailLine(sb,indent+4,"WARNING: Roles supplied with setTo will be the ONLY roles attached to this permission"); - detailLine(sb,indent+8,"If no roles are supplied, permission's roles are reset."); + detailLine(sb,indent,"Grant a Permission to a Role or Roles OR"); + detailLine(sb,indent,"Ungrant a Permission from a Role or Roles"); detailLine(sb,indent,"see Create for definitions of type,instance and action"); api(sb,indent,HttpMethods.POST,"authz/role/perm",RolePermRequest.class,true); api(sb,indent,HttpMethods.DELETE,"authz/role//perm",RolePermRequest.class,false); - api(sb,indent,HttpMethods.PUT,"authz/role/perm",RolePermRequest.class,false); - } } diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/role/User.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/role/User.java index 364b3980..45361a3f 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/role/User.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/role/User.java @@ -40,12 +40,12 @@ import aaf.v2_0.UserRoleRequest; * */ public class User extends Cmd { - private final static String[] options = {"add","del","setTo","extend"}; + private final static String[] options = {"add","del","extend"}; public User(Role parent) { super(parent,"user", new Param(optionsToString(options),true), new Param("role",true), - new Param("id[,id]* (not required for setTo)",false)); + new Param("id[,id]*",false)); } @Override @@ -63,87 +63,62 @@ public class User extends Cmd { Future fp = null; - if (option != 2) { - String[] ids = args[idx++].split(","); - String verb=null,participle=null; - // You can request to be added or removed from role. - setQueryParamsOn(client); + String[] ids = args[idx++].split(","); + String verb=null,participle=null; + // You can request to be added or removed from role. + setQueryParamsOn(client); - for (String id: ids) { - id=fullID(id); - urr.setUser(id); - switch(option) { - case 0: - fp = client.create( - "/authz/userRole", - getDF(UserRoleRequest.class), - urr); - verb = "Added"; - participle = "] to Role [" ; - break; - case 1: - fp = client.delete( - "/authz/userRole/"+urr.getUser()+'/'+urr.getRole(), - Void.class); - verb = "Removed"; - participle = "] from Role [" ; - break; - case 3: - fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); - verb = "Extended"; - participle = "] in Role [" ; - break; + for (String id: ids) { + id=fullID(id); + urr.setUser(id); + switch(option) { + case 0: + fp = client.create( + "/authz/userRole", + getDF(UserRoleRequest.class), + urr); + verb = "Added"; + participle = "] to Role [" ; + break; + case 1: + fp = client.delete( + "/authz/userRole/"+urr.getUser()+'/'+urr.getRole(), + Void.class); + verb = "Removed"; + participle = "] from Role [" ; + break; + case 2: + fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); + verb = "Extended"; + participle = "] in Role [" ; + break; - default: // actually, should never get here... - throw new CadiException("Invalid action [" + action + ']'); - } - if (fp.get(AAFcli.timeout())) { - pw().print(verb); - pw().print(" User ["); - pw().print(urr.getUser()); - pw().print(participle); - pw().print(urr.getRole()); - pw().println(']'); - } else { - switch(fp.code()) { - case 202: - pw().print("User Role "); - pw().print(action); - pw().println(" is Accepted, but requires Approvals before actualizing"); - break; - case 404: - if (option==3) { - pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); - break; - } - default: - error(fp); - } - } + default: // actually, should never get here... + throw new CadiException("Invalid action [" + action + ']'); } - } else { - String allUsers = ""; - if (idx < args.length) - allUsers = args[idx++]; - StringBuilder finalUsers = new StringBuilder(); - for (String u : allUsers.split(",")) { - if (u != "") { - u=fullID(u); - if (finalUsers.length() > 0) finalUsers.append(","); - finalUsers.append(u); - } - } - - urr.setUser(finalUsers.toString()); - fp = client.update( - "/authz/userRole/role", - getDF(UserRoleRequest.class), - urr); if (fp.get(AAFcli.timeout())) { - pw().println("Set the Role to Users [" + allUsers + "]"); + pw().print(verb); + pw().print(" User ["); + pw().print(urr.getUser()); + pw().print(participle); + pw().print(urr.getRole()); + pw().println(']'); } else { - error(fp); - } + switch(fp.code()) { + case 202: + pw().print("User Role "); + pw().print(action); + pw().println(" is Accepted, but requires Approvals before actualizing"); + break; + case 404: + if (option==3) { + pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); + break; + } + default: + error(fp); + } + } } return fp==null?0:fp.code(); } @@ -152,18 +127,13 @@ public class User extends Cmd { @Override public void detailedHelp(int indent, StringBuilder sb) { - detailLine(sb,indent,"Add OR Delete a User to/from a Role OR"); - detailLine(sb,indent,"Set a User's Roles to the roles supplied"); + detailLine(sb,indent,"Add OR Delete a User to/from a Role OR extend Expiration"); detailLine(sb,indent+2,"role - Name of Role to create"); detailLine(sb,indent+2,"id(s) - ID or IDs to add to the Role"); sb.append('\n'); - detailLine(sb,indent+2,"Note: this is the same as \"user role add...\" except allows"); - detailLine(sb,indent+2,"assignment of role to multiple userss"); - detailLine(sb,indent+2,"WARNING: Users supplied with setTo will be the ONLY users attached to this role"); - detailLine(sb,indent+2,"If no users are supplied, the users attached to this role are reset."); api(sb,indent,HttpMethods.POST,"authz/userRole",UserRoleRequest.class,true); api(sb,indent,HttpMethods.DELETE,"authz/userRole//",Void.class,false); - api(sb,indent,HttpMethods.PUT,"authz/userRole/",UserRoleRequest.class,false); + api(sb,indent,HttpMethods.PUT,"authz/userRole/extend//",Void.class,false); } } diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/List.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/List.java index 6733989e..6d993284 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/List.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/List.java @@ -56,16 +56,26 @@ public class List extends BaseCmd { } return u1.getId().compareTo(u2.getId()); }); - String format = reportColHead("%-40s %-10s %-30s\n","User","Type","Expires"); + String format = reportColHead("%-48s %-5s %-11s %-16s\n","User","Type","Expires","Tag"); String date = "XXXX-XX-XX"; for (aaf.v2_0.Users.User user : sorted) { if (!aafcli.isTest()) { date = Chrono.dateOnlyStamp(user.getExpires()); } + String tag=null; + if(user.getType()<200) { + tag = user.getTag(); + } else { + tag = "\n\tfingerprint: " + user.getTag(); + } + if(tag==null) { + tag=""; + } pw().format(format, count? (Integer.valueOf(++idx) + ") " + user.getId()): user.getId(), org.onap.aaf.auth.cmd.ns.List.getType(user), - date); + date, + tag); } pw().println(); } diff --git a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java index 4bc99366..4787cabc 100644 --- a/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java +++ b/auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Role.java @@ -41,10 +41,10 @@ import aaf.v2_0.UserRoleRequest; * */ public class Role extends Cmd { - private static final String[] options = {"add", "del", "setTo","extend"}; + private static final String[] options = {"add", "del", "extend"}; public Role(User parent) { - super(parent, "role", new Param(optionsToString(options), true), new Param("user", true), new Param( - "role[,role]* (!REQ S)", false)); + super(parent, "role", new Param(optionsToString(options), true), new Param("user", true), + new Param("role[,role]*", false)); } @Override @@ -64,72 +64,57 @@ public class Role extends Cmd { Future fp = null; - if (option != 2) { - if (args.length < 5) { - throw new CadiException(build(new StringBuilder("Too few args: "), null).toString()); + if (args.length < 5) { + throw new CadiException(build(new StringBuilder("Too few args: "), null).toString()); + } + String[] roles = args[idx++].split(","); + for (String role : roles) { + String verb = null,participle=null; + urr.setRole(role); + // You can request to be added or removed from role. + setQueryParamsOn(client); + switch(option) { + case 0: + fp = client.create("/authz/userRole", getDF(UserRoleRequest.class), urr); + verb = "Added"; + participle = "] to User [" ; + break; + case 1: + fp = client.delete("/authz/userRole/" + urr.getUser() + '/' + urr.getRole(), Void.class); + verb = "Removed"; + participle = "] from User [" ; + break; + case 2: + fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); + verb = "Extended"; + participle = "] to User [" ; + break; + default: + throw new CadiException("Invalid action [" + key + ']'); } - String[] roles = args[idx++].split(","); - for (String role : roles) { - String verb = null,participle=null; - urr.setRole(role); - // You can request to be added or removed from role. - setQueryParamsOn(client); - switch(option) { - case 0: - fp = client.create("/authz/userRole", getDF(UserRoleRequest.class), urr); - verb = "Added"; - participle = "] to User [" ; - break; - case 1: - fp = client.delete("/authz/userRole/" + urr.getUser() + '/' + urr.getRole(), Void.class); - verb = "Removed"; - participle = "] from User [" ; - break; - case 3: - fp = client.update("/authz/userRole/extend/" + urr.getUser() + '/' + urr.getRole()); - verb = "Extended"; - participle = "] to User [" ; + if (fp.get(AAFcli.timeout())) { + pw().print(verb); + pw().print(" Role ["); + pw().print(urr.getRole()); + pw().print(participle); + pw().print(urr.getUser()); + pw().println(']'); + } else { + switch(fp.code()) { + case 202: + pw().print("UserRole "); + pw().print(option == 0 ? "Creation" : option==1?"Deletion":"Extension"); + pw().println(" Accepted, but requires Approvals before actualizing"); break; - default: - throw new CadiException("Invalid action [" + key + ']'); - } - if (fp.get(AAFcli.timeout())) { - pw().print(verb); - pw().print(" Role ["); - pw().print(urr.getRole()); - pw().print(participle); - pw().print(urr.getUser()); - pw().println(']'); - } else { - switch(fp.code()) { - case 202: - pw().print("UserRole "); - pw().print(option == 0 ? "Creation" : option==1?"Deletion":"Extension"); - pw().println(" Accepted, but requires Approvals before actualizing"); + case 404: + if (option==3) { + pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); break; - case 404: - if (option==3) { - pw().println("Failed with code 404: UserRole is not found, or you do not have permission to view"); - break; - } - default: - error(fp); } + default: + error(fp); } } - } else { - // option 2 is setTo command (an update call) - String allRoles = ""; - if (idx < args.length) - allRoles = args[idx++]; - - urr.setRole(allRoles); - fp = client.update("/authz/userRole/user", getDF(UserRoleRequest.class), urr); - if (fp.get(AAFcli.timeout())) { - pw().println("Set User's Roles to [" + allRoles + "]"); - } else { - error(fp); - } } return fp == null ? 0 : fp.code(); } @@ -138,18 +123,14 @@ public class Role extends Cmd { @Override public void detailedHelp(int indent, StringBuilder sb) { - detailLine(sb, indent, "Add OR Delete a User to/from a Role OR"); - detailLine(sb, indent, "Set a User's Roles to the roles supplied"); + detailLine(sb, indent, "Add or Delete a User to/from a Role OR extend Expiration"); detailLine(sb, indent + 2, "user - ID of User"); detailLine(sb, indent + 2, "role(s) - Role or Roles to which to add the User"); sb.append('\n'); - detailLine(sb, indent + 2, "Note: this is the same as \"role user add...\" except allows"); - detailLine(sb, indent + 2, "assignment of user to multiple roles"); - detailLine(sb, indent + 2, "WARNING: Roles supplied with setTo will be the ONLY roles attached to this user"); - detailLine(sb, indent + 2, "If no roles are supplied, user's roles are reset."); api(sb, indent, HttpMethods.POST, "authz/userRole", UserRoleRequest.class, true); api(sb, indent, HttpMethods.DELETE, "authz/userRole//", Void.class, false); - api(sb, indent, HttpMethods.PUT, "authz/userRole/", UserRoleRequest.class, false); + api(sb,indent,HttpMethods.PUT,"authz/userRole/extend//",Void.class,false); + } } diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java index 8e252c9e..ebd5f5f9 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/perm/JU_Grant.java @@ -92,36 +92,20 @@ public class JU_Grant { @Test public void testExecError() throws APIException, LocatorException, CadiException, URISyntaxException { - grant._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"}); + grant._exec(0, new String[] {"grant","type","instance","action","role"}); } @Test public void testExecSuccess1() throws APIException, LocatorException, CadiException, URISyntaxException { when(futureMock.code()).thenReturn(202); - grant._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"}); - grant._exec(1, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"}); + grant._exec(0, new String[] {"grant","type","instance","action","role"}); + } @Test public void testExecSuccess2() throws APIException, LocatorException, CadiException, URISyntaxException { when(futureMock.get(any(Integer.class))).thenReturn(true); - grant._exec(0, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"}); - } - - @Test - public void testExecSetToError() throws APIException, LocatorException, CadiException, URISyntaxException { - grant._exec(2, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"}); - } - - @Test - public void testExecSetToSuccess1() throws APIException, LocatorException, CadiException, URISyntaxException { - when(futureMock.get(any(Integer.class))).thenReturn(true); - grant._exec(2, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo"}); - } - - @Test - public void testExecSetToSuccess2() throws APIException, LocatorException, CadiException, URISyntaxException { - grant._exec(2, new String[] {"grant","ungrant","setTo","grant","ungrant","setTo","another"}); + grant._exec(0, new String[] {"grant","type","instance","action","role"}); } @Test diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java index 2bae29b5..0256c1bf 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java @@ -43,6 +43,8 @@ public interface AuthzTrans extends TransStore { public abstract AuthzTrans set(HttpServletRequest req); + public abstract HttpServletRequest hreq(); + public abstract String user(); public abstract void setUser(TaggedPrincipal p); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java index aa6b038b..ce947be9 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java @@ -34,16 +34,16 @@ import org.onap.aaf.misc.env.LogTarget; import org.onap.aaf.misc.env.impl.BasicTrans; public class AuthzTransImpl extends BasicTrans implements AuthzTrans { + private static final String N_A = "n/a"; + private static final String BLANK = ""; + private HttpServletRequest hreq; private TaggedPrincipal user; - private String ip,agent,meth,path; - private int port; private Lur lur; private Organization org; private int mask; private Date now; public AuthzTransImpl(AuthzEnv env) { super(env); - ip="n/a"; org=null; mask=0; } @@ -53,12 +53,8 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public AuthzTrans set(HttpServletRequest req) { + hreq = req; user = (TaggedPrincipal)req.getUserPrincipal(); - ip = req.getRemoteAddr(); - port = req.getRemotePort(); - agent = req.getHeader("User-Agent"); - meth = req.getMethod(); - path = req.getPathInfo(); for (REQD_TYPE rt : REQD_TYPE.values()) { requested(rt,req); @@ -72,6 +68,10 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { org=null; return this; } + @Override + public HttpServletRequest hreq() { + return hreq; + } @Override public void setUser(TaggedPrincipal p) { @@ -83,7 +83,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String user() { - return user==null?"n/a":user.getName(); + return user==null?N_A:user.getName(); } /** @@ -99,7 +99,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String ip() { - return ip; + return hreq==null?N_A:hreq.getRemoteAddr(); } /** @@ -107,7 +107,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public int port() { - return port; + return hreq==null?0:hreq.getRemotePort(); } @@ -116,7 +116,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String meth() { - return meth; + return hreq==null?"":hreq.getMethod(); } /* (non-Javadoc) @@ -124,7 +124,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String path() { - return path; + return hreq==null?"":hreq.getPathInfo(); } /** @@ -132,7 +132,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String agent() { - return agent; + return hreq==null?BLANK:hreq.getHeader("User-Agent"); } @Override diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java index 942a0e54..94a6aad5 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java @@ -135,6 +135,11 @@ public class NullTrans implements AuthzTrans { } @Override + public HttpServletRequest hreq() { + return null; + } + + @Override public String user() { return null; } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java index fa17f040..a269f24b 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java @@ -154,10 +154,10 @@ public class CachingFileAccess extends HttpCode2 && slash>=0 && key.substring(0,slash).equals(clear_command)) { resp.setHeader("Content-Type",typeMap.get("txt")); - if ("clear".equals(cmd)) { + if ("clear".equals(key.substring(slash+1))) { content.clear(); resp.setStatus(200/*HttpStatus.OK_200*/); } else { @@ -165,7 +165,7 @@ public class CachingFileAccess extends HttpCode0?key+'/'+cmd:key, null, checkInterval); + Content c = load(logT , web_path,key, null, checkInterval); if (c.attachmentOnly) { resp.setHeader("Content-disposition", "attachment"); } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java index c1bfd6ad..acca80ba 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java @@ -32,6 +32,9 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; import org.onap.aaf.misc.env.Trans; @@ -122,6 +125,15 @@ public abstract class RServlet implements Servlet { return "RServlet for Jetty"; } + /** + * Allow Service to instantiate certain actions after service starts up + * @throws LocatorException + * @throws CadiException + * @throws APIException + */ + public void postStartup(String hostname, int port) throws APIException { + } + @Override public void destroy() { } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java index 85b35ac7..d0fc1a3f 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java @@ -138,8 +138,9 @@ public abstract class TransFilter implements Filter { // Would need Cached Counter objects that are cleaned up on // use trans.checkpoint(resp.desc(),Env.ALWAYS); - if (resp.isFailedAttempt()) + if (resp.isFailedAttempt()) { trans.audit().log(resp.desc()); + } } } catch (Exception e) { trans.error().log(e); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java index b3e2883d..0e8cb78d 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java @@ -67,8 +67,9 @@ public abstract class AbsServiceStarter rserv) throws Exception; - public abstract void _propertyAdjustment(); + + protected abstract void _start(RServlet rserv) throws Exception; + protected abstract void _propertyAdjustment(); public ENV env() { return service.env; @@ -103,10 +104,8 @@ public abstract class AbsServiceStarter ... registrants) { if (do_register) { diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java index 182956cf..bcc071a2 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java @@ -216,7 +216,8 @@ public class JettyServiceStarter ex access().printf(Level.INIT,"'aaf_no_register' is set. %s will not be registered with Locator", service.app_name); } access().printf(Level.INIT, "Starting Jetty Service for %s, version %s, on %s://%s:%d", service.app_name,service.app_version,protocol,hostname,port); - //server.join(); + + rserv.postStartup(hostname, port); } catch (Exception e) { access().log(e,"Error registering " + service.app_name); String doExit = access().getProperty("cadi_exitOnFailure", "true"); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java index fd0691b6..894f571d 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java @@ -22,7 +22,6 @@ package org.onap.aaf.auth.server; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; import org.apache.log4j.Logger; import org.onap.aaf.cadi.Access.Level; @@ -31,12 +30,11 @@ import org.onap.aaf.cadi.PropAccess.LogIt; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.log4j.LogFileNamer; +import org.onap.aaf.misc.env.util.Chrono; public class Log4JLogIt implements LogIt { protected static final String AAF_LOG4J_PREFIX = "aaf_log4j_prefix"; - - // Sonar says cannot be static... it's ok. not too many PropAccesses created. - private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + // Log4j does it's own date. Can't apparently turn it off. private final String service; private final String audit; @@ -104,30 +102,30 @@ public class Log4JLogIt implements LogIt { public void push(Level level, Object... elements) { switch(level) { case AUDIT: - laudit.warn(PropAccess.buildMsg(audit, iso8601, level, elements)); + laudit.warn(PropAccess.buildMsg(audit, Chrono.utcFmt, level, elements)); break; case INIT: - linit.warn(PropAccess.buildMsg(init, iso8601, level, elements)); + linit.warn(PropAccess.buildMsg(init, Chrono.utcFmt, level, elements)); break; case ERROR: - lservice.error(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.error(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case WARN: - lservice.warn(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.warn(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case INFO: - lservice.info(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.info(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case DEBUG: - lservice.debug(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.debug(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case TRACE: - ltrace.trace(PropAccess.buildMsg(service, iso8601, level, elements)); + ltrace.trace(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case NONE: break; default: - lservice.info(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.info(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; } diff --git a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java index 26e49290..76041cef 100644 --- a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java +++ b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java @@ -59,8 +59,7 @@ public class AAF_FS extends AbsService { env.staticSlot(CachingFileAccess.CFA_WEB_PATH,"aaf_public_dir"); CachingFileAccess cfa = new CachingFileAccess(env); - route(env,GET,"/:key", cfa); - route(env,GET,"/:key/:cmd", cfa); + route(env,GET,"/:key*", cfa); final String aaf_locate_url = access.getProperty(Config.AAF_LOCATE_URL, null); if (aaf_locate_url == null) { access.printf(Level.WARN, "Redirection requires property %s",Config.AAF_LOCATE_URL); diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java index 121ee3f7..7859b7cc 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java @@ -76,11 +76,11 @@ public class CUI extends HttpCode { aafcli.gui(true); String cmdStr = cmd.toString(); - if (!cmdStr.contains("--help")) { - cmdStr = cmdStr.replaceAll("help", "--help"); + if (cmdStr.contains("--help")) { + cmdStr = cmdStr.replaceAll("--help", "help"); } - if (!cmdStr.contains("--version")) { - cmdStr = cmdStr.replaceAll("version", "--version"); + if (cmdStr.contains("--version")) { + cmdStr = cmdStr.replaceAll("--version", "version"); } try { aafcli.eval(cmdStr); diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java index 064a8a5c..359cb28b 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java @@ -94,7 +94,7 @@ import certman.v1_0.Artifacts; import certman.v1_0.CertInfo; public class AAF_GUI extends AbsService implements State{ - private static final String AAF_GUI_THEME = "aaf_gui_theme"; + public static final String AAF_GUI_THEME = "aaf_gui_theme"; public static final String AAF_GUI_COPYRIGHT = "aaf_gui_copyright"; public static final String HTTP_SERVLET_REQUEST = "HTTP_SERVLET_REQUEST"; public static final int TIMEOUT = 60000; @@ -113,15 +113,18 @@ public class AAF_GUI extends AbsService implements State implements State(env)); + CachingFileAccess cfa = new CachingFileAccess(env); + //route(env,GET,"/"+env.get(sThemeWebPath)+"/:key*", cfa); + route(env,GET,"/theme/:key*", cfa); /////////////////////// aafCon = aafCon(); lur = aafCon.newLur(); diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/BreadCrumbs.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/BreadCrumbs.java index 4f1a7e82..621257b2 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/BreadCrumbs.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/BreadCrumbs.java @@ -37,7 +37,7 @@ import org.onap.aaf.misc.xgen.Mark; import org.onap.aaf.misc.xgen.html.HTMLGen; public class BreadCrumbs extends NamedCode { - private Page[] breadcrumbs; + Page[] breadcrumbs; public BreadCrumbs(Page ... pages) { super(false,"breadcrumbs"); diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Display.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Display.java index de1a8461..877974bd 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Display.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Display.java @@ -31,7 +31,6 @@ import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.rserv.HttpCode; import org.onap.aaf.auth.rserv.HttpMethods; import org.onap.aaf.misc.env.Slot; -import org.onap.aaf.misc.xgen.html.HTMLGen; public class Display { private final Page get; diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Page.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Page.java index 1e067c44..8924ba26 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Page.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Page.java @@ -27,21 +27,30 @@ import static org.onap.aaf.misc.xgen.html.HTMLGen.LI; import static org.onap.aaf.misc.xgen.html.HTMLGen.TITLE; import static org.onap.aaf.misc.xgen.html.HTMLGen.UL; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import org.onap.aaf.auth.common.Define; import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.auth.env.AuthzTrans; -import org.onap.aaf.auth.rserv.CachingFileAccess; +import org.onap.aaf.auth.gui.pages.Home; import org.onap.aaf.cadi.Permission; import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.client.Holder; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.principal.TaggedPrincipal; import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.Slot; import org.onap.aaf.misc.env.StaticSlot; import org.onap.aaf.misc.env.util.Split; @@ -71,11 +80,9 @@ public class Page extends HTMLCacheGen { public static final String PERM_NS = Define.ROOT_NS(); public static enum BROWSER {iPhone,html5,ie,ieOld}; - - public static final int MAX_LINE=20; + public static final int MAX_LINE = 20; protected static final String[] NO_FIELDS = new String[0]; - private static final String BROWSER_TYPE = "BROWSER_TYPE"; private final String bcName, bcUrl; @@ -151,14 +158,90 @@ public class Page extends HTMLCacheGen { private final int backdots; protected AuthzEnv env; private StaticSlot sTheme; + private static Map> themes; + private static Map themeProps; public PageCode(AuthzEnv env, int backdots, final ContentCode[] content) { this.content = content; this.backdots = backdots; browserSlot = env.slot(BROWSER_TYPE); - sTheme = env.staticSlot(CachingFileAccess.CFA_WEB_PATH); + sTheme = env.staticSlot(AAF_GUI.AAF_GUI_THEME); this.env = env; } + + private static synchronized List getThemeFiles(Env env, String theme) { + if(themes==null) { + themes = new TreeMap<>(); + File themeD = new File("theme"); + if(themeD.exists() && themeD.isDirectory()) { + for (File t : themeD.listFiles()) { + if(t.isDirectory()) { + List la = new ArrayList<>(); + for(File f : t.listFiles()) { + if(f.isFile()) { + if(f.getName().endsWith(".props")) { + Properties props; + if(themeProps == null) { + themeProps = new TreeMap<>(); + props = null; + } else { + props = themeProps.get(theme); + } + if(props==null) { + props = new Properties(); + themeProps.put(theme, props); + } + + try { + FileInputStream fis = new FileInputStream(f); + try { + props.load(fis); + } finally { + fis.close(); + } + } catch (IOException e) { + env.error().log(e); + } + } else { + la.add(f.getName()); + } + } + } + themes.put(t.getName(),la); + } + } + } + } + return themes.get(theme); + } + + protected Imports getImports(Env env, Holder theme, String defaultTheme, int backdots, BROWSER browser) { + List ls = getThemeFiles(env,theme.get()); + Imports imp = new Imports(backdots); + if(ls==null) { + theme.set(defaultTheme); + } + String prefix = "theme/" + theme.get() + '/'; + for(String f : ls) { + if(f.endsWith(".js")) { + imp.js(prefix + f); + } else if(f.endsWith(".css")) { + if(f.endsWith("iPhone.css")) { + if(BROWSER.iPhone.equals(browser)) { + imp.css(prefix + f); + } + } else if (f.endsWith("Desktop.css")){ + if(!BROWSER.iPhone.equals(browser)) { + imp.css(prefix + f); + } + // Make Console specific to Console page + } else if (!"console.js".equals(f)) { + imp.css(prefix + f); + } + } + } + return imp; + } @Override public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { @@ -178,29 +261,34 @@ public class Page extends HTMLCacheGen { }); hgen.html(); final String title = env.getProperty(AAF_GUI_TITLE,"Authentication/Authorization Framework"); - final String theme = env.get(sTheme); + final String defaultTheme = env.get(sTheme); + final Holder hTheme = new Holder<>(defaultTheme); + Mark head = hgen.head(); hgen.leaf(TITLE).text(title).end(); - hgen.imports(new Imports(backdots).css(theme + "/aaf5.css") - .js(theme + "/comm.js") - .js(theme + "/console.js") - .js(theme + "/common.js")); cache.dynamic(hgen, new DynamicCode() { @Override public void code(AAF_GUI state, AuthzTrans trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { - switch(browser(trans,browserSlot)) { - case iPhone: - hgen.imports(new Imports(backdots).css(theme + "/aaf5iPhone.css")); - break; + BROWSER browser = browser(trans,browserSlot); + Cookie[] cookies = trans.hreq().getCookies(); + if(cookies!=null) { + for(Cookie c : cookies) { + if("aaf_theme".equals(c.getName())) { + hTheme.set(c.getValue()); + } + } + } + hgen.imports(getImports(env,hTheme,defaultTheme,backdots,browser)); + switch(browser) { case ie: case ieOld: hgen.js().text("document.createElement('header');") .text("document.createElement('nav');") .done(); - case html5: - hgen.imports(new Imports(backdots).css(theme + "/aaf5Desktop.css")); break; + default: } + } }); hgen.end(head); @@ -274,9 +362,62 @@ public class Page extends HTMLCacheGen { hgen.end(inner); - // Navigation - Using older Nav to work with decrepit IE versions + // Navigation - Using older Nav to work with decrepit IE versions Mark nav = hgen.divID("nav"); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(AAF_GUI state, AuthzTrans trans,Cache cache, HTMLGen xgen) throws APIException, IOException { + Properties props = themeProps.get(hTheme.get()); + if(props!=null && "TRUE".equalsIgnoreCase(props.getProperty("main_menu_in_nav"))) { + xgen.incr("h2").text("Navigation").end(); + Mark mark = new Mark(); + boolean selected = isSelected(trans.path(),Home.HREF); + //trans.path().endsWith("home"); + xgen.incr(mark,HTMLGen.UL) + .incr(HTMLGen.LI,selected?"class=selected":"") + .incr(HTMLGen.A, "href=home") + .text("Home") + .end(2); + boolean noSelection = !selected; + for(String[] mi : Home.MENU_ITEMS) { + //selected = trans.path().endsWith(mi[0]); + if(noSelection) { + selected = isSelected(trans.path(),mi[2]); + noSelection = !selected; + } else { + selected = false; + } + xgen.incr(HTMLGen.LI,selected?"class=selected":"") + .incr(HTMLGen.A, "href="+mi[0]) + .text(mi[1]) + .end(2); + } + xgen.end(mark); + } + } + + private boolean isSelected(String path, String item) { + if(item.equals(path)) { + return true; + } else { + for(ContentCode c : content) { + if(c instanceof BreadCrumbs) { + Page[] bc = ((BreadCrumbs)c).breadcrumbs; + if(bc!=null) { + for(int i = bc.length-1;i>0;--i) { + if(bc[i].url().equals(item)) { + return true; + } + } + return false; + } + } + } + } + return false; + } + }); hgen.incr("h2").text("Related Links").end(); hgen.incr(UL); String aaf_help = env.getProperty(AAF_URL_AAF_HELP,null); @@ -398,6 +539,5 @@ public class Page extends HTMLCacheGen { return values.length<1?null:values[0]; } - } diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/Home.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/Home.java index e0a73dca..e7a643ca 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/Home.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/Home.java @@ -37,10 +37,25 @@ import org.onap.aaf.misc.xgen.html.HTMLGen; public class Home extends Page { public static final String HREF = "/gui/home"; + /* + * Relative path, Menu Name, Full Path + */ + public static String[][] MENU_ITEMS = new String[][] { + {"myperms","My Permissions","/gui/myperms"}, + {"myroles","My Roles","/gui/myroles"}, + {"ns","My Namespaces","/gui/ns"}, + {"approve","My Approvals","/gui/approve"}, + {"myrequests","My Pending Requests","/gui/myrequests"}, + // Enable later + // {"onboard","Onboarding"}, + {"passwd","Password Management","/gui/passwd"}, + {"cui","Command Prompt","/gui/cui"}, + {"api","AAF API","/gui/api"} + }; public Home(final AAF_GUI gui) throws APIException, IOException { super(gui.env,"Home",HREF, NO_FIELDS, new NamedCode(false,"content") { @Override - public void code(final Cache cache, final HTMLGen xgen) throws APIException, IOException { + public void code(final Cache cache, final HTMLGen htmlGen) throws APIException, IOException { // // TEMP // JSGen jsg = xgen.js(); // jsg.function("httpPost","sURL","sParam") @@ -53,25 +68,14 @@ public class Home extends Page { // .text(text) // jsg.done(); // TEMP - final Mark pages = xgen.divID("Pages"); - xgen.leaf(H3).text("Choose from the following:").end() - .leaf(A,"href=myperms").text("My Permissions").end() - .leaf(A,"href=myroles").text("My Roles").end() - // TODO: uncomment when on cassandra 2.1.2 for MyNamespace GUI page - .leaf(A,"href=ns").text("My Namespaces").end() - .leaf(A,"href=approve").text("My Approvals").end() - .leaf(A, "href=myrequests").text("My Pending Requests").end() - // Enable later -// .leaf(A, "href=onboard").text("Onboarding").end() - // Password Change. If logged in as CSP/GSO, go to their page - .leaf(A,"href=passwd").text("Password Management").end() - .leaf(A,"href=cui").text("Command Prompt").end() - .leaf(A,"href=api").text("AAF API").end() - ; - - xgen.end(pages); + final Mark pages = htmlGen.divID("Pages"); + htmlGen.leaf(H3).text("Choose from the following:").end(); + for(String[] mi : MENU_ITEMS) { + htmlGen.leaf(A,"href="+mi[0]).text(mi[1]).end(); + } + htmlGen.end(pages); } }); } - + } diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/WebCommand.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/WebCommand.java index 6ad95e51..d0e834a5 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/WebCommand.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/WebCommand.java @@ -28,7 +28,9 @@ import org.onap.aaf.auth.gui.AAF_GUI; import org.onap.aaf.auth.gui.BreadCrumbs; import org.onap.aaf.auth.gui.NamedCode; import org.onap.aaf.auth.gui.Page; +import org.onap.aaf.auth.rserv.CachingFileAccess; import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.StaticSlot; import org.onap.aaf.misc.xgen.Cache; import org.onap.aaf.misc.xgen.DynamicCode; import org.onap.aaf.misc.xgen.Mark; @@ -41,6 +43,8 @@ public class WebCommand extends Page { super(gui.env, "Web Command Client",HREF, NO_FIELDS, new BreadCrumbs(breadcrumbs), new NamedCode(true, "content") { + StaticSlot sThemeWebPath = gui.env.staticSlot(CachingFileAccess.CFA_WEB_PATH); + StaticSlot sTheme = gui.env.staticSlot(AAF_GUI.AAF_GUI_THEME); @Override public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { hgen.leaf("p","id=help_msg") @@ -56,31 +60,33 @@ public class WebCommand extends Page { hgen.end(); //console_area hgen.divID("options_link", "class=closed"); - hgen.img("src=../../"+gui.theme + "/options_down.png", "onclick=handleDivHiding('options',this);", - "id=options_img", "alt=Options", "title=Options") - .end(); //options_link - - hgen.divID("options"); cache.dynamic(hgen, new DynamicCode() { @Override public void code(AAF_GUI state, AuthzTrans trans, Cache cache, HTMLGen xgen) throws APIException, IOException { + String image_root = "src=../../"+state.env.get(sThemeWebPath).toString() + '/' + state.env.get(sTheme) + "/images/icons"; + hgen.img(image_root + "/options_down.png", "onclick=handleDivHiding('options',this);", + "id=options_img", "alt=Options", "title=Options") + .end(); //options_link + + hgen.divID("options"); + switch(browser(trans,trans.env().slot(getBrowserType()))) { case ie: case ieOld: // IE doesn't support file save break; default: - xgen.img("src=../../"+gui.theme+"/AAFdownload.png", "onclick=saveToFile();", + xgen.img(image_root+"/AAF_download.png", "onclick=saveToFile();", "alt=Save log to file", "title=Save log to file"); } -// xgen.img("src=../../"+gui.theme+"/AAFemail.png", "onclick=emailLog();", +// xgen.img("src=../../"+gui.theme+"/AAF_email.png", "onclick=emailLog();", // "alt=Email log to me", "title=Email log to me"); - xgen.img("src=../../"+gui.theme+"/AAF_font_size.png", "onclick=handleDivHiding('text_slider',this);", + xgen.img(image_root+"/AAF_font_size.png", "onclick=handleDivHiding('text_slider',this);", "id=fontsize_img", "alt=Change text size", "title=Change text size"); - xgen.img("src=../../"+gui.theme+"/AAF_details.png", "onclick=selectOption(this,0);", + xgen.img(image_root+"/AAF_details.png", "onclick=selectOption(this,0);", "id=details_img", "alt=Turn on/off details mode", "title=Turn on/off details mode"); - xgen.img("src=../../"+gui.theme+"/AAF_maximize.png", "onclick=maximizeConsole(this);", + xgen.img(image_root+"/AAF_maximize.png", "onclick=maximizeConsole(this);", "id=maximize_img", "alt=Maximize Console Window", "title=Maximize Console Window"); } }); diff --git a/auth/auth-gui/theme/onap/images/AAF_details.png b/auth/auth-gui/theme/onap/images/AAF_details.png new file mode 100644 index 00000000..5c187459 Binary files /dev/null and b/auth/auth-gui/theme/onap/images/AAF_details.png differ diff --git a/auth/auth-gui/theme/onap/images/AAF_font_size.png b/auth/auth-gui/theme/onap/images/AAF_font_size.png new file mode 100644 index 00000000..466cbfbc Binary files /dev/null and b/auth/auth-gui/theme/onap/images/AAF_font_size.png differ diff --git a/auth/auth-gui/theme/onap/images/AAF_maximize.png b/auth/auth-gui/theme/onap/images/AAF_maximize.png new file mode 100644 index 00000000..706603bb Binary files /dev/null and b/auth/auth-gui/theme/onap/images/AAF_maximize.png differ diff --git a/auth/auth-gui/theme/onap/images/AAFdownload.png b/auth/auth-gui/theme/onap/images/AAFdownload.png new file mode 100644 index 00000000..cebd9522 Binary files /dev/null and b/auth/auth-gui/theme/onap/images/AAFdownload.png differ diff --git a/auth/auth-gui/theme/onap/images/AAFemail.png b/auth/auth-gui/theme/onap/images/AAFemail.png new file mode 100644 index 00000000..6d487769 Binary files /dev/null and b/auth/auth-gui/theme/onap/images/AAFemail.png differ diff --git a/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray.png b/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray.png new file mode 100644 index 00000000..abbf4b1a Binary files /dev/null and b/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray.png differ diff --git a/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray_stripe.png b/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray_stripe.png new file mode 100644 index 00000000..fb9b37a2 Binary files /dev/null and b/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray_stripe.png differ diff --git a/auth/auth-gui/theme/onap/images/LF_Collab_header_gray.png b/auth/auth-gui/theme/onap/images/LF_Collab_header_gray.png new file mode 100644 index 00000000..43781fad Binary files /dev/null and b/auth/auth-gui/theme/onap/images/LF_Collab_header_gray.png differ diff --git a/auth/auth-gui/theme/onap/images/ONAP_LOGO.png b/auth/auth-gui/theme/onap/images/ONAP_LOGO.png new file mode 100644 index 00000000..55e37188 Binary files /dev/null and b/auth/auth-gui/theme/onap/images/ONAP_LOGO.png differ diff --git a/auth/auth-gui/theme/onap/images/logo_onap.png b/auth/auth-gui/theme/onap/images/logo_onap.png new file mode 100644 index 00000000..458e320c Binary files /dev/null and b/auth/auth-gui/theme/onap/images/logo_onap.png differ diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java index 0d50f5d2..aca71363 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java @@ -74,7 +74,7 @@ public class Mapper_1_1 implements Mapper { - private static final String DOT_OAUTH = ".oauth"; public Map cacheUser; public AAFAuthn aafAuthn; public AAFLurPerm aafLurPerm; @@ -103,7 +102,8 @@ public class AAF_OAuth extends AbsService { // Start Background Processing // Question question = - question = new Question(trans, cluster, CassAccess.KEYSPACE, true); + question = new Question(trans, cluster, CassAccess.KEYSPACE); + question.startTimers(env); // Have AAFLocator object Create DirectLocators for Location needs AbsAAFLocator.setCreator(new DirectLocatorCreator(env, question.locateDAO)); diff --git a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/service/OAuthService.java b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/service/OAuthService.java index e3aed80c..1e4b6cbb 100644 --- a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/service/OAuthService.java +++ b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/service/OAuthService.java @@ -76,7 +76,7 @@ public class OAuthService { @SuppressWarnings("unchecked") public OAuthService(final Access access, final AuthzTrans trans, final Question q) throws APIException, IOException { permLoader = JSONPermLoaderFactory.direct(q); - tokenDAO = new OAuthTokenDAO(trans, q.historyDAO); + tokenDAO = new OAuthTokenDAO(trans, q.historyDAO()); daos =(DAO[]) new DAO[] { tokenDAO }; diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java index 90d4744a..6a63907d 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java @@ -25,6 +25,7 @@ import javax.servlet.Filter; import org.onap.aaf.auth.cache.Cache; import org.onap.aaf.auth.dao.CassAccess; +import org.onap.aaf.auth.dao.cass.CacheInfoDAO; import org.onap.aaf.auth.dao.hl.Question; import org.onap.aaf.auth.direct.DirectAAFLur; import org.onap.aaf.auth.direct.DirectAAFUserPass; @@ -96,8 +97,10 @@ public class AAF_Service extends AbsService { // Need Question for Security purposes (direct User/Authz Query in Filter) // Start Background Processing - question = new Question(trans, cluster, CassAccess.KEYSPACE, true); - DirectCertIdentity.set(question.certDAO); + question = new Question(trans, cluster, CassAccess.KEYSPACE); + question.startTimers(env); + + DirectCertIdentity.set(question.certDAO()); // Have AAFLocator object Create DirectLocators for Location needs AbsAAFLocator.setCreator(new DirectLocatorCreator(env, question.locateDAO)); @@ -190,10 +193,20 @@ public class AAF_Service extends AbsService { new DirectRegistrar(access,question.locateDAO, actualPort) }; } + + @Override + public void postStartup(final String hostname, final int port) throws APIException { + try { + CacheInfoDAO.startUpdate(env, aafCon().hman(), aafCon().securityInfo().defSS,hostname,port); + } catch (CadiException | LocatorException e) { + throw new APIException(e); + } + } @Override public void destroy() { Cache.stopTimer(); + CacheInfoDAO.stopUpdate(); if (cluster!=null) { cluster.close(); } diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzCassServiceImpl.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzCassServiceImpl.java index 81a9d5ec..751825c1 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzCassServiceImpl.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzCassServiceImpl.java @@ -168,6 +168,7 @@ public class AuthzCassServiceImpl > rlnsd = ques.nsDAO.read(trans, ns); + Result> rlnsd = ques.nsDAO().read(trans, ns); if (rlnsd.notOKorIsEmpty()) { return Result.err(rlnsd); } @@ -318,7 +319,8 @@ public class AuthzCassServiceImpl > rsd = ques.nsDAO.dao().readNsByAttrib(trans, key); + Result> rsd = ques.nsDAO().dao().readNsByAttrib(trans, key); if (rsd.notOK()) { return Result.err(rsd); } @@ -382,7 +384,7 @@ public class AuthzCassServiceImpl > rlnsd = ques.nsDAO.read(trans, ns); + Result> rlnsd = ques.nsDAO().read(trans, ns); if (rlnsd.notOKorIsEmpty()) { return Result.err(rlnsd); } @@ -401,8 +403,8 @@ public class AuthzCassServiceImpl > rlnsd = ques.nsDAO.read(trans, ns); + Result> rlnsd = ques.nsDAO().read(trans, ns); if (rlnsd.notOKorIsEmpty()) { return Result.err(rlnsd); } @@ -451,7 +453,8 @@ public class AuthzCassServiceImpl > rlnd = ques.nsDAO.read(trans, ns); + Result> rlnd = ques.nsDAO().read(trans, ns); if (rlnd.isOK()) { if (rlnd.isEmpty()) { return Result.err(Status.ERR_NotFound, "No data found for %s",ns); @@ -563,7 +565,7 @@ public class AuthzCassServiceImpl > loadNamepace(AuthzTrans trans, String user, String endsWith, boolean full) { - Result> urd = ques.userRoleDAO.readByUser(trans, user); + Result> urd = ques.userRoleDAO().readByUser(trans, user); if (urd.notOKorIsEmpty()) { return Result.err(urd); } @@ -679,7 +681,7 @@ public class AuthzCassServiceImpl lm = new HashSet<>(); - Result> rlnd = ques.nsDAO.dao().getChildren(trans, parent); + Result> rlnd = ques.nsDAO().dao().getChildren(trans, parent); if (rlnd.isOK()) { if (rlnd.isEmpty()) { return Result.err(Status.ERR_NotFound, "No data found for %s",parent); @@ -727,7 +729,7 @@ public class AuthzCassServiceImpl > rlnd = ques.nsDAO.read(trans, namespace.name); + Result> rlnd = ques.nsDAO().read(trans, namespace.name); if (rlnd.notOKorIsEmpty()) { return Result.err(Status.ERR_NotFound, "Namespace [%s] does not exist",namespace.name); @@ -737,7 +739,7 @@ public class AuthzCassServiceImpl rdr = ques.nsDAO.dao().addDescription(trans, namespace.name, namespace.description); + Result rdr = ques.nsDAO().dao().addDescription(trans, namespace.name, namespace.description); if (rdr.isOK()) { return Result.ok(); } else { @@ -797,6 +799,12 @@ public class AuthzCassServiceImpl createPerm(final AuthzTrans trans,REQUEST rreq) { final Result newPd = mapper.perm(trans, rreq); + // Does Perm Type exist as a Namespace? + if(newPd.value.type.isEmpty() || ques.nsDAO().read(trans, newPd.value.fullType()).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Permission Type exists as a Namespace"); + } + final ServiceValidator v = new ServiceValidator(); if (v.perm(newPd).err()) { return Result.err(Status.ERR_BadData,v.errs()); @@ -822,7 +830,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, newPd.value.ns); + Result> nsr = ques.nsDAO().read(trans, newPd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1138,7 +1146,7 @@ public class AuthzCassServiceImpl > rlpd = ques.permDAO.readNS(trans, ns); + Result> rlpd = ques.permDAO().readNS(trans, ns); if (rlpd.notOK()) { return Result.err(rlpd); } @@ -1176,7 +1184,7 @@ public class AuthzCassServiceImpl nss = ques.deriveNsSplit(trans, origType); - Result> origRlpd = ques.permDAO.read(trans, nss.value.ns, nss.value.name, origInstance, origAction); + Result> origRlpd = ques.permDAO().read(trans, nss.value.ns, nss.value.name, origInstance, origAction); if (origRlpd.notOKorIsEmpty()) { return Result.err(Status.ERR_PermissionNotFound, @@ -1235,7 +1243,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, pd.value.ns); + Result> nsr = ques.nsDAO().read(trans, pd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } - Result rdr = ques.permDAO.addDescription(trans, perm.ns, perm.type, perm.instance, + Result rdr = ques.permDAO().addDescription(trans, perm.ns, perm.type, perm.instance, perm.action, perm.description); if (rdr.isOK()) { return Result.ok(); @@ -1287,7 +1295,7 @@ public class AuthzCassServiceImpl > rcurr = ques.permDAO.read(trans, + Result> rcurr = ques.permDAO().read(trans, updt.value.ns, updt.value.type, updt.value.instance, @@ -1321,7 +1329,7 @@ public class AuthzCassServiceImpl key = RoleDAO.Data.decode(trans, ques, role); if (key.isOKhasData()) { - Result> rrd = ques.roleDAO.read(trans, key.value); + Result> rrd = ques.roleDAO().read(trans, key.value); if (rrd.isOKhasData()) { for (RoleDAO.Data r : rrd.value) { rv = func.addPermToRole(trans, r, curr, false); @@ -1341,7 +1349,7 @@ public class AuthzCassServiceImpl key = RoleDAO.Data.decode(trans, ques, role); if (key.isOKhasData()) { - Result> rdd = ques.roleDAO.read(trans, key.value); + Result> rdd = ques.roleDAO().read(trans, key.value); if (rdd.isOKhasData()) { for (RoleDAO.Data r : rdd.value) { rv = func.delPermFromRole(trans, r, curr, true); @@ -1380,7 +1388,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, perm.ns); + Result> nsr = ques.nsDAO().read(trans, perm.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1483,12 +1491,17 @@ public class AuthzCassServiceImpl createRole(final AuthzTrans trans, REQUEST from) { final Result rd = mapper.role(trans, from); + // Does Perm Type exist as a Namespace? + if(rd.value.name.isEmpty() || ques.nsDAO().read(trans, rd.value.fullName()).isOKhasData()) { + return Result.err(Status.ERR_ConflictAlreadyExists, + "Role exists as a Namespace"); + } final ServiceValidator v = new ServiceValidator(); if (v.role(rd).err()) { return Result.err(Status.ERR_BadData,v.errs()); } final RoleDAO.Data role = rd.value; - if (ques.roleDAO.read(trans, role.ns, role.name).isOKhasData()) { + if (ques.roleDAO().read(trans, role.ns, role.name).isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, "Role [" + role.fullName() + "] already exists"); } @@ -1512,7 +1525,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, rd.value.ns); + Result> nsr = ques.nsDAO().read(trans, rd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1529,7 +1542,7 @@ public class AuthzCassServiceImpl rdr = ques.roleDAO.create(trans, role); + Result rdr = ques.roleDAO().create(trans, role); if (rdr.isOK()) { return Result.ok(); } else { @@ -1608,10 +1621,10 @@ public class AuthzCassServiceImpl > rlrd; - Result> rlurd = ques.userRoleDAO.readByUser(trans, user); + Result> rlurd = ques.userRoleDAO().readByUser(trans, user); if (rlurd.isOKhasData()) { for (UserRoleDAO.Data urd : rlurd.value ) { - rlrd = ques.roleDAO.read(trans, urd.ns,urd.rname); + rlrd = ques.roleDAO().read(trans, urd.ns,urd.rname); // Note: Mapper will restrict what can be viewed // if user is the same as that which is looked up, no filtering is required if (rlrd.isOKhasData()) { @@ -1658,7 +1671,7 @@ public class AuthzCassServiceImpl > rlrd = ques.roleDAO.readNS(trans, ns); + Result> rlrd = ques.roleDAO().readNS(trans, ns); if (rlrd.isOK()) { if (!rlrd.isEmpty()) { // Note: Mapper doesn't need to restrict what can be viewed, because we did it already. @@ -1700,7 +1713,7 @@ public class AuthzCassServiceImpl > rlrd = ques.roleDAO.readName(trans, name); + Result> rlrd = ques.roleDAO().readName(trans, name); if (rlrd.isOK()) { if (!rlrd.isEmpty()) { // Note: Mapper will restrict what can be viewed @@ -1757,13 +1770,13 @@ public class AuthzCassServiceImpl > pdlr = ques.permDAO.read(trans, pdd); + Result> pdlr = ques.permDAO().read(trans, pdd); if (pdlr.isOK())for (PermDAO.Data pd : pdlr.value) { Result> rlrd; for (String r : pd.roles) { Result rs = RoleDAO.Data.decodeToArray(trans, ques, r); if (rs.isOK()) { - rlrd = ques.roleDAO.read(trans, rs.value[0],rs.value[1]); + rlrd = ques.roleDAO().read(trans, rs.value[0],rs.value[1]); // Note: Mapper will restrict what can be viewed if (rlrd.isOKhasData()) { mapper.roles(trans,rlrd.value,roles,true); @@ -1799,7 +1812,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, rd.value.ns); + Result> nsr = ques.nsDAO().read(trans, rd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } - Result rdr = ques.roleDAO.addDescription(trans, role.ns, role.name, role.description); + Result rdr = ques.roleDAO().addDescription(trans, role.ns, role.name, role.description); if (rdr.isOK()) { return Result.ok(); } else { @@ -1861,13 +1874,13 @@ public class AuthzCassServiceImpl > rlrd = ques.roleDAO.read(trans, rrd.value.ns, rrd.value.name); + Result> rlrd = ques.roleDAO().read(trans, rrd.value.ns, rrd.value.name); if (rlrd.notOKorIsEmpty()) { return Result.err(Status.ERR_RoleNotFound, "Role [%s] does not exist", rrd.value.fullName()); } // Check Status of Data in DB (does it exist) - Result> rlpd = ques.permDAO.read(trans, rpd.value.ns, + Result> rlpd = ques.permDAO().read(trans, rpd.value.ns, rpd.value.type, rpd.value.instance, rpd.value.action); PermDAO.Data createPerm = null; // if not null, create first if (rlpd.notOKorIsEmpty()) { // Permission doesn't exist @@ -1908,7 +1921,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, rpd.value.ns); + Result> nsr = ques.nsDAO().read(trans, rpd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1980,7 +1993,7 @@ public class AuthzCassServiceImpl delPermFromRole(final AuthzTrans trans, PermDAO.Data pdd, RoleDAO.Data rdd, REQUEST rreq) { - Result> rlpd = ques.permDAO.read(trans, pdd.ns, pdd.type, + Result> rlpd = ques.permDAO().read(trans, pdd.ns, pdd.type, pdd.instance, pdd.action); if (rlpd.notOKorIsEmpty()) { @@ -2007,7 +2020,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, pdd.ns); + Result> nsr = ques.nsDAO().read(trans, pdd.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2070,12 +2083,12 @@ public class AuthzCassServiceImpl > rrd = ques.roleDAO.read(trans, rrns.value.parent, rrns.value.name); + final Result> rrd = ques.roleDAO().read(trans, rrns.value.parent, rrns.value.name); if (rrd.notOKorIsEmpty()) { return Result.err(rrd); } - final Result> rpd = ques.permDAO.read(trans, rpns.value.parent, rpns.value.name, instance, action); + final Result> rpd = ques.permDAO().read(trans, rpns.value.parent, rpns.value.name, instance, action); if (rpd.notOKorIsEmpty()) { return Result.err(rpd); } @@ -2131,7 +2144,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, rd.value.ns); + Result> nsr = ques.nsDAO().read(trans, rd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2299,7 +2312,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, rcred.value.ns); + Result> nsr = ques.nsDAO().read(trans, rcred.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(Status.ERR_NsNotFound,"Cannot provision %s on non-existent Namespace %s",mechID.id(),rcred.value.ns); } @@ -2309,7 +2322,7 @@ public class AuthzCassServiceImpl > rlcd = ques.credDAO.readID(trans, rcred.value.id); + Result> rlcd = ques.credDAO().readID(trans, rcred.value.id); if (rlcd.isOKhasData()) { if (!org.canHaveMultipleCreds(rcred.value.id)) { return Result.err(Status.ERR_ConflictAlreadyExists, "Credential exists"); @@ -2335,7 +2348,7 @@ public class AuthzCassServiceImpl udr = ques.credDAO.create(trans, rcred.value); + Resultudr = ques.credDAO().create(trans, rcred.value); if (udr.isOK()) { return Result.ok(); } @@ -2442,7 +2455,7 @@ public class AuthzCassServiceImpl > rlcd = ques.credDAO.readNS(trans, ns); + Result> rlcd = ques.credDAO().readNS(trans, ns); if (rlcd.isOK()) { if (!rlcd.isEmpty()) { @@ -2489,7 +2502,7 @@ public class AuthzCassServiceImpl > rlcd = ques.credDAO.readID(trans, id); + Result> rlcd = ques.credDAO().readID(trans, id); if (rlcd.isOK()) { if (!rlcd.isEmpty()) { @@ -2519,7 +2532,7 @@ public class AuthzCassServiceImpl > rlcd = ques.certDAO.readID(trans, id); + Result> rlcd = ques.certDAO().readID(trans, id); if (rlcd.isOK()) { if (!rlcd.isEmpty()) { @@ -2560,7 +2573,7 @@ public class AuthzCassServiceImpl > rlcd = ques.credDAO.readID(trans, rcred.value.id); + Result> rlcd = ques.credDAO().readID(trans, rcred.value.id); if (rlcd.notOKorIsEmpty()) { return Result.err(Status.ERR_UserNotFound, "Credential does not exist"); } @@ -2592,7 +2605,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, rcred.value.ns); + Result> nsr = ques.nsDAO().read(trans, rcred.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2634,9 +2647,9 @@ public class AuthzCassServiceImpl > rlcd = ques.credDAO.readID(trans, cred.value.id); + Result> rlcd = ques.credDAO().readID(trans, cred.value.id); if (rlcd.notOKorIsEmpty()) { return Result.err(Status.ERR_UserNotFound, "Credential does not exist"); } @@ -2735,7 +2748,7 @@ public class AuthzCassServiceImpl > rlcd = ques.credDAO.readID(trans, cred.value.id); + Result> rlcd = ques.credDAO().readID(trans, cred.value.id); if (rlcd.notOKorIsEmpty()) { // Empty Creds should have no user_roles. - Result> rlurd = ques.userRoleDAO.readByUser(trans, cred.value.id); + Result> rlurd = ques.userRoleDAO().readByUser(trans, cred.value.id); if (rlurd.isOK()) { for (UserRoleDAO.Data data : rlurd.value) { - ques.userRoleDAO.delete(trans, data, false); + ques.userRoleDAO().delete(trans, data, false); } } return Result.err(Status.ERR_UserNotFound, "Credential does not exist"); @@ -2859,7 +2872,7 @@ public class AuthzCassServiceImpl > nsr = ques.nsDAO.read(trans, cred.value.ns); + Result> nsr = ques.nsDAO().read(trans, cred.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2880,20 +2893,20 @@ public class AuthzCassServiceImpl = rlcd.value.size()) { return Result.err(Status.ERR_BadData,"Invalid Choice [" + entry + "] chosen for Delete [%s] is saved for future processing",cred.value.id); } - udr = ques.credDAO.delete(trans, rlcd.value.get(entry),false); + udr = ques.credDAO().delete(trans, rlcd.value.get(entry),false); } else { for (CredDAO.Data curr : rlcd.value) { - udr = ques.credDAO.delete(trans, curr, false); + udr = ques.credDAO().delete(trans, curr, false); if (udr.notOK()) { return Result.err(udr); } } } if (isLastCred) { - Result> rlurd = ques.userRoleDAO.readByUser(trans, cred.value.id); + Result> rlurd = ques.userRoleDAO().readByUser(trans, cred.value.id); if (rlurd.isOK()) { for (UserRoleDAO.Data data : rlurd.value) { - ques.userRoleDAO.delete(trans, data, false); + ques.userRoleDAO().delete(trans, data, false); } } } @@ -3094,7 +3107,7 @@ public class AuthzCassServiceImpl userSet = new HashSet<>(); - Result> rlurd = ques.userRoleDAO.readByRole(trans, role); + Result> rlurd = ques.userRoleDAO().readByRole(trans, role); if (rlurd.isOK()) { for (UserRoleDAO.Data data : rlurd.value) { userSet.add(data); @@ -3127,7 +3140,7 @@ public class AuthzCassServiceImpl > rlurd = ques.userRoleDAO.readByUser(trans, user); + Result> rlurd = ques.userRoleDAO().readByUser(trans, user); if (rlurd.notOK()) { return Result.err(rlurd); } @@ -3188,172 +3201,9 @@ public class AuthzCassServiceImpl resetRolesForUser(AuthzTrans trans, REQUEST rreq) { - Result rurdd = mapper.userRole(trans, rreq); - final ServiceValidator v = new ServiceValidator(); - if (rurdd.notOKorIsEmpty()) { - return Result.err(rurdd); - } - if (v.user(trans.org(), rurdd.value.user).err()) { - return Result.err(Status.ERR_BadData,v.errs()); - } - - Set currRoles = new HashSet<>(); - Result> rlurd = ques.userRoleDAO.readByUser(trans, rurdd.value.user); - if (rlurd.isOK()) { - for (UserRoleDAO.Data data : rlurd.value) { - currRoles.add(data.role); - } - } - - Result rv = null; - String[] roles; - if (rurdd.value.role==null) { - roles = new String[0]; - } else { - roles = rurdd.value.role.split(","); - } - - for (String role : roles) { - if (v.role(role).err()) { - return Result.err(Status.ERR_BadData,v.errs()); - } - Result rrdd = RoleDAO.Data.decode(trans, ques, role); - if (rrdd.notOK()) { - return Result.err(rrdd); - } - - rurdd.value.role(rrdd.value); - - Result nsd = ques.mayUser(trans, trans.user(), rrdd.value,Access.write); - if (nsd.notOK()) { - return Result.err(nsd); - } - Result nsr = ques.deriveNs(trans, role); - if (nsr.notOKorIsEmpty()) { - return Result.err(nsr); - } - - if (currRoles.contains(role)) { - currRoles.remove(role); - } else { - rv = func.addUserRole(trans, rurdd.value); - if (rv.notOK()) { - return rv; - } - } - } - - for (String role : currRoles) { - rurdd.value.role(trans,ques,role); - rv = ques.userRoleDAO.delete(trans, rurdd.value, false); - if (rv.notOK()) { - trans.info().log(rurdd.value.user,"/",rurdd.value.role, "expected to be deleted, but does not exist"); - // return rv; // if it doesn't exist, don't error out - } - - } - - return Result.ok(); - - } - - @ApiDoc( - method = PUT, - path = "/authz/userRole/role", - params = {}, - expectedCode = 200, - errorCodes = {403,404,406}, - text = { "Set a Role's users to the users specified in the UserRoleRequest object.", - "WARNING: Users supplied will be the ONLY users attached to this role", - "If no users are supplied, role's users are reset." - } - ) - @Override - public Result resetUsersForRole(AuthzTrans trans, REQUEST rreq) { - Result rurdd = mapper.userRole(trans, rreq); - if (rurdd.notOKorIsEmpty()) { - return Result.err(rurdd); - } - final ServiceValidator v = new ServiceValidator(); - if (v.user_role(rurdd.value).err()) { - return Result.err(Status.ERR_BadData,v.errs()); - } - - RoleDAO.Data rd = RoleDAO.Data.decode(rurdd.value); - - Result nsd = ques.mayUser(trans, trans.user(), rd, Access.write); - if (nsd.notOK()) { - return Result.err(nsd); - } - - Result nsr = ques.deriveNs(trans, rurdd.value.role); - if (nsr.notOKorIsEmpty()) { - return Result.err(nsr); - } - - Set currUsers = new HashSet<>(); - Result> rlurd = ques.userRoleDAO.readByRole(trans, rurdd.value.role); - if (rlurd.isOK()) { - for (UserRoleDAO.Data data : rlurd.value) { - currUsers.add(data.user); - } - } - - // found when connected remotely to DEVL, can't replicate locally - // inconsistent errors with cmd: role user setTo [nothing] - // deleteUserRole --> read --> get --> cacheIdx(?) - // sometimes returns idx for last added user instead of user passed in - // cache bug? - - - Result rv = null; - String[] users = {}; - if (rurdd.value.user != null) { - users = rurdd.value.user.split(","); - } - - for (String user : users) { - if (v.user(trans.org(), user).err()) { - return Result.err(Status.ERR_BadData,v.errs()); - } - rurdd.value.user = user; - - if (currUsers.contains(user)) { - currUsers.remove(user); - } else { - rv = func.addUserRole(trans, rurdd.value); - if (rv.notOK()) { - return rv; - } - } - } - - for (String user : currUsers) { - rurdd.value.user = user; - rv = ques.userRoleDAO.delete(trans, rurdd.value, false); - if (rv.notOK()) { - trans.info().log(rurdd.value, "expected to be deleted, but not exists"); - return rv; - } - } - - return Result.ok(); - } + - @ApiDoc( + @ApiDoc( method = GET, path = "/authz/userRole/extend/:user/:role", params = { "user|string|true", @@ -3386,7 +3236,7 @@ public class AuthzCassServiceImpl > rr = ques.userRoleDAO.read(trans, user,role); + Result> rr = ques.userRoleDAO().read(trans, user,role); if (rr.notOK()) { return Result.err(rr); } @@ -3461,7 +3311,7 @@ public class AuthzCassServiceImpl > rulr; - if ((rulr=ques.userRoleDAO.read(trans, usr, role)).notOKorIsEmpty()) { + if ((rulr=ques.userRoleDAO().read(trans, usr, role)).notOKorIsEmpty()) { return Result.err(Status.ERR_UserRoleNotFound, "User [ "+usr+" ] is not " + "Assigned to the Role [ " + role + " ]"); } @@ -3485,7 +3335,7 @@ public class AuthzCassServiceImpl userSet = new HashSet<>(); - Result> rlurd = ques.userRoleDAO.readUserInRole(trans, user, role); + Result> rlurd = ques.userRoleDAO().readUserInRole(trans, user, role); if (rlurd.isOK()) { for (UserRoleDAO.Data data : rlurd.value) { userSet.add(data); @@ -3573,7 +3423,7 @@ public class AuthzCassServiceImpl userSet = new HashSet<>(); - Result> rlurd = ques.userRoleDAO.readByRole(trans, role); + Result> rlurd = ques.userRoleDAO().readByRole(trans, role); if (rlurd.isOK()) { for (UserRoleDAO.Data data : rlurd.value) { if (contactOnly) { //scrub data @@ -3626,7 +3476,7 @@ public class AuthzCassServiceImpl > nsd = ques.nsDAO.read(trans, nss.value.ns); + Result> nsd = ques.nsDAO().read(trans, nss.value.ns); if (nsd.notOK()) { return Result.err(nsd); } @@ -3640,7 +3490,7 @@ public class AuthzCassServiceImpl userSet = new HashSet<>(); if (!nss.isEmpty()) { - Result> rlp = ques.permDAO.readByType(trans, nss.value.ns, nss.value.name); + Result> rlp = ques.permDAO().readByType(trans, nss.value.ns, nss.value.name); if (rlp.isOKhasData()) { for (PermDAO.Data pd : rlp.value) { if ((allInstance || pd.instance.equals(instance)) && @@ -3649,7 +3499,7 @@ public class AuthzCassServiceImpl > rlurd = ques.userRoleDAO.readByRole(trans, role.replace('|', '.')); + Result> rlurd = ques.userRoleDAO().readByRole(trans, role.replace('|', '.')); if (rlurd.isOKhasData()) { for (UserRoleDAO.Data urd : rlurd.value) { userSet.add(urd); @@ -3703,7 +3553,7 @@ public class AuthzCassServiceImpl > resp = ques.historyDAO.readByUser(trans, user, yyyymm); + Result> resp = ques.historyDAO().readByUser(trans, user, yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3726,7 +3576,7 @@ public class AuthzCassServiceImpl > resp = ques.historyDAO.readBySubject(trans, role, "role", yyyymm); + Result> resp = ques.historyDAO().readBySubject(trans, role, "role", yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3751,7 +3601,7 @@ public class AuthzCassServiceImpl > resp = ques.historyDAO.readBySubject(trans, type, "perm", yyyymm); + Result> resp = ques.historyDAO().readBySubject(trans, type, "perm", yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3775,7 +3625,7 @@ public class AuthzCassServiceImpl > resp = ques.historyDAO.readBySubject(trans, ns, "ns", yyyymm); + Result> resp = ques.historyDAO().readBySubject(trans, ns, "ns", yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3805,7 +3655,7 @@ public class AuthzCassServiceImpl > ddr = ques.delegateDAO.read(trans, dd); + Result> ddr = ques.delegateDAO().read(trans, dd); if (access==Access.create && ddr.isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, "[%s] already delegates to [%s]", dd.user, ddr.value.get(0).delegate); } else if (access!=Access.create && ddr.notOKorIsEmpty()) { @@ -3845,14 +3695,14 @@ public class AuthzCassServiceImpl rdr = ques.delegateDAO.create(trans, dd); + Result rdr = ques.delegateDAO().create(trans, dd); if (rdr.isOK()) { return Result.ok(); } else { return Result.err(rdr); } } else { - return ques.delegateDAO.update(trans, dd); + return ques.delegateDAO().update(trans, dd); } default: return Result.err(fd); @@ -3868,7 +3718,7 @@ public class AuthzCassServiceImpl > ddl; - if ((ddl=ques.delegateDAO.read(trans, rd.value)).notOKorIsEmpty()) { + if ((ddl=ques.delegateDAO().read(trans, rd.value)).notOKorIsEmpty()) { return Result.err(Status.ERR_DelegateNotFound,"Cannot delete non-existent Delegate"); } final DelegateDAO.Data dd = ddl.value.get(0); @@ -3877,7 +3727,7 @@ public class AuthzCassServiceImpl > ddl; - if ((ddl=ques.delegateDAO.read(trans, dd)).notOKorIsEmpty()) { + if ((ddl=ques.delegateDAO().read(trans, dd)).notOKorIsEmpty()) { return Result.err(Status.ERR_DelegateNotFound,"Cannot delete non-existent Delegate"); } dd = ddl.value.get(0); @@ -3898,7 +3748,7 @@ public class AuthzCassServiceImpl > dbDelgs = ques.delegateDAO.read(trans, user); + Result> dbDelgs = ques.delegateDAO().read(trans, user); try { if (dbDelgs.isOKhasData()) { return mapper.delegate(dbDelgs.value); @@ -3946,7 +3796,7 @@ public class AuthzCassServiceImpl > dbDelgs = ques.delegateDAO.readByDelegate(trans, delegate); + Result> dbDelgs = ques.delegateDAO().readByDelegate(trans, delegate); try { if (dbDelgs.isOKhasData()) { return mapper.delegate(dbDelgs.value); @@ -3979,16 +3829,16 @@ public class AuthzCassServiceImpl > apprByTicket=null; for (ApprovalDAO.Data updt : rlad.value) { if (updt.ticket!=null) { - curr = ques.approvalDAO.readByTicket(trans, updt.ticket); + curr = ques.approvalDAO().readByTicket(trans, updt.ticket); if (curr.isOKhasData()) { final List add = curr.value; // Store a Pre-Lookup apprByTicket = (trans1, noop) -> add; } } else if (updt.id!=null) { - curr = ques.approvalDAO.read(trans, updt); + curr = ques.approvalDAO().read(trans, updt); } else if (updt.approver!=null) { - curr = ques.approvalDAO.readByApprover(trans, updt.approver); + curr = ques.approvalDAO().readByApprover(trans, updt.approver); } else { return Result.err(Status.ERR_BadData,"Approvals need ID, Ticket or Approval data to update"); } @@ -4024,7 +3874,7 @@ public class AuthzCassServiceImpl rfdd = ques.futureDAO.readPrimKey(trans, cd.ticket); + Result rfdd = ques.futureDAO().readPrimKey(trans, cd.ticket); if (rfdd.isOK()) { fdd = rfdd.value; // null is ok } else { @@ -4067,7 +3917,7 @@ public class AuthzCassServiceImpl > rapd = ques.approvalDAO.readByUser(trans, user); + Result> rapd = ques.approvalDAO().readByUser(trans, user); if (rapd.isOK()) { return mapper.approvals(rapd.value); } else { @@ -4131,7 +3981,7 @@ public class AuthzCassServiceImpl > rapd = ques.approvalDAO.readByTicket(trans, uuid); + Result> rapd = ques.approvalDAO().readByTicket(trans, uuid); if (rapd.isOK()) { return mapper.approvals(rapd.value); } else { @@ -4148,19 +3998,19 @@ public class AuthzCassServiceImpl listRapds = new ArrayList<>(); - Result> myRapd = ques.approvalDAO.readByApprover(trans, approver); + Result> myRapd = ques.approvalDAO().readByApprover(trans, approver); if (myRapd.notOK()) { return Result.err(myRapd); } listRapds.addAll(myRapd.value); - Result> delegatedFor = ques.delegateDAO.readByDelegate(trans, approver); + Result> delegatedFor = ques.delegateDAO().readByDelegate(trans, approver); if (delegatedFor.isOK()) { for (DelegateDAO.Data dd : delegatedFor.value) { if (dd.expires.after(new Date())) { String delegator = dd.user; - Result> rapd = ques.approvalDAO.readByApprover(trans, delegator); + Result> rapd = ques.approvalDAO().readByApprover(trans, delegator); if (rapd.isOK()) { for (ApprovalDAO.Data d : rapd.value) { if (!d.user.equals(trans.user())) { @@ -4210,7 +4060,7 @@ public class AuthzCassServiceImpl getUserRolesByUser(AuthzTrans trans, String user); - /** - * - * @param trans - * @param from - * @return - */ - public Result resetRolesForUser(AuthzTrans trans, REQUEST from); - - /** - * - * @param trans - * @param from - * @return + /* + * Note: Removed "resetRolesForUsers" because it was too dangerous, and + * removed "resetUsersForRoles" because it was being misused. */ - public Result resetUsersForRole(AuthzTrans trans, REQUEST from); /** * diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_Creds.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_Creds.java index 7a028c91..c8bae9f0 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_Creds.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_Creds.java @@ -112,7 +112,6 @@ public class API_Creds { decoded.substring(0,colon), CredVal.Type.PASSWORD , decoded.substring(colon+1).getBytes(),trans)) { - resp.setStatus(HttpStatus.OK_200); } else { // DME2 at this version crashes without some sort of response diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_UserRole.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_UserRole.java index 7937a184..a56b7c26 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_UserRole.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/api/API_UserRole.java @@ -104,21 +104,17 @@ public class API_UserRole { } }); - + /* TODO + * REMOVE dangerous resetUsersForRole and resetRolesForUser APIs + */ + final Result removeAPI = Result.err(Result.ERR_NotFound,"API Removed, use /authz/userRole instead."); /** * Update roles attached to user in path */ authzAPI.route(PUT,"/authz/userRole/user",API.USER_ROLE_REQ,new Code(facade,"Update Roles for a user", true) { @Override public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - Result r = context.resetRolesForUser(trans, resp, req); - switch(r.status) { - case OK: - resp.setStatus(HttpStatus.OK_200); - break; - default: - context.error(trans,resp,r); - } + context.error(trans,resp,removeAPI); } }); @@ -129,16 +125,14 @@ public class API_UserRole { authzAPI.route(PUT,"/authz/userRole/role",API.USER_ROLE_REQ,new Code(facade,"Update Users for a role", true) { @Override public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { - Result r = context.resetUsersForRole(trans, resp, req); - switch(r.status) { - case OK: - resp.setStatus(HttpStatus.OK_200); - break; - default: - context.error(trans,resp,r); - } + context.error(trans,resp,removeAPI); } }); + + /* + * END REMOVE Dangerous API + */ + /** * Extend Expiration Date (according to Organizational rules) diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacade.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacade.java index a08e958f..463de35f 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacade.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacade.java @@ -210,10 +210,10 @@ public interface AuthzFacade { public abstract Result getUserRolesByUser(AuthzTrans trans, HttpServletResponse resp, String user); public abstract Result deleteUserRole(AuthzTrans trans, HttpServletResponse resp, String user, String role); - - public abstract Result resetUsersForRole(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req); - public abstract Result resetRolesForUser(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req); + /* + * resetUsersForRoles and resetRolesForUsers is too dangerous and not helpful. + */ public abstract Result extendUserRoleExpiration(AuthzTrans trans, HttpServletResponse resp, String user, String role); diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacadeImpl.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacadeImpl.java index a2fb2209..02fa842f 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacadeImpl.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/facade/AuthzFacadeImpl.java @@ -66,9 +66,9 @@ import org.onap.aaf.auth.service.mapper.Mapper.API; import org.onap.aaf.cadi.aaf.client.Examples; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Data; +import org.onap.aaf.misc.env.Data.TYPE; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; -import org.onap.aaf.misc.env.Data.TYPE; import org.onap.aaf.misc.env.util.Chrono; import org.onap.aaf.misc.rosetta.Marshal; import org.onap.aaf.misc.rosetta.env.RosettaDF; @@ -1939,8 +1939,8 @@ public abstract class AuthzFacadeImpl resetUsersForRole(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req) { - TimeTaken tt = trans.start(SET_USERS_FOR_ROLE, Env.SUB|Env.ALWAYS); - try { - REQUEST rreq; - try { - RosettaData data = userRoleRequestDF.newData().load(req.getInputStream()); - if (Question.willSpecialLog(trans, trans.user())) { - Question.logEncryptTrace(trans,data.asString()); - } - rreq = data.asObject(); - } catch (APIException e) { - trans.error().log("Invalid Input",IN, SET_USERS_FOR_ROLE); - return Result.err(Status.ERR_BadData,"Invalid Input"); - } - - Result rp = service.resetUsersForRole(trans, rreq); - - switch(rp.status) { - case OK: - setContentType(resp,permsDF.getOutType()); - return Result.ok(); - default: - return Result.err(rp); - } - } catch (Exception e) { - trans.error().log(e,IN,SET_USERS_FOR_ROLE); - return Result.err(e); - } finally { - tt.done(); - } - - } - - @Override - public Result resetRolesForUser(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req) { - TimeTaken tt = trans.start(SET_ROLES_FOR_USER, Env.SUB|Env.ALWAYS); - try { - REQUEST rreq; - try { - RosettaData data = userRoleRequestDF.newData().load(req.getInputStream()); - if (Question.willSpecialLog(trans, trans.user())) { - Question.logEncryptTrace(trans,data.asString()); - } - - rreq = data.asObject(); - } catch (APIException e) { - trans.error().log("Invalid Input",IN, SET_ROLES_FOR_USER); - return Result.err(Status.ERR_BadData,"Invalid Input"); - } - - Result rp = service.resetRolesForUser(trans, rreq); - - switch(rp.status) { - case OK: - setContentType(resp,permsDF.getOutType()); - return Result.ok(); - default: - return Result.err(rp); - } - } catch (Exception e) { - trans.error().log(e,IN,SET_ROLES_FOR_USER); - return Result.err(e); - } finally { - tt.done(); - } - - } - /* (non-Javadoc) * @see com.att.authz.facade.AuthzFacade#extendUserRoleExpiration(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String) */ diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/mapper/Mapper_2_0.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/mapper/Mapper_2_0.java index 2d322390..72a24d21 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/mapper/Mapper_2_0.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/mapper/Mapper_2_0.java @@ -541,6 +541,7 @@ public class Mapper_2_0 implements Mapper { erroringTimer = null; } } else { + env.error().log(rv.toString()); // Account for different Registrations not being to same place if (erroringTimer==null) { erroringTimer = new Timer(REGISTRAR + " error re-check ",true); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java index ac715163..5221d8ea 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java @@ -98,15 +98,25 @@ public class RegistrationCreator { String protocol = access.getProperty(Config.AAF_LOCATOR_PROTOCOL + dot_le, null); if (protocol!=null) { locate.setProtocol(protocol); - String subprotocols = access.getProperty(Config.AAF_LOCATOR_SUBPROTOCOL + dot_le, null); - if(subprotocols!=null) { - List ls = locate.getSubprotocol(); - for (String s : Split.split(',', subprotocols)) { - ls.add(s); - } - } + List ls = locate.getSubprotocol(); + if(ls==null || ls.isEmpty()) { + String subprotocols = access.getProperty(Config.AAF_LOCATOR_SUBPROTOCOL + dot_le, null); + if(subprotocols==null) { + subprotocols = access.getProperty(Config.CADI_PROTOCOLS, null); + } + if(subprotocols!=null) { + for (String s : Split.split(',', subprotocols)) { + ls.add(s); + } + } else { + access.printf(Level.ERROR, "%s is required for Locator Registration of %s", + Config.AAF_LOCATOR_SUBPROTOCOL,Config.AAF_LOCATOR_PROTOCOL); + } + } + lme.add(locate); + } else { + access.printf(Level.ERROR, "%s is required for Locator Registration",Config.AAF_LOCATOR_PROTOCOL); } - lme.add(locate); } } } catch (NumberFormatException | UnknownHostException e) { diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java index c9b8b4ee..7c589ae3 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java @@ -319,7 +319,7 @@ public class AAFSSO { if(aaf_root_ns==null) { locateRoot=Defaults.AAF_ROOT; } else { - locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS.%" + aaf_root_ns; + locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS." + aaf_root_ns; } if(access.getProperty(Config.AAF_URL)==null) { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java index 2fe5f41c..d6b8d56d 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -149,6 +150,7 @@ public class PropAccess implements Access { name = props.getProperty(Config.CADI_LOGNAME, name); SecurityInfo.setHTTPProtocols(this); + } @@ -260,27 +262,34 @@ public class PropAccess implements Access { return buildMsg(name,iso8601,level,elements); } - public static StringBuilder buildMsg(final String name, final SimpleDateFormat sdf, Level level, Object[] elements) { - StringBuilder sb = new StringBuilder(sdf.format(new Date())); - sb.append(' '); - sb.append(level.name()); - sb.append(" ["); - sb.append(name); - + public static StringBuilder buildMsg(final String name, final DateFormat sdf, Level level, Object[] elements) { + final StringBuilder sb; int end = elements.length; - if (end<=0) { - sb.append("] "); - } else { - int idx = 0; - if(elements[idx]!=null && - elements[idx] instanceof Integer) { - sb.append('-'); - sb.append(elements[idx]); - ++idx; - } - sb.append("] "); - write(true,sb,elements); - } + if(sdf==null) { + sb = new StringBuilder(); + write(true,sb,elements); + } else { + sb = new StringBuilder( + sdf.format(new Date()) + ); + sb.append(' '); + sb.append(level.name()); + sb.append(" ["); + sb.append(name); + if (end<=0) { + sb.append("] "); + } else { + int idx = 0; + if(elements[idx]!=null && + elements[idx] instanceof Integer) { + sb.append('-'); + sb.append(elements[idx]); + ++idx; + } + sb.append("] "); + write(true,sb,elements); + } + } return sb; } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java index ff1f3955..8cb1045b 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java @@ -88,6 +88,9 @@ public class Config { public static final String CADI_LOGDIR = "cadi_log_dir"; public static final String CADI_ETCDIR = "cadi_etc_dir"; public static final String CADI_LOGNAME = "cadi_logname"; +// public static final String CADI_LOGFMT="cad_logging_format"; +// public static final String CADI_LOGFMT_UTC="UTC"; +// public static final String CADI_LOGFMT_ISO8601="ISO-8601"; public static final String CADI_KEYFILE = "cadi_keyfile"; public static final String CADI_KEYSTORE = "cadi_keystore"; public static final String CADI_KEYSTORE_PASSWORD = "cadi_keystore_password"; @@ -174,6 +177,11 @@ public class Config { public static final String AAF_LOCATOR_PUBLIC_PORT = "aaf_locator_public_port"; public static final String AAF_LOCATOR_PUBLIC_FQDN = "aaf_locator_public_fqdn"; public static final String AAF_LOCATOR_PUBLIC_NAME = "aaf_locator_public_name"; + + // AAF Service will write to the Audit Log if a past due AAF stored Password + // is being used within # of days specified. + public static final String AAF_CRED_WARN_DAYS="aaf_cred_warn_days"; + public static final String AAF_CRED_WARN_DAYS_DFT="7"; public static final String AAF_APPID = "aaf_id"; public static final String AAF_APPPASS = "aaf_password"; diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java b/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java index a1a81b9d..58c588f6 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java @@ -77,8 +77,8 @@ public abstract class TimeTaken { end = System.nanoTime(); } - - /** + + /** * For sizable contents, set the size. Implementations can simply write a no-op if they don't wish to * store the size. * diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java index 83a049c1..5ba74369 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java @@ -112,7 +112,6 @@ public abstract class AbsTrans implements TransStore { public final void checkpoint(String name, int additionalFlag) { TimeTaken tt = newTimeTaken(name,CHECKPOINT|additionalFlag); trail.add(tt); - tt.done(); } @Override @@ -130,8 +129,13 @@ public abstract class AbsTrans implements TransStore { // If first entry is sub, then it's actually the last "end" as well // otherwise, check end //long end = (first.flag&SUB)==SUB?first.end():trail.get(last).end(); - long end = trail.get(last).end(); + long end = 0L; + for(int i=last;end==0L && i>=0;--i) { + end= trail.get(i).end(); + } metric.total = (end - first.start) / 1000000f; + } else { + metric.total=0L; } if (sb==null) { @@ -165,6 +169,18 @@ public abstract class AbsTrans implements TransStore { for (int i=0;i implements TransStore { ++indent; } - // Add time values to Metric - float ms = tt.millis(); - for (int i=0;i(); js = new ArrayList<>(); this.backdots = backdots; -- cgit 1.2.3-korg