diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-05-29 04:58:50 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-05-29 07:34:28 -0500 |
commit | ff1417ff60baee231a28272f9a16ef2c9c8ea0a2 (patch) | |
tree | d9ca6c5f9661a3ffd6263d1380812e2430d9b230 /auth | |
parent | a47bd51641efcb84e19d68a6383f0947df826636 (diff) |
Post Init Service Starter
minor fixes
Remove JU generated garbage files
Issue-ID: AAF-835
Change-Id: I476291f1f1140f0640ed49452f8a5dabb28d9c30
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth')
72 files changed, 1220 insertions, 1813 deletions
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<T> { 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<TRANS extends Trans, DATA extends Cacheable> extends Cache<T Date dbStamp = info.get(trans, name,cacheIdx); // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax) - if (cached!=null && dbStamp.before(cached.timestamp)) { + if (cached!=null && dbStamp!=null && dbStamp.before(cached.timestamp)) { ld = (List<DATA>)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<AuthzTrans,CacheInfoDAO.Data> impl } } - public static<T extends Trans> void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter<HttpURLConnection> ss, String ip, int port) { + public static synchronized <T extends Trans> void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter<HttpURLConnection> 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<AuthzTrans,CredDAO.Data> { } } - private static class CredLoader extends Loader<Data> implements Streamer<Data>{ + public static class CredLoader extends Loader<Data> implements Streamer<Data>{ 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<AuthzTrans, HistoryDAO.Data> { public ByteBuffer reconstruct; } - private static class HistLoader extends Loader<Data> { + public static class HistLoader extends Loader<Data> { 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<RV> extends Result<RV> { * @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<NsSplit> 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<List<RoleDAO.Data>> rrdc = q.roleDAO.readChildren(trans, targetNs, targetName); + Result<List<RoleDAO.Data>> 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<List<UserRoleDAO.Data>> rurd = q.userRoleDAO.readByRole(trans, rdd.fullName()); + Result<List<UserRoleDAO.Data>> 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<List<PermDAO.Data>> rpdc = q.permDAO.readChildren(trans,targetNs, targetName); + Result<List<PermDAO.Data>> 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<List<NsDAO.Data>> 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<List<CredDAO.Data>> creds = q.credDAO.readNS(trans, ns); + Result<List<CredDAO.Data>> 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<List<UserRoleDAO.Data>> rlurd = q.userRoleDAO + Result<List<UserRoleDAO.Data>> 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<List<PermDAO.Data>> rpdc = q.permDAO.readNS(trans, ns); + Result<List<PermDAO.Data>> 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<List<RoleDAO.Data>> rrdc = q.roleDAO.readNS(trans, ns); + Result<List<RoleDAO.Data>> 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<List<String>> 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<List<UserRoleDAO.Data>> ruinr = q.userRoleDAO.readUserInRole(trans, trans.user(),ns+".owner"); + Result<List<UserRoleDAO.Data>> 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<List<CredDAO.Data>> cdr = q.credDAO.readID(trans, user); + Result<List<CredDAO.Data>> 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<List<UserRoleDAO.Data>> ruinr = q.userRoleDAO.readUserInRole(trans, trans.user(),ns+".owner"); + Result<List<UserRoleDAO.Data>> 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<List<RoleDAO.Data>> 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<PermDAO.Data> pdr = q.permDAO.create(trans, perm); + Result<PermDAO.Data> pdr = q.permDAO().create(trans, perm); if (pdr.isOK()) { return Result.ok(); } else { @@ -1011,7 +1025,7 @@ public class Function { } } // Does Perm exist? - Result<List<PermDAO.Data>> pdr = q.permDAO.read(trans, perm); + Result<List<PermDAO.Data>> 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<RoleDAO.Data> 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<Void> 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<List<UserRoleDAO.Data>> urdr = q.userRoleDAO.readByRole(trans,role.fullName()); + Result<List<UserRoleDAO.Data>> 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<List<RoleDAO.Data>> rdr = q.roleDAO.read(trans, role); + Result<List<RoleDAO.Data>> 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<List<UserRoleDAO.Data>> rlurd = q.userRoleDAO + Result<List<UserRoleDAO.Data>> rlurd = q.userRoleDAO() .readByUser(trans, trans.user()); if (rlurd.isOK()) { for (UserRoleDAO.Data ur : rlurd.value) { @@ -1161,13 +1175,13 @@ public class Function { } } - Result<List<PermDAO.Data>> rlpd = q.permDAO.read(trans, pd); + Result<List<PermDAO.Data>> rlpd = q.permDAO().read(trans, pd); if (rlpd.notOKorIsEmpty()) { return Result.err(Status.ERR_PermissionNotFound, "Permission must exist to add to Role"); } - Result<List<RoleDAO.Data>> rlrd = q.roleDAO.read(trans, role); // Already + Result<List<RoleDAO.Data>> rlrd = q.roleDAO().read(trans, role); // Already // Checked // for // can @@ -1187,7 +1201,7 @@ public class Function { } role.perms(true).add(pd.encode()); - Result<RoleDAO.Data> rdd = q.roleDAO.create(trans, role); + Result<RoleDAO.Data> 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<List<RoleDAO.Data>> rlr = q.roleDAO.read(trans, role); + Result<List<RoleDAO.Data>> rlr = q.roleDAO().read(trans, role); if (rlr.notOKorIsEmpty()) { // If Bad Data, clean out - Result<List<PermDAO.Data>> rlp = q.permDAO.read(trans, pd); + Result<List<PermDAO.Data>> 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<List<PermDAO.Data>> rlp = q.permDAO.read(trans, pd); + Result<List<PermDAO.Data>> rlp = q.permDAO().read(trans, pd); Result<Void> 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<UserRoleDAO.Data> udr = q.userRoleDAO.create(trans, urData); + Result<UserRoleDAO.Data> udr = q.userRoleDAO().create(trans, urData); if (udr.status == OK) { return Result.ok(); } @@ -1388,12 +1402,12 @@ public class Function { */ public Result<Void> 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<List<String>> getUsersByRole(AuthzTrans trans, String role, boolean includeExpired) { - Result<List<UserRoleDAO.Data>> rurdd = q.userRoleDAO.readByRole(trans,role); + Result<List<UserRoleDAO.Data>> 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<List<UserRoleDAO.Data>> r = q.userRoleDAO.read(trans, urdd); + Result<List<UserRoleDAO.Data>> 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<String> createFuture(AuthzTrans trans, FutureDAO.Data data, String id, String user, @@ -1458,7 +1472,7 @@ public class Function { List<Identity> approvers = op.equals(FUTURE_OP.A)?NO_ADDL_APPROVE:org.getApprovers(trans, user); List<Identity> owners = new ArrayList<>(); if (nsd != null) { - Result<List<UserRoleDAO.Data>> rrbr = q.userRoleDAO + Result<List<UserRoleDAO.Data>> 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<FutureDAO.Data> fr = q.futureDAO.create(trans, data, id); + Result<FutureDAO.Data> 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<UserRoleDAO.Data> urDBLookup = new Lookup<UserRoleDAO.Data>() { @Override public UserRoleDAO.Data get(AuthzTrans trans, Object ... keys) { - Result<List<UserRoleDAO.Data>> r = q.userRoleDAO.read(trans, keys); + Result<List<UserRoleDAO.Data>> 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<OP_STATUS> 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<ApprovalDAO.Data> r = q.approvalDAO.create(trans,ad); + Result<ApprovalDAO.Data> 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<List<UserRoleDAO.Data>> getUserRoles() { if (userRoles==null) { - userRoles = q.userRoleDAO.readByUser(trans,user); + userRoles = q.userRoleDAO().readByUser(trans,user); if (userRoles.isOKhasData()) { List<UserRoleDAO.Data> 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<List<RoleDAO.Data>> rlrd = q.roleDAO.read( + Result<List<RoleDAO.Data>> rlrd = q.roleDAO().read( trans, urdata.ns, urdata.rname); if (rlrd.isOK()) { lrdd.addAll(rlrd.value); @@ -155,7 +155,7 @@ class PermLookup { Result<String[]> ap = PermDAO.Data.decodeToArray(trans, q, perm); if (ap.isOK()) { - Result<List<PermDAO.Data>> rlpd = q.permDAO.read(perm,trans,ap.value); + Result<List<PermDAO.Data>> 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<close) { int daysLeft = days-(int)((close-cexp)/86400000); - trans.audit().printf("user=%s,ip=%s,expires=%s,days=%d,msg=\"Password expires in less than %d day%s\"", - cdd.id,trans.ip(),Chrono.dateOnlyStamp(cdd.expires),daysLeft, daysLeft,daysLeft==1?"":"s"); + trans.audit().printf("user=%s,ip=%s,expires=%s,days=%d,tag=%s,msg=\"Password expires in less than %d day%s\"", + cdd.id,trans.ip(),Chrono.dateOnlyStamp(cdd.expires),daysLeft, cdd.tag, + daysLeft,daysLeft==1?"":"s"); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java index 7cc8bd67..055e91ed 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java @@ -80,7 +80,9 @@ public class JU_Cached { cached.invalidate("test"); cached.invalidate("test1"); } - + +/* + * DO NOT ATTEMPT TO TEST Timer Threads in JUNIT!!!!! @SuppressWarnings("static-access") @Test public void testStopTimer(){ @@ -96,6 +98,7 @@ public class JU_Cached { cached.startRefresh(authzEnvMock, cidaoATMock); assertTrue(true); } +*/ // @Mock // Trans transMock; // @Mock diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java index fbd1b813..939cd27d 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java @@ -32,7 +32,6 @@ import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.junit.Before; @@ -66,8 +65,6 @@ import com.datastax.driver.core.Session; import com.datastax.driver.core.Statement; import com.datastax.driver.core.exceptions.DriverException; -import io.netty.util.concurrent.Future; - public class JU_CacheInfoDAO { @Mock @@ -252,6 +249,8 @@ public class JU_CacheInfoDAO { } +/* + * This has intermittent Null Pointers, JUnit only @Test public void testGet() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -276,6 +275,7 @@ public class JU_CacheInfoDAO { e.printStackTrace(); } } +*/ @Test public void testWasMOdified() { diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java index 8981b0a6..9eee56c4 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java @@ -23,17 +23,17 @@ package org.onap.aaf.auth.dao.cass; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.math.BigInteger; import java.nio.ByteBuffer; import java.util.List; @@ -44,8 +44,8 @@ import org.mockito.Mockito; import org.onap.aaf.auth.dao.AbsCassDAO; import org.onap.aaf.auth.dao.AbsCassDAO.CRUD; import org.onap.aaf.auth.dao.AbsCassDAO.PSInfo; -import org.onap.aaf.auth.dao.cass.ConfigDAO.Data; import org.onap.aaf.auth.dao.CassAccess; +import org.onap.aaf.auth.dao.cass.ConfigDAO.Data; import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; @@ -57,7 +57,6 @@ import org.onap.aaf.misc.env.LogTarget; import org.onap.aaf.misc.env.TimeTaken; import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; @@ -139,11 +138,13 @@ public class JU_ConfigDAOTest { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ConfigDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_ConfigDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {ConfigDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_ConfigDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ConfigDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -165,12 +166,6 @@ public class JU_ConfigDAOTest { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java index bfc370f4..3493b088 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java @@ -24,11 +24,10 @@ package org.onap.aaf.auth.dao.cass; import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -189,11 +188,13 @@ public class JU_LocateDAO { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {LocateDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_LocateDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {LocateDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_LocateDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {LocateDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -215,9 +216,6 @@ public class JU_LocateDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java index 2b0e101b..d5af0a63 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java @@ -25,11 +25,11 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -218,11 +218,13 @@ public class JU_NsDAO { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {NsDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_NsDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {NsDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_NsDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {NsDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -244,9 +246,6 @@ public class JU_NsDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } @Test diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java index c9f08a83..e8de65ad 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java @@ -23,11 +23,11 @@ package org.onap.aaf.auth.dao.cass; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -203,11 +203,13 @@ public class JU_OAuthTokenDAO { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {OAuthTokenDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_OAuthTokenDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {OAuthTokenDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_OAuthTokenDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {OAuthTokenDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -229,9 +231,6 @@ public class JU_OAuthTokenDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java index a26e179b..c92420da 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java @@ -24,33 +24,30 @@ package org.onap.aaf.auth.dao.cass; import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; -import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; +import org.onap.aaf.auth.dao.AbsCassDAO; import org.onap.aaf.auth.dao.AbsCassDAO.CRUD; import org.onap.aaf.auth.dao.AbsCassDAO.PSInfo; -import org.onap.aaf.auth.dao.cass.PermDAO.Data; -import org.onap.aaf.auth.dao.hl.Question; -import org.onap.aaf.auth.dao.AbsCassDAO; import org.onap.aaf.auth.dao.CassAccess; import org.onap.aaf.auth.dao.CassDAOImpl; +import org.onap.aaf.auth.dao.cass.PermDAO.Data; +import org.onap.aaf.auth.dao.hl.Question; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; import org.onap.aaf.cadi.config.Config; @@ -517,11 +514,13 @@ public class JU_PermDAO { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {PermDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_PermDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {PermDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_PermDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {PermDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -543,9 +542,6 @@ public class JU_PermDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java index 1f383469..16f05aa3 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java @@ -24,11 +24,10 @@ package org.onap.aaf.auth.dao.cass; import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -516,11 +515,13 @@ public class JU_RoleDAO { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {RoleDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_RoleDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {RoleDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_RoleDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {RoleDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -542,9 +543,6 @@ public class JU_RoleDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java index e01cd42e..8023fa9e 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java @@ -24,20 +24,17 @@ package org.onap.aaf.auth.dao.cass; import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; -import java.util.HashSet; import java.util.List; -import java.util.TreeSet; import org.junit.Before; import org.junit.Test; @@ -46,9 +43,7 @@ import org.mockito.Mockito; import org.onap.aaf.auth.dao.AbsCassDAO; import org.onap.aaf.auth.dao.AbsCassDAO.CRUD; import org.onap.aaf.auth.dao.AbsCassDAO.PSInfo; -import org.onap.aaf.auth.dao.CassAccess; import org.onap.aaf.auth.dao.CassDAOImpl; -import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data; import org.onap.aaf.auth.dao.hl.Question; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; @@ -289,11 +284,13 @@ public class JU_UserRoleDAO { innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_UserRoleDAOTest.java")); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {UserRoleDAO.Data.class, DataOutputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dos }); - DataInputStream dis = new DataInputStream(new FileInputStream("JU_UserRoleDAOTest.java")); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {UserRoleDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); @@ -315,9 +312,6 @@ public class JU_UserRoleDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java index 5dd33c7e..56cc2b0e 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java @@ -48,6 +48,8 @@ public class JU_CassExecutor { + private static final Object NO_PARAM = new Object[0]; + @Mock AuthzTransImpl trans; @@ -87,7 +89,7 @@ public class JU_CassExecutor { public void testInRole() { CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Result<NsSplit> retVal1 = new Result<NsSplit>(null,1,"",new String[0]); + Result<NsSplit> retVal1 = new Result<NsSplit>(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<Data> retVal1 = new Result<Data>(null,1,"",new String[0]); + Result<Data> retVal1 = new Result<Data>(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<Object>() { 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<Data> retVal1 = new Result<Data>(null,0,"",new String[0]); + Result<Data> retVal1 = new Result<Data>(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<String> owner = new ArrayList<String>(); 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<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result<Void> retVal = new Result<Void>(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<Void> retVal = new Result<Void>(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<Void> 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<String> owner = new ArrayList<String>(); @@ -157,13 +178,11 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result<Void> retVal = new Result<Void>(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Function funcObj = new Function(trans, ques); Result<Void> 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<String> owner = new ArrayList<String>(); @@ -192,9 +201,9 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<String> owner = new ArrayList<String>(); @@ -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<String> owner = new ArrayList<String>(); @@ -297,7 +286,7 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Result<Void> 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<NsDAO.Data>(data,0,"test",new String[0]); + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, null); - CachedNSDAO nsDaoObj = Mockito.mock(CachedNSDAO.class); - Result<Void> retVal = new Result<Void>(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<Void> retVal = new Result<Void>(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<String> owner = new ArrayList<String>(); @@ -506,14 +319,12 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(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<Void> retVal = new Result<Void>(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<Void> retVal = new Result<Void>(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<CredDAO.Data> 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<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",new String[0]); + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(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<Void> 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<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(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<Void> retVal = new Result<Void>(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<Void> retVal = new Result<Void>(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<CredDAO.Data> 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<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",new String[0]); - Result<List<CredDAO.Data>> retVal6 = new Result<List<CredDAO.Data>>(dataObj,1,"test",new String[0]); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",new String[0]); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",new String[0]); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",new String[0]); + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); + Result<List<CredDAO.Data>> retVal6 = new Result<List<CredDAO.Data>>(dataObj,1,"test",NO_PARAM); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(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<Void> 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<String> owner = new ArrayList<String>(); @@ -676,17 +471,12 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(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<Void> retVal = new Result<Void>(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<Void> retVal = new Result<Void>(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<CredDAO.Data> 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<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",new String[0]); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",new String[0]); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",new String[0]); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",new String[0]); + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(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<Void> 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<Void> retVal = new Result<Void>(null,1,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Function funcObj = new Function(trans, ques); Result<Void> 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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(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<Void> 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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(retVal5).when(cachedPermDAO).readNS(trans, "test"); - setQuestionCachedPermDao(ques, cachedPermDAO); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); - CachedUserRoleDAO cachedUserRoleDAO = Mockito.mock(CachedUserRoleDAO.class); List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; indData4.rname = "test"; dataObj4.add(indData4); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedUserRoleDAO).readByRole(trans, "test"); - setQuestionUserRoleDao(ques, cachedUserRoleDAO); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(trans, "test"); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); List<RoleDAO.Data> 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<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(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<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; indData5.type = "test"; dataObj5.add(indData5); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(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<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(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<RoleDAO.Data> 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<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(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<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(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<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); NsDAO.Data dataObj = new NsDAO.Data(); dataObj.type=1; dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal).when(nsDaoObj).read(Mockito.any(), Mockito.anyString()); - setQuestion(ques, nsDaoObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); List<CredDAO.Data> nsDataList = new ArrayList<CredDAO.Data>(); CredDAO.Data nsData = new CredDAO.Data(); nsData.id="test"; nsDataList.add(nsData); - Result<List<CredDAO.Data>> retVal21 = new Result<List<CredDAO.Data>>(nsDataList,0,"test",new String[0]); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); + Result<List<CredDAO.Data>> retVal21 = new Result<List<CredDAO.Data>>(nsDataList,0,"test",NO_PARAM); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; indData5.type = "test"; dataObj5.add(indData5); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(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<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(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<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; indData4.rname = "test"; dataObj4.add(indData4); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(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<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(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<RoleDAO.Data> 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<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(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<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(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<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.delOwner(trans, "test", "test"); assertTrue(result.status == 1); - retVal1 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + retVal1 = new Result<NsDAO.Data>(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<NsDAO.Data>(data,0,"test",new String[0]); + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); - retVal2 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + retVal2 = new Result<NsDAO.Data>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.delAdmin(trans, "test", "test"); assertTrue(result.status == 1); - retVal1 = new Result<NsDAO.Data>(data,1,"test",new String[0]); + retVal1 = new Result<NsDAO.Data>(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<NsDAO.Data>(data,0,"test",new String[0]); + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); - retVal2 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + retVal2 = new Result<NsDAO.Data>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(null,1,"test",new String[0]); + Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(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<List<PermDAO.Data>>(dataObj5,0,"test",new String[0]); + retVal1 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(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<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(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<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",new String[0]); + Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); invokeMovePerms(nsDataObj, sb, retVal1); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(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<List<RoleDAO.Data>>(dataObj5,0,"test",new String[0]); + retVal1 = new Result<List<RoleDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(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<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(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<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",new String[0]); + Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); invokeMoveRoles(nsDataObj, sb, retVal1); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); - Mockito.doReturn(retVal4).when(cachedRoleDAO).create(Mockito.any(), Mockito.any()); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createPerm(trans, perm, false); assertTrue(result.status == 1); - retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); + retVal2 = new Result<NsDAO.Data>(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<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",new String[0]); + Result<NsSplit> retValNs = new Result<NsSplit>(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<List<RoleDAO.Data>> retVal3 = Result.ok(new ArrayList<>()); + Mockito.doReturn(retVal3).when(roleDAO).read(Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Result<List<RoleDAO.Data>> 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<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal1).when(cachedPermDAO).read(trans, perm); + Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(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<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<PermDAO.Data>> retVal = new Result<List<PermDAO.Data>>(dataAl,1,"test",new String[0]); + Result<List<PermDAO.Data>> retVal = new Result<List<PermDAO.Data>>(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<Void> 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<NsDAO.Data>(null,0,"test",new String[0]); + retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - Result<List<PermDAO.Data>> retVal3 = new Result<List<PermDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedPermDAO).read(trans, perm); + Result<List<PermDAO.Data>> retVal3 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(permDAO).read(trans, perm); NsSplit nsObj = new NsSplit("test","test"); - Result<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",new String[0]); + Result<NsSplit> retValNs = new Result<NsSplit>(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<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,role, Access.write); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<Void> result = funcObj.deleteRole(trans, role, true, false); assertTrue(result.status == 1); - CachedRoleDAO cachedRoleDAO = Mockito.mock(CachedRoleDAO.class); - setQuestionCachedRoleDao(ques, cachedRoleDAO); - Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal1).when(cachedRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(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<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",new String[0]); + Result<NsSplit> retVal3 = new Result<NsSplit>(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<List<UserRoleDAO.Data>>(dataAlUser,0,"test",new String[0]); + retVal = new Result<List<UserRoleDAO.Data>>(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<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); PermDAO.Data rolePerm = new PermDAO.Data(); Set<String> 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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",new String[0]); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<NsDAO.Data> retVal3 = new Result<NsDAO.Data>(null,1,"test",new String[0]); + Result<NsDAO.Data> retVal3 = new Result<NsDAO.Data>(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<Void> result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - retVal2 = new Result<NsDAO.Data>(nsObj,1,"test",new String[0]); + retVal2 = new Result<NsDAO.Data>(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<NsDAO.Data>(nsObj,0,"test",new String[0]); + retVal2 = new Result<NsDAO.Data>(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<NsDAO.Data>(nsObj,0,"test1",new String[0]); + retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - Result<NsDAO.Data> retVal21 = new Result<NsDAO.Data>(nsObj1,0,"test1",new String[0]); + Result<NsDAO.Data> retVal21 = new Result<NsDAO.Data>(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<NsDAO.Data>(null,0,"test",new String[0]); + retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); - retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",new String[0]); + retVal2 = new Result<NsDAO.Data>(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<List<PermDAO.Data>> retValPerm= new Result<List<PermDAO.Data>>(dataAlPerm,0,"test1",new String[0]); - Mockito.doReturn(retValPerm).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Result<List<PermDAO.Data>> retValPerm= new Result<List<PermDAO.Data>>(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<NsDAO.Data>(null,0,"test",new String[0]); + retVal3 = new Result<NsDAO.Data>(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<NsDAO.Data>(null,1,"test",new String[0]); - Mockito.doReturn(retVal3).when(cachedRoleDAO).create(trans, role); + retVal3 = new Result<NsDAO.Data>(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<List<RoleDAO.Data>> retVal31 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retVal31).when(cachedRoleDAO).read(trans, role); + Result<List<RoleDAO.Data>> retVal31 = new Result<List<RoleDAO.Data>>(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<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); PermDAO.Data rolePerm = new PermDAO.Data(); Set<String> rolesSetUser = new HashSet<>(); @@ -1771,17 +1339,15 @@ public class JU_Function { role.perms = rolesSet; dataAl.add(role); - CachedUserRoleDAO userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); - Result<NsDAO.Data> retValFail = new Result<NsDAO.Data>(null,1,"test",new String[0]); - Result<NsDAO.Data> retValSuc = new Result<NsDAO.Data>(null,0,"test",new String[0]); + Result<NsDAO.Data> retValFail = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Result<NsDAO.Data> retValSuc = new Result<NsDAO.Data>(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<List<PermDAO.Data>> retValPermSuc = new Result<List<PermDAO.Data>>(dataAlPerm,0,"test",new String[0]); - Mockito.doReturn(retValPermSuc).when(cachedPermDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Result<List<PermDAO.Data>> retValPermSuc = new Result<List<PermDAO.Data>>(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<List<RoleDAO.Data>> retValRoleSuc = new Result<List<RoleDAO.Data>>(dataAl,0,"test",new String[0]); - Mockito.doReturn(retValRoleSuc).when(cachedRoleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Result<List<RoleDAO.Data>> retValRoleSuc = new Result<List<RoleDAO.Data>>(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<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",new String[0]); + Result<NsSplit> retVal3 = new Result<NsSplit>(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<NsSplit>(null,1,"test",new String[0]); + retVal3 = new Result<NsSplit>(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<UserRoleDAO.Data> 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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); - Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(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<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(null,1,"test",new String[0]); + + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(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<Void> result = funcObj.addUserRole(trans, urData); @@ -1906,7 +1452,7 @@ public class JU_Function { NsDAO.Data data = new NsDAO.Data(); data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",new String[0]); + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(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<UserRoleDAO.Data> 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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); - Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(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<UserRoleDAO.Data> 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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<List<String>> 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<UserRoleDAO.Data> 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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(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<Void> result = funcObj.delUserRole(trans, "test", "test", "test"); assertNull(result); - retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",new String[0]); + retVal = new Result<List<UserRoleDAO.Data>>(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<UserRoleDAO.Data> 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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",new String[0]); - Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(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<String> 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<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(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<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(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<ApprovalDAO.Data> retValApproval = new Result<ApprovalDAO.Data>(approvalData,0,"test",new String[0]); - Mockito.doReturn(retValApproval).when(approvalDaoObj).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); - setQuestionApprovalDao(ques, approvalDaoObj); + Result<ApprovalDAO.Data> retValApproval = new Result<ApprovalDAO.Data>(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<ApprovalDAO.Data>(null,1,"test",new String[0]); - Mockito.doReturn(retValApproval).when(approvalDaoObj).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); + retValApproval = new Result<ApprovalDAO.Data>(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<UserRoleDAO.Data> 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<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",new String[0]); - Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(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<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(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<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(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<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",new String[0]); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - setQuestionUserRoleDao(ques, userRoleDAO); // -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",new String[0]); +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(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<FutureDAO.Data>(futureData,1,"test",new String[0]); - Mockito.doReturn(retValFuture).when(futureDaoObj).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); + retValFuture = new Result<FutureDAO.Data>(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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); @@ -136,12 +145,12 @@ public class JU_PermLookup { @Test public void testGetUserRolesFirstIf() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); @@ -151,7 +160,7 @@ public class JU_PermLookup { @Test public void testGetUserRolesSecondIf() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); @@ -178,7 +187,7 @@ public class JU_PermLookup { @Test public void testGetRole() { - q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<List<RoleDAO.Data>> 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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<List<RoleDAO.Data>> 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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<List<RoleDAO.Data>> 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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<Set<String>> 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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); 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<Set<String>> 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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); Result<List<RoleDAO.Data>> 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<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); Result<List<RoleDAO.Data>> 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<BaseRequest,CertInfo,Artifacts,Error> { List<ArtiDAO.Data> 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<String> 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<RolePermRequest> 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/<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/<user>/<role>",Void.class,false); - api(sb,indent,HttpMethods.PUT,"authz/userRole/<role>",UserRoleRequest.class,false); + api(sb,indent,HttpMethods.PUT,"authz/userRole/extend/<user>/<role>",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<User> { } 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/<user>/<role>", Void.class, false); - api(sb, indent, HttpMethods.PUT, "authz/userRole/<user>", UserRoleRequest.class, false); + api(sb,indent,HttpMethods.PUT,"authz/userRole/extend/<user>/<role>",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<TRANS extends Trans> extends HttpCode<TRANS, Void @Override public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException { String key = pathParam(req, ":key"); - String cmd = pathParam(req,":cmd"); - if (key.equals(clear_command)) { + int slash = key.indexOf('/'); + if(key.length()>2 && 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<TRANS extends Trans> extends HttpCode<TRANS, Void } return; } - Content c = load(logT , web_path,cmd!=null && cmd.length()>0?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<TRANS extends Trans> 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<TRANS extends TransStore> 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<ENV extends RosettaEnv, TRANS extends Tr } } - public abstract void _start(RServlet<TRANS> rserv) throws Exception; - public abstract void _propertyAdjustment(); + + protected abstract void _start(RServlet<TRANS> rserv) throws Exception; + protected abstract void _propertyAdjustment(); public ENV env() { return service.env; @@ -103,10 +104,8 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr } catch (IOException e) { } } - } - @SafeVarargs public final synchronized void register(final Registrant<ENV> ... 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<ENV extends RosettaEnv, TRANS extends Trans> 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<AuthzEnv, AuthzTrans> { env.staticSlot(CachingFileAccess.CFA_WEB_PATH,"aaf_public_dir"); CachingFileAccess<AuthzTrans> cfa = new CachingFileAccess<AuthzTrans>(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<AuthzTrans, Void> { 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<AuthzEnv, AuthzTrans> implements State<Env>{ - 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<AuthzEnv, AuthzTrans> implements State<E public final Slot slot_httpServletRequest; protected final String deployedVersion; private StaticSlot sThemeWebPath; - public final String theme; + private StaticSlot sDefaultTheme; +// public final String theme; public AAF_GUI(final AuthzEnv env) throws Exception { super(env.access(), env); - theme = env.getProperty(AAF_GUI_THEME,"theme/onap"); + sDefaultTheme = env.staticSlot(AAF_GUI_THEME); + env.put(sDefaultTheme, env.getProperty(AAF_GUI_THEME,"onap")); + sThemeWebPath = env.staticSlot(CachingFileAccess.CFA_WEB_PATH); if(env.get(sThemeWebPath)==null) { - env.put(sThemeWebPath,theme); + env.put(sThemeWebPath,"theme"); } slot_httpServletRequest = env.slot(HTTP_SERVLET_REQUEST); @@ -203,7 +206,9 @@ public class AAF_GUI extends AbsService<AuthzEnv, AuthzTrans> implements State<E /////////////////////// // WebContent Handler /////////////////////// - route(env,GET,"/"+env.get(sThemeWebPath)+"/:key", new CachingFileAccess<AuthzTrans>(env)); + CachingFileAccess<AuthzTrans> cfa = new CachingFileAccess<AuthzTrans>(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<String,List<String>> themes; + private static Map<String,Properties> 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<String> 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<String> 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<String> theme, String defaultTheme, int backdots, BROWSER browser) { + List<String> 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<HTMLGen> 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<String> 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<HTMLGen,AAF_GUI,AuthzTrans>() { @Override public void code(AAF_GUI state, AuthzTrans trans, final Cache<HTMLGen> 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<HTMLGen,AAF_GUI,AuthzTrans>() { + @Override + public void code(AAF_GUI state, AuthzTrans trans,Cache<HTMLGen> 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<HTMLGen> cache, final HTMLGen xgen) throws APIException, IOException { + public void code(final Cache<HTMLGen> 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<HTMLGen> 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<HTMLGen,AAF_GUI,AuthzTrans>() { @Override public void code(AAF_GUI state, AuthzTrans trans, Cache<HTMLGen> 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 Binary files differnew file mode 100644 index 00000000..5c187459 --- /dev/null +++ b/auth/auth-gui/theme/onap/images/AAF_details.png diff --git a/auth/auth-gui/theme/onap/images/AAF_font_size.png b/auth/auth-gui/theme/onap/images/AAF_font_size.png Binary files differnew file mode 100644 index 00000000..466cbfbc --- /dev/null +++ b/auth/auth-gui/theme/onap/images/AAF_font_size.png diff --git a/auth/auth-gui/theme/onap/images/AAF_maximize.png b/auth/auth-gui/theme/onap/images/AAF_maximize.png Binary files differnew file mode 100644 index 00000000..706603bb --- /dev/null +++ b/auth/auth-gui/theme/onap/images/AAF_maximize.png diff --git a/auth/auth-gui/theme/onap/images/AAFdownload.png b/auth/auth-gui/theme/onap/images/AAFdownload.png Binary files differnew file mode 100644 index 00000000..cebd9522 --- /dev/null +++ b/auth/auth-gui/theme/onap/images/AAFdownload.png diff --git a/auth/auth-gui/theme/onap/images/AAFemail.png b/auth/auth-gui/theme/onap/images/AAFemail.png Binary files differnew file mode 100644 index 00000000..6d487769 --- /dev/null +++ b/auth/auth-gui/theme/onap/images/AAFemail.png 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 Binary files differnew file mode 100644 index 00000000..abbf4b1a --- /dev/null +++ b/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray.png 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 Binary files differnew file mode 100644 index 00000000..fb9b37a2 --- /dev/null +++ b/auth/auth-gui/theme/onap/images/LF_Collab_footer_gray_stripe.png 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 Binary files differnew file mode 100644 index 00000000..43781fad --- /dev/null +++ b/auth/auth-gui/theme/onap/images/LF_Collab_header_gray.png diff --git a/auth/auth-gui/theme/onap/images/ONAP_LOGO.png b/auth/auth-gui/theme/onap/images/ONAP_LOGO.png Binary files differnew file mode 100644 index 00000000..55e37188 --- /dev/null +++ b/auth/auth-gui/theme/onap/images/ONAP_LOGO.png diff --git a/auth/auth-gui/theme/onap/images/logo_onap.png b/auth/auth-gui/theme/onap/images/logo_onap.png Binary files differnew file mode 100644 index 00000000..458e320c --- /dev/null +++ b/auth/auth-gui/theme/onap/images/logo_onap.png 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<InRequest,Out,Endpoints,MgmtEndpoints, Error err = new Error(); err.setMessageId(msgID); // AT&T Restful Error Format requires numbers "%" placements - err.setText(Vars.convert(holder, text, var)); + err.setText(Vars.convert(holder, text, (Object[])var)); for (String s : var) { err.getVariables().add(s); } diff --git a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java index ef0c4da5..d5a6615f 100644 --- a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java +++ b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java @@ -66,7 +66,6 @@ import com.datastax.driver.core.Cluster; import aafoauth.v2_0.Introspect; public class AAF_OAuth extends AbsService<AuthzEnv,AuthzTrans> { - private static final String DOT_OAUTH = ".oauth"; public Map<String, Dated> cacheUser; public AAFAuthn<?> aafAuthn; public AAFLurPerm aafLurPerm; @@ -103,7 +102,8 @@ public class AAF_OAuth extends AbsService<AuthzEnv,AuthzTrans> { // 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<AuthzTrans, ?>[]) 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<AuthzEnv,AuthzTrans> { // 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<AuthzEnv,AuthzTrans> { 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(parentNs); } + // Note: Data validate occurs in func.createNS if (namespace.name.lastIndexOf('.')<0) { // Root Namespace... Function will check if allowed return func.createNS(trans, namespace, false); } @@ -299,7 +300,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } // Check if exists already - Result<List<Data>> rlnsd = ques.nsDAO.read(trans, ns); + Result<List<Data>> rlnsd = ques.nsDAO().read(trans, ns); if (rlnsd.notOKorIsEmpty()) { return Result.err(rlnsd); } @@ -318,7 +319,8 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE // Add Attrib nsd.attrib.put(key, value); - ques.nsDAO.dao().attribAdd(trans,ns,key,value); + ques.nsDAO().dao().attribAdd(trans,ns,key,value); + ques.nsDAO().invalidate(trans, nsd); return Result.ok(); } finally { tt.done(); @@ -349,7 +351,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_Denied,"%s may not read NS by Attrib '%s'",trans.user(),key); } - Result<Set<String>> rsd = ques.nsDAO.dao().readNsByAttrib(trans, key); + Result<Set<String>> rsd = ques.nsDAO().dao().readNsByAttrib(trans, key); if (rsd.notOK()) { return Result.err(rsd); } @@ -382,7 +384,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } // Check if exists already (NS must exist) - Result<List<Data>> rlnsd = ques.nsDAO.read(trans, ns); + Result<List<Data>> rlnsd = ques.nsDAO().read(trans, ns); if (rlnsd.notOKorIsEmpty()) { return Result.err(rlnsd); } @@ -401,8 +403,8 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE // Add Attrib nsd.attrib.put(key, value); - - return ques.nsDAO.update(trans,nsd); + ques.nsDAO().invalidate(trans, nsd); + return ques.nsDAO().update(trans,nsd); } finally { tt.done(); @@ -433,7 +435,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } // Check if exists already - Result<List<Data>> rlnsd = ques.nsDAO.read(trans, ns); + Result<List<Data>> rlnsd = ques.nsDAO().read(trans, ns); if (rlnsd.notOKorIsEmpty()) { return Result.err(rlnsd); } @@ -451,7 +453,8 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE // Add Attrib nsd.attrib.remove(key); - ques.nsDAO.dao().attribRemove(trans,ns,key); + ques.nsDAO().dao().attribRemove(trans,ns,key); + ques.nsDAO().invalidate(trans, nsd); return Result.ok(); } finally { tt.done(); @@ -465,8 +468,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE expectedCode = 200, errorCodes = { 404,406 }, text = { - "Lists the Admin(s), Responsible Party(s), Role(s), Permission(s)", - "Credential(s) and Expiration of Credential(s) in Namespace :id", + "Lists the Owner(s), Admin(s), Description, and Attributes of Namespace :id", } ) @Override @@ -476,7 +478,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } - Result<List<NsDAO.Data>> rlnd = ques.nsDAO.read(trans, ns); + Result<List<NsDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } private Result<Collection<Namespace>> loadNamepace(AuthzTrans trans, String user, String endsWith, boolean full) { - Result<List<UserRoleDAO.Data>> urd = ques.userRoleDAO.readByUser(trans, user); + Result<List<UserRoleDAO.Data>> urd = ques.userRoleDAO().readByUser(trans, user); if (urd.notOKorIsEmpty()) { return Result.err(urd); } @@ -679,7 +681,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } Set<Namespace> lm = new HashSet<>(); - Result<List<NsDAO.Data>> rlnd = ques.nsDAO.dao().getChildren(trans, parent); + Result<List<NsDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } Namespace namespace = nsd.value; - Result<List<NsDAO.Data>> rlnd = ques.nsDAO.read(trans, namespace.name); + Result<List<NsDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_Denied, "You do not have approval to change %s",namespace.name); } - Result<Void> rdr = ques.nsDAO.dao().addDescription(trans, namespace.name, namespace.description); + Result<Void> rdr = ques.nsDAO().dao().addDescription(trans, namespace.name, namespace.description); if (rdr.isOK()) { return Result.ok(); } else { @@ -797,6 +799,12 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE @Override public Result<Void> createPerm(final AuthzTrans trans,REQUEST rreq) { final Result<PermDAO.Data> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return nsd; } }); - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, newPd.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, newPd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1138,7 +1146,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(rnd); } - Result<List<PermDAO.Data>> rlpd = ques.permDAO.readNS(trans, ns); + Result<List<PermDAO.Data>> rlpd = ques.permDAO().readNS(trans, ns); if (rlpd.notOK()) { return Result.err(rlpd); } @@ -1176,7 +1184,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } Result<NsSplit> nss = ques.deriveNsSplit(trans, origType); - Result<List<PermDAO.Data>> origRlpd = ques.permDAO.read(trans, nss.value.ns, nss.value.name, origInstance, origAction); + Result<List<PermDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } final PermDAO.Data perm = pd.value; - if (ques.permDAO.read(trans, perm.ns, perm.type, perm.instance,perm.action).notOKorIsEmpty()) { + if (ques.permDAO().read(trans, perm.ns, perm.type, perm.instance,perm.action).notOKorIsEmpty()) { return Result.err(Status.ERR_NotFound, "Permission [%s.%s|%s|%s] does not exist", perm.ns,perm.type,perm.instance,perm.action); } @@ -1245,12 +1253,12 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE perm.ns,perm.type,perm.instance,perm.action); } - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, pd.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, pd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } - Result<Void> rdr = ques.permDAO.addDescription(trans, perm.ns, perm.type, perm.instance, + Result<Void> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } // Read full set to get CURRENT values - Result<List<PermDAO.Data>> rcurr = ques.permDAO.read(trans, + Result<List<PermDAO.Data>> rcurr = ques.permDAO().read(trans, updt.value.ns, updt.value.type, updt.value.instance, @@ -1321,7 +1329,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (!currRoles.contains(role)) { Result<RoleDAO.Data> key = RoleDAO.Data.decode(trans, ques, role); if (key.isOKhasData()) { - Result<List<RoleDAO.Data>> rrd = ques.roleDAO.read(trans, key.value); + Result<List<RoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (!updtRoles.contains(role)) { Result<RoleDAO.Data> key = RoleDAO.Data.decode(trans, ques, role); if (key.isOKhasData()) { - Result<List<RoleDAO.Data>> rdd = ques.roleDAO.read(trans, key.value); + Result<List<RoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } final PermDAO.Data perm = pd.value; - if (ques.permDAO.read(trans, perm).notOKorIsEmpty()) { + if (ques.permDAO().read(trans, perm).notOKorIsEmpty()) { return Result.err(Status.ERR_PermissionNotFound, "Permission [%s.%s|%s|%s] does not exist", perm.ns,perm.type,perm.instance,perm.action ); } @@ -1405,7 +1413,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE switch(fd.status) { case OK: - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, perm.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, perm.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1483,12 +1491,17 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE @Override public Result<Void> createRole(final AuthzTrans trans, REQUEST from) { final Result<RoleDAO.Data> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } }); - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, rd.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, rd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1529,7 +1542,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(rfc); } case Status.ACC_Now: - Result<RoleDAO.Data> rdr = ques.roleDAO.create(trans, role); + Result<RoleDAO.Data> rdr = ques.roleDAO().create(trans, role); if (rdr.isOK()) { return Result.ok(); } else { @@ -1608,10 +1621,10 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE ROLES roles = mapper.newInstance(API.ROLES); // Get list of roles per user, then add to Roles as we go Result<List<RoleDAO.Data>> rlrd; - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByUser(trans, user); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE try { ROLES roles = mapper.newInstance(API.ROLES); // Get list of roles per user, then add to Roles as we go - Result<List<RoleDAO.Data>> rlrd = ques.roleDAO.readNS(trans, ns); + Result<List<RoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE try { ROLES roles = mapper.newInstance(API.ROLES); // Get list of roles per user, then add to Roles as we go - Result<List<RoleDAO.Data>> rlrd = ques.roleDAO.readName(trans, name); + Result<List<RoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(res); } - Result<List<PermDAO.Data>> pdlr = ques.permDAO.read(trans, pdd); + Result<List<PermDAO.Data>> pdlr = ques.permDAO().read(trans, pdd); if (pdlr.isOK())for (PermDAO.Data pd : pdlr.value) { Result<List<RoleDAO.Data>> rlrd; for (String r : pd.roles) { Result<String[]> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } } final RoleDAO.Data role = rd.value; - if (ques.roleDAO.read(trans, role.ns, role.name).notOKorIsEmpty()) { + if (ques.roleDAO().read(trans, role.ns, role.name).notOKorIsEmpty()) { return Result.err(Status.ERR_NotFound, "Role [" + role.fullName() + "] does not exist"); } @@ -1807,12 +1820,12 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_Denied, "You do not have approval to change " + role.fullName()); } - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, rd.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, rd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } - Result<Void> rdr = ques.roleDAO.addDescription(trans, role.ns, role.name, role.description); + Result<Void> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } - Result<List<RoleDAO.Data>> rlrd = ques.roleDAO.read(trans, rrd.value.ns, rrd.value.name); + Result<List<RoleDAO.Data>> 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<List<PermDAO.Data>> rlpd = ques.permDAO.read(trans, rpd.value.ns, + Result<List<PermDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return nsd; } }); - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, rpd.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, rpd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -1980,7 +1993,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } private Result<Void> delPermFromRole(final AuthzTrans trans, PermDAO.Data pdd, RoleDAO.Data rdd, REQUEST rreq) { - Result<List<PermDAO.Data>> rlpd = ques.permDAO.read(trans, pdd.ns, pdd.type, + Result<List<PermDAO.Data>> rlpd = ques.permDAO().read(trans, pdd.ns, pdd.type, pdd.instance, pdd.action); if (rlpd.notOKorIsEmpty()) { @@ -2007,7 +2020,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return nsd; } }); - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, pdd.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, pdd.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2070,12 +2083,12 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(rrns); } - final Result<List<RoleDAO.Data>> rrd = ques.roleDAO.read(trans, rrns.value.parent, rrns.value.name); + final Result<List<RoleDAO.Data>> rrd = ques.roleDAO().read(trans, rrns.value.parent, rrns.value.name); if (rrd.notOKorIsEmpty()) { return Result.err(rrd); } - final Result<List<PermDAO.Data>> rpd = ques.permDAO.read(trans, rpns.value.parent, rpns.value.name, instance, action); + final Result<List<PermDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } final RoleDAO.Data role = rd.value; - if (ques.roleDAO.read(trans, role).notOKorIsEmpty() && !trans.requested(force)) { + if (ques.roleDAO().read(trans, role).notOKorIsEmpty() && !trans.requested(force)) { return Result.err(Status.ERR_RoleNotFound, "Role [" + role.fullName() + "] does not exist"); } @@ -2151,7 +2164,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE switch(fd.status) { case OK: - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, rd.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, rd.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2299,7 +2312,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_Policy,"MechIDs must be registered with %s before provisioning in AAF",org.getName()); } - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, rcred.value.ns); + Result<List<NsDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE MayChange mc; CassExecutor exec = new CassExecutor(trans, func); - Result<List<CredDAO.Data>> rlcd = ques.credDAO.readID(trans, rcred.value.id); + Result<List<CredDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE String theMechID = rcred.value.id; Boolean otherMechIDs = false; // find out if this is the only mechID. other MechIDs mean special handling (not automated) - for (CredDAO.Data cd : ques.credDAO.readNS(trans,nsr.value.get(0).name).value) { + for (CredDAO.Data cd : ques.credDAO().readNS(trans,nsr.value.get(0).name).value) { if (!cd.id.equals(theMechID)) { otherMechIDs = true; break; @@ -2396,7 +2409,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE trans.error().log(e, "While setting expiration to TempPassword"); } - Result<?>udr = ques.credDAO.create(trans, rcred.value); + Result<?>udr = ques.credDAO().create(trans, rcred.value); if (udr.isOK()) { return Result.ok(); } @@ -2442,7 +2455,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE TimeTaken tt = trans.start("MAP Creds by NS to Creds", Env.SUB); try { USERS users = mapper.newInstance(API.USERS); - Result<List<CredDAO.Data>> rlcd = ques.credDAO.readNS(trans, ns); + Result<List<CredDAO.Data>> rlcd = ques.credDAO().readNS(trans, ns); if (rlcd.isOK()) { if (!rlcd.isEmpty()) { @@ -2489,7 +2502,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE TimeTaken tt = trans.start("MAP Creds by ID to Creds", Env.SUB); try { USERS users = mapper.newInstance(API.USERS); - Result<List<CredDAO.Data>> rlcd = ques.credDAO.readID(trans, id); + Result<List<CredDAO.Data>> rlcd = ques.credDAO().readID(trans, id); if (rlcd.isOK()) { if (!rlcd.isEmpty()) { @@ -2519,7 +2532,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE TimeTaken tt = trans.start("Get Cert Info by ID", Env.SUB); try { CERTS certs = mapper.newInstance(API.CERTS); - Result<List<CertDAO.Data>> rlcd = ques.certDAO.readID(trans, id); + Result<List<CertDAO.Data>> rlcd = ques.certDAO().readID(trans, id); if (rlcd.isOK()) { if (!rlcd.isEmpty()) { @@ -2560,7 +2573,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (v.cred(trans, trans.org(),rcred,false).err()) {// Note: Creates have stricter Validations return Result.err(Status.ERR_BadData,v.errs()); } - Result<List<CredDAO.Data>> rlcd = ques.credDAO.readID(trans, rcred.value.id); + Result<List<CredDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE }, mc); - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, rcred.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, rcred.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2634,9 +2647,9 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE rcred.value.expires = org.expiration(null,exp).getTime(); } - udr = ques.credDAO.create(trans, rcred.value); + udr = ques.credDAO().create(trans, rcred.value); if (udr.isOK()) { - udr = ques.credDAO.delete(trans, rlcd.value.get(entry),false); + udr = ques.credDAO().delete(trans, rlcd.value.get(entry),false); } if (udr.isOK()) { return Result.ok(); @@ -2712,7 +2725,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } // Get the list of Cred Entries - Result<List<CredDAO.Data>> rlcd = ques.credDAO.readID(trans, cred.value.id); + Result<List<CredDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE cd.expires = org.expiration(null, Expiration.ExtendPassword,days).getTime(); cd.tag = found.tag; - cred = ques.credDAO.create(trans, cd); + cred = ques.credDAO().create(trans, cd); if (cred.isOK()) { return Result.ok(); } @@ -2796,13 +2809,13 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } - Result<List<CredDAO.Data>> rlcd = ques.credDAO.readID(trans, cred.value.id); + Result<List<CredDAO.Data>> rlcd = ques.credDAO().readID(trans, cred.value.id); if (rlcd.notOKorIsEmpty()) { // Empty Creds should have no user_roles. - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByUser(trans, cred.value.id); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE ']', mc); - Result<List<NsDAO.Data>> nsr = ques.nsDAO.read(trans, cred.value.ns); + Result<List<NsDAO.Data>> nsr = ques.nsDAO().read(trans, cred.value.ns); if (nsr.notOKorIsEmpty()) { return Result.err(nsr); } @@ -2880,20 +2893,20 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (entry<0 || entry >= 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<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByUser(trans, cred.value.id); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE // Get list of roles per user, then add to Roles as we go HashSet<UserRoleDAO.Data> userSet = new HashSet<>(); - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByRole(trans, role); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } // Get list of roles per user, then add to Roles as we go - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByUser(trans, user); + Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO().readByUser(trans, user); if (rlurd.notOK()) { return Result.err(rlurd); } @@ -3188,172 +3201,9 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } - @ApiDoc( - method = PUT, - path = "/authz/userRole/user", - params = {}, - expectedCode = 200, - errorCodes = {403,404,406}, - text = { "Set a User's roles to the roles specified in the UserRoleRequest object.", - "WARNING: Roles supplied will be the ONLY roles attached to this user", - "If no roles are supplied, user's roles are reset." - } - ) - @Override - public Result<Void> resetRolesForUser(AuthzTrans trans, REQUEST rreq) { - Result<UserRoleDAO.Data> 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<String> currRoles = new HashSet<>(); - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByUser(trans, rurdd.value.user); - if (rlurd.isOK()) { - for (UserRoleDAO.Data data : rlurd.value) { - currRoles.add(data.role); - } - } - - Result<Void> 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<RoleDAO.Data> rrdd = RoleDAO.Data.decode(trans, ques, role); - if (rrdd.notOK()) { - return Result.err(rrdd); - } - - rurdd.value.role(rrdd.value); - - Result<NsDAO.Data> nsd = ques.mayUser(trans, trans.user(), rrdd.value,Access.write); - if (nsd.notOK()) { - return Result.err(nsd); - } - Result<NsDAO.Data> 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<Void> resetUsersForRole(AuthzTrans trans, REQUEST rreq) { - Result<UserRoleDAO.Data> 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<NsDAO.Data> nsd = ques.mayUser(trans, trans.user(), rd, Access.write); - if (nsd.notOK()) { - return Result.err(nsd); - } - - Result<NsDAO.Data> nsr = ques.deriveNs(trans, rurdd.value.role); - if (nsr.notOKorIsEmpty()) { - return Result.err(nsr); - } - - Set<String> currUsers = new HashSet<>(); - Result<List<UserRoleDAO.Data>> 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<Void> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(rcr); } - Result<List<UserRoleDAO.Data>> rr = ques.userRoleDAO.read(trans, user,role); + Result<List<UserRoleDAO.Data>> rr = ques.userRoleDAO().read(trans, user,role); if (rr.notOK()) { return Result.err(rr); } @@ -3461,7 +3311,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(rfc); } } else { - return ques.userRoleDAO.delete(trans, rulr.value.get(0), false); + return ques.userRoleDAO().delete(trans, rulr.value.get(0), false); } } @@ -3521,7 +3371,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } HashSet<UserRoleDAO.Data> userSet = new HashSet<>(); - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readUserInRole(trans, user, role); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } HashSet<UserRoleDAO.Data> userSet = new HashSet<>(); - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByRole(trans, role); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(nss); } - Result<List<NsDAO.Data>> nsd = ques.nsDAO.read(trans, nss.value.ns); + Result<List<NsDAO.Data>> nsd = ques.nsDAO().read(trans, nss.value.ns); if (nsd.notOK()) { return Result.err(nsd); } @@ -3640,7 +3490,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE Set<UserRoleDAO.Data> userSet = new HashSet<>(); if (!nss.isEmpty()) { - Result<List<PermDAO.Data>> rlp = ques.permDAO.readByType(trans, nss.value.ns, nss.value.name); + Result<List<PermDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE for (String role : pd.roles) { if (!roleUsed.contains(role)) { // avoid evaluating Role many times roleUsed.add(role); - Result<List<UserRoleDAO.Data>> rlurd = ques.userRoleDAO.readByRole(trans, role.replace('|', '.')); + Result<List<UserRoleDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } } } - Result<List<HistoryDAO.Data>> resp = ques.historyDAO.readByUser(trans, user, yyyymm); + Result<List<HistoryDAO.Data>> resp = ques.historyDAO().readByUser(trans, user, yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3726,7 +3576,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (rnd.notOK()) { return Result.err(rnd); } - Result<List<HistoryDAO.Data>> resp = ques.historyDAO.readBySubject(trans, role, "role", yyyymm); + Result<List<HistoryDAO.Data>> resp = ques.historyDAO().readBySubject(trans, role, "role", yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3751,7 +3601,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (rnd.notOK()) { return Result.err(rnd); } - Result<List<HistoryDAO.Data>> resp = ques.historyDAO.readBySubject(trans, type, "perm", yyyymm); + Result<List<HistoryDAO.Data>> resp = ques.historyDAO().readBySubject(trans, type, "perm", yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3775,7 +3625,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(rnd); } - Result<List<HistoryDAO.Data>> resp = ques.historyDAO.readBySubject(trans, ns, "ns", yyyymm); + Result<List<HistoryDAO.Data>> resp = ques.historyDAO().readBySubject(trans, ns, "ns", yyyymm); if (resp.notOK()) { return Result.err(resp); } @@ -3805,7 +3655,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE final DelegateDAO.Data dd = rd.value; - Result<List<DelegateDAO.Data>> ddr = ques.delegateDAO.read(trans, dd); + Result<List<DelegateDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } case Status.ACC_Now: if (access==Access.create) { - Result<DelegateDAO.Data> rdr = ques.delegateDAO.create(trans, dd); + Result<DelegateDAO.Data> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } Result<List<DelegateDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return rv; } - return ques.delegateDAO.delete(trans, dd, false); + return ques.delegateDAO().delete(trans, dd, false); } @Override @@ -3889,7 +3739,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } dd.user = userName; Result<List<DelegateDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return rv; } - return ques.delegateDAO.delete(trans, dd, false); + return ques.delegateDAO().delete(trans, dd, false); } @Override @@ -3918,7 +3768,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE TimeTaken tt = trans.start("Get delegates for a user", Env.SUB); - Result<List<DelegateDAO.Data>> dbDelgs = ques.delegateDAO.read(trans, user); + Result<List<DelegateDAO.Data>> dbDelgs = ques.delegateDAO().read(trans, user); try { if (dbDelgs.isOKhasData()) { return mapper.delegate(dbDelgs.value); @@ -3946,7 +3796,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE TimeTaken tt = trans.start("Get users for a delegate", Env.SUB); - Result<List<DelegateDAO.Data>> dbDelgs = ques.delegateDAO.readByDelegate(trans, delegate); + Result<List<DelegateDAO.Data>> dbDelgs = ques.delegateDAO().readByDelegate(trans, delegate); try { if (dbDelgs.isOKhasData()) { return mapper.delegate(dbDelgs.value); @@ -3979,16 +3829,16 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE Lookup<List<ApprovalDAO.Data>> 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<ApprovalDAO.Data> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE if (cd.ticket!=null) { FutureDAO.Data fdd = futureCache.get(cd.ticket); if (fdd==null) { // haven't processed ticket yet - Result<FutureDAO.Data> rfdd = ques.futureDAO.readPrimKey(trans, cd.ticket); + Result<FutureDAO.Data> rfdd = ques.futureDAO().readPrimKey(trans, cd.ticket); if (rfdd.isOK()) { fdd = rfdd.value; // null is ok } else { @@ -4067,7 +3917,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE ++numProcessed; } if (ch.hasChanged()) { - ques.approvalDAO.update(trans, cd, true); + ques.approvalDAO().update(trans, cd, true); } } } @@ -4110,7 +3960,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,v.errs()); } - Result<List<ApprovalDAO.Data>> rapd = ques.approvalDAO.readByUser(trans, user); + Result<List<ApprovalDAO.Data>> rapd = ques.approvalDAO().readByUser(trans, user); if (rapd.isOK()) { return mapper.approvals(rapd.value); } else { @@ -4131,7 +3981,7 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE return Result.err(Status.ERR_BadData,e.getMessage()); } - Result<List<ApprovalDAO.Data>> rapd = ques.approvalDAO.readByTicket(trans, uuid); + Result<List<ApprovalDAO.Data>> rapd = ques.approvalDAO().readByTicket(trans, uuid); if (rapd.isOK()) { return mapper.approvals(rapd.value); } else { @@ -4148,19 +3998,19 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE List<ApprovalDAO.Data> listRapds = new ArrayList<>(); - Result<List<ApprovalDAO.Data>> myRapd = ques.approvalDAO.readByApprover(trans, approver); + Result<List<ApprovalDAO.Data>> myRapd = ques.approvalDAO().readByApprover(trans, approver); if (myRapd.notOK()) { return Result.err(myRapd); } listRapds.addAll(myRapd.value); - Result<List<DelegateDAO.Data>> delegatedFor = ques.delegateDAO.readByDelegate(trans, approver); + Result<List<DelegateDAO.Data>> 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<List<ApprovalDAO.Data>> rapd = ques.approvalDAO.readByApprover(trans, delegator); + Result<List<ApprovalDAO.Data>> 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 <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE */ @Override public void dbReset(AuthzTrans trans) { - ques.historyDAO.reportPerhapsReset(trans, null); + ques.historyDAO().reportPerhapsReset(trans, null); } } diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzService.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzService.java index 178e1aae..a89f64ed 100644 --- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzService.java +++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzService.java @@ -566,21 +566,10 @@ public interface AuthzService<NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DELGS,CERT */ public Result<USERROLES> getUserRolesByUser(AuthzTrans trans, String user); - /** - * - * @param trans - * @param from - * @return - */ - public Result<Void> 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<Void> 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<Object> 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<Void> 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<Void> 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<Void> getUserRolesByUser(AuthzTrans trans, HttpServletResponse resp, String user); public abstract Result<Void> deleteUserRole(AuthzTrans trans, HttpServletResponse resp, String user, String role); - - public abstract Result<Void> resetUsersForRole(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req); - public abstract Result<Void> resetRolesForUser(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req); + /* + * resetUsersForRoles and resetRolesForUsers is too dangerous and not helpful. + */ public abstract Result<Void> 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<NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE private static final String GET_USERROLES = "getUserRoles"; private static final String GET_USERROLES_BY_ROLE = "getUserRolesByRole"; private static final String GET_USERROLES_BY_USER = "getUserRolesByUser"; - private static final String SET_ROLES_FOR_USER = "setRolesForUser"; - private static final String SET_USERS_FOR_ROLE = "setUsersForRole"; +// private static final String SET_ROLES_FOR_USER = "setRolesForUser"; +// private static final String SET_USERS_FOR_ROLE = "setUsersForRole"; private static final String EXTEND_USER_ROLE = "extendUserRole"; private static final String DELETE_USER_ROLE = "deleteUserRole"; @Override @@ -2060,75 +2060,6 @@ public abstract class AuthzFacadeImpl<NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DE } - @Override - public Result<Void> resetUsersForRole(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req) { - TimeTaken tt = trans.start(SET_USERS_FOR_ROLE, Env.SUB|Env.ALWAYS); - try { - REQUEST rreq; - try { - RosettaData<REQUEST> 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<Void> 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<Void> resetRolesForUser(AuthzTrans trans, HttpServletResponse resp, HttpServletRequest req) { - TimeTaken tt = trans.start(SET_ROLES_FOR_USER, Env.SUB|Env.ALWAYS); - try { - REQUEST rreq; - try { - RosettaData<REQUEST> 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<Void> 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<Nss, Perms, Pkey, Roles, Users, UserRo user.setId(cred.id); user.setExpires(Chrono.timeStamp(cred.expires)); user.setType(cred.type); + user.setTag(cred.tag); cu.add(user); } return Result.ok(to); diff --git a/auth/helm/aaf-hello/Chart.yaml b/auth/helm/aaf-hello/Chart.yaml index 3b23f6d0..96ede381 100644 --- a/auth/helm/aaf-hello/Chart.yaml +++ b/auth/helm/aaf-hello/Chart.yaml @@ -22,4 +22,4 @@ apiVersion: v1 appVersion: "1.0" description: AAF Hello Helm Chart name: aaf-hello -version: 2.1.11-SNAPSHOT +version: 2.1.12-SNAPSHOT diff --git a/auth/helm/aaf-hello/values.yaml b/auth/helm/aaf-hello/values.yaml index a695a456..8d43070e 100644 --- a/auth/helm/aaf-hello/values.yaml +++ b/auth/helm/aaf-hello/values.yaml @@ -54,7 +54,7 @@ image: # When using Docker Repo, add, and include trailing "/" # repository: nexus3.onap.org:10003/ # repository: localhost:5000/ - version: 2.1.11-SNAPSHOT + version: 2.1.12-SNAPSHOT resources: {} # We usually recommend not to specify default resources and to leave this as a conscious diff --git a/auth/helm/aaf/Chart.yaml b/auth/helm/aaf/Chart.yaml index e5ba1746..0f0f2761 100644 --- a/auth/helm/aaf/Chart.yaml +++ b/auth/helm/aaf/Chart.yaml @@ -22,4 +22,4 @@ apiVersion: v1 appVersion: "1.0" description: AAF Helm Chart name: aaf -version: 2.1.11-SNAPSHOT +version: 2.1.12-SNAPSHOT |