X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2FBatch.java;h=7826eb68cd9d1cb1dabda021284abe98c4ff0ce2;hb=5f1a6a0ab09ea3fa4199a8d413af75d4378e2a8e;hp=64c09711110a3b1851593dc3035f952182cb6c37;hpb=67bac2c1c44beab7752b39584553449e1c8a4e94;p=aaf%2Fauthz.git 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 64c09711..7826eb68 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,11 @@ 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 final Organization org; @@ -123,7 +121,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 +132,7 @@ public abstract class Batch { org.setTestMode(dryRun); // Special names to allow behaviors beyond normal rules - specialNames = new HashSet(); + specialNames = new HashSet<>(); String names = env.getProperty( "SPECIAL_NAMES" ); if ( names != null ) { @@ -147,11 +145,11 @@ public abstract class Batch { } } - protected abstract void run(AuthzTrans trans); + protected abstract void run(AuthzTrans trans); protected abstract void _close(AuthzTrans trans); public String[] args() { - return (String[])env.get(ssargs); + return env.get(ssargs); } public boolean isDryRun() @@ -177,9 +175,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 +185,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 +196,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 +217,7 @@ public abstract class Batch { return (null); } - return (org); + return (organization); } public static Row executeDeleteQuery(Statement stmt) { @@ -238,7 +235,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 +328,32 @@ public abstract class Batch { // IMPORTANT! VALIDATE Organization isUser method protected void checkOrganizationAcccess(AuthzTrans trans, Question q) throws APIException, OrganizationException { - Set testUsers = new HashSet(); - Result> rrd = q.roleDAO.readNS(trans, ROOT_NS); - if(rrd.isOK()) { - for(RoleDAO.Data r : rrd.value) { - Result> rur = q.userRoleDAO.readByRole(trans, r.fullName()); - if(rur.isOK()) { - for(UserRoleDAO.Data udd : rur.value) { + Set testUsers = new HashSet<>(); + Result> rrd = q.roleDAO.readNS(trans, rootNs); + if (rrd.isOK()) { + for (RoleDAO.Data r : rrd.value) { + Result> 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 +390,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 { @@ -422,12 +420,7 @@ public abstract class Batch { // Flow all Env Logs to Log4j, with ENV LogFileNamer lfn; - if ((batchEnv = env.getProperty(CASS_ENV)) == null) { - lfn = new LogFileNamer(logDir()).noPID(); - } else { - lfn = new LogFileNamer(logDir()).noPID(); - } - + lfn = new LogFileNamer(logDir(),"").noPID(); lfn.setAppender("authz-batch"); lfn.setAppender("aspr|ASPR"); lfn.setAppender("sync");