diff options
Diffstat (limited to 'auth')
4 files changed, 58 insertions, 62 deletions
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java index d4b582a3..b2043f07 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java @@ -68,7 +68,7 @@ import com.datastax.driver.core.Statement; public abstract class Batch { - private static String ROOT_NS; + private static String rootNs; private static StaticSlot ssargs; @@ -84,13 +84,13 @@ public abstract class Batch { public static final String CASS_ENV = "CASS_ENV"; public static final String LOG_DIR = "LOG_DIR"; - protected final static String PUNT="punt"; - protected final static String MAX_EMAILS="MAX_EMAILS"; - protected final static String VERSION="VERSION"; - public final static String GUI_URL="GUI_URL"; + protected static final String PUNT="punt"; + protected static final String MAX_EMAILS="MAX_EMAILS"; + protected static final String VERSION="VERSION"; + public static final String GUI_URL="GUI_URL"; - protected final static String ORA_URL="ora_url"; - protected final static String ORA_PASSWORD="ora_password"; + protected static final String ORA_URL="ora_url"; + protected static final String ORA_PASSWORD="ora_password"; protected final Organization org; @@ -123,7 +123,7 @@ public abstract class Batch { cluster = CassAccess.cluster(env,batchEnv); env.info().log("cluster name - ",cluster.getClusterName()); String dryRunStr = env.getProperty( "DRY_RUN" ); - if ( dryRunStr == null || dryRunStr.trim().equals("false") ) { + if ( dryRunStr == null || "false".equals(dryRunStr.trim()) ) { dryRun = false; } else { dryRun = true; @@ -134,7 +134,7 @@ public abstract class Batch { org.setTestMode(dryRun); // Special names to allow behaviors beyond normal rules - specialNames = new HashSet<String>(); + specialNames = new HashSet<>(); String names = env.getProperty( "SPECIAL_NAMES" ); if ( names != null ) { @@ -151,7 +151,7 @@ public abstract class Batch { protected abstract void _close(AuthzTrans trans); public String[] args() { - return (String[])env.get(ssargs); + return env.get(ssargs); } public boolean isDryRun() @@ -177,9 +177,9 @@ public abstract class Batch { } } - protected PrintStream fallout(PrintStream _fallout, String logType) + protected PrintStream fallout(PrintStream inFallout, String logType) throws IOException { - PrintStream fallout = _fallout; + PrintStream fallout = inFallout; if (fallout == null) { File dir = new File("logs"); if (!dir.exists()) { @@ -187,7 +187,6 @@ public abstract class Batch { } File f = null; - // String os = System.getProperty("os.name").toLowerCase(); long uniq = System.currentTimeMillis(); f = new File(dir, getClass().getSimpleName() + "_" + logType + "_" @@ -199,15 +198,15 @@ public abstract class Batch { } public Organization getOrgFromID(AuthzTrans trans, String user) { - Organization org; + Organization organization; try { - org = OrganizationFactory.obtain(trans.env(),user.toLowerCase()); + organization = OrganizationFactory.obtain(trans.env(),user.toLowerCase()); } catch (OrganizationException e1) { trans.error().log(e1); - org=null; + organization=null; } - if (org == null) { + if (organization == null) { PrintStream fallout = null; try { @@ -220,7 +219,7 @@ public abstract class Batch { return (null); } - return (org); + return (organization); } public static Row executeDeleteQuery(Statement stmt) { @@ -238,7 +237,7 @@ public abstract class Batch { String envStr = env.getProperty("AFT_ENVIRONMENT"); if (envStr != null) { - if (envStr.equals("AFTPRD")) { + if ("AFTPRD".equals(envStr)) { testEnv = false; } } else { @@ -331,31 +330,32 @@ public abstract class Batch { // IMPORTANT! VALIDATE Organization isUser method protected void checkOrganizationAcccess(AuthzTrans trans, Question q) throws APIException, OrganizationException { - Set<String> testUsers = new HashSet<String>(); - Result<List<RoleDAO.Data>> rrd = q.roleDAO.readNS(trans, ROOT_NS); - if(rrd.isOK()) { - for(RoleDAO.Data r : rrd.value) { - Result<List<UserRoleDAO.Data>> rur = q.userRoleDAO.readByRole(trans, r.fullName()); - if(rur.isOK()) { - for(UserRoleDAO.Data udd : rur.value) { + Set<String> testUsers = new HashSet<>(); + Result<List<RoleDAO.Data>> rrd = q.roleDAO.readNS(trans, rootNs); + if (rrd.isOK()) { + for (RoleDAO.Data r : rrd.value) { + Result<List<UserRoleDAO.Data>> rur = q.userRoleDAO.readByRole(trans, r.fullName()); + if (!rur.isOK()) { + continue; + } + for (UserRoleDAO.Data udd : rur.value) { testUsers.add(udd.user); } } + if (testUsers.size() < 2) { + throw new APIException("Not enough Users in Roles for " + rootNs + " to Validate"); + } + + Identity iden; + for (String user : testUsers) { + if ((iden = org.getIdentity(trans, user)) == null) { + throw new APIException("Failed Organization Entity Validation Check: " + user); + } else { + trans.info().log("Organization Validation Check: " + iden.id()); + } + } } } - if(testUsers.size()<2) { - throw new APIException("Not enough Users in Roles for " + ROOT_NS + " to Validate"); - } - - Identity iden; - for(String user : testUsers) { - if((iden=org.getIdentity(trans,user))==null) { - throw new APIException("Failed Organization Entity Validation Check: " + user); - } else { - trans.info().log("Organization Validation Check: " + iden.id()); - } - } - } protected static String logDir() { String ld = env.getProperty(LOG_DIR); @@ -392,7 +392,7 @@ public abstract class Batch { String propLoc; try { Define.set(access); - ROOT_NS=Define.ROOT_NS(); + rootNs =Define.ROOT_NS(); File f = new File("etc/authzBatch.props"); try { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/Email.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/Email.java index 25e2ffca..15dfed38 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/Email.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/Email.java @@ -46,9 +46,9 @@ public class Email implements Action<Organization,Void, String>{ public Email(String ... defaultCC) { - toList = new ArrayList<String>(); + toList = new ArrayList<>(); this.defaultCC = defaultCC; - ccList = new ArrayList<String>(); + ccList = new ArrayList<>(); clear(); } @@ -71,10 +71,8 @@ public class Email implements Action<Organization,Void, String>{ } public Email addTo(Identity id) { - if(id!=null) { - if(!toList.contains(id.email())) { + if(id!=null && !toList.contains(id.email())) { toList.add(id.email()); - } } return this; } @@ -94,10 +92,8 @@ public class Email implements Action<Organization,Void, String>{ } public Email addCC(Identity id) { - if(id!=null) { - if(!ccList.contains(id.email())) { + if(id!=null && !ccList.contains(id.email())) { ccList.add(id.email()); - } } return this; } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/URFutureApproveExec.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/URFutureApproveExec.java index 6cf2c53e..635efef0 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/URFutureApproveExec.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/URFutureApproveExec.java @@ -56,8 +56,8 @@ public class URFutureApproveExec extends ActionDAO<List<Approval>, OP_STATUS, Fu return Result.err(Result.ERR_ActionNotCompleted,"Not Executed"); } else { // Save on Lookups - final List<ApprovalDAO.Data> apprs = new ArrayList<ApprovalDAO.Data>(); - final List<UserRoleDAO.Data> urs = new ArrayList<UserRoleDAO.Data>(); + final List<ApprovalDAO.Data> apprs = new ArrayList<>(); + final List<UserRoleDAO.Data> urs = new ArrayList<>(); for(Approval a : app) { apprs.add(a.add); UserRole ur = UserRole.get(a.add.user, future.role); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/cache/Cache.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/cache/Cache.java index 17368031..9d48ecbe 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/cache/Cache.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/cache/Cache.java @@ -50,12 +50,11 @@ public class Cache<TRANS extends Trans, DATA> { public static final String CACHE_HIGH_COUNT = "CACHE_HIGH_COUNT"; public static final String CACHE_CLEAN_INTERVAL = "CACHE_CLEAN_INTERVAL"; -// public static final String CACHE_MIN_REFRESH_INTERVAL = "CACHE_MIN_REFRESH_INTERVAL"; private static final Map<String,Map<String,Dated>> cacheMap; static { - cacheMap = new HashMap<String,Map<String,Dated>>(); + cacheMap = new HashMap<>(); } /** @@ -64,7 +63,7 @@ public class Cache<TRANS extends Trans, DATA> { * @author Jonathan * */ - public final static class Dated { + public static final class Dated { public Date timestamp; public List<?> data; private long expireIn; @@ -77,7 +76,7 @@ public class Cache<TRANS extends Trans, DATA> { public <T> Dated(T t, long expireIn) { timestamp = new Date(System.currentTimeMillis()+expireIn); - ArrayList<T> al = new ArrayList<T>(1); + ArrayList<T> al = new ArrayList<>(1); al.add(t); data = al; this.expireIn = expireIn; @@ -91,7 +90,7 @@ public class Cache<TRANS extends Trans, DATA> { public static Map<String,Dated> obtain(String key) { Map<String, Dated> m = cacheMap.get(key); if(m==null) { - m = new ConcurrentHashMap<String, Dated>(); + m = new ConcurrentHashMap<>(); synchronized(cacheMap) { cacheMap.put(key, m); } @@ -108,7 +107,7 @@ public class Cache<TRANS extends Trans, DATA> { * @author Jonathan * */ - private final static class Clean extends TimerTask { + private static final class Clean extends TimerTask { private final Env env; private Set<String> set; @@ -124,7 +123,7 @@ public class Cache<TRANS extends Trans, DATA> { high = highCount; timeInterval = cleanInterval; advance = 0; - set = new HashSet<String>(); + set = new HashSet<>(); } public synchronized void add(String key) { @@ -140,16 +139,17 @@ public class Cache<TRANS extends Trans, DATA> { for(String name : set) { Map<String,Dated> map = cacheMap.get(name); - if(map!=null) for(Map.Entry<String,Dated> me : map.entrySet()) { + if(map==null) { + continue; + } + + for(Map.Entry<String,Dated> me : map.entrySet()) { ++total; - if(me.getValue().timestamp.before(now)) { + if (me.getValue().timestamp.before(now)) { map.remove(me.getKey()); ++count; } } -// if(count>0) { -// env.info().log(Level.INFO, "Cache removed",count,"expired",name,"Elements"); -// } } if(count>0) { |