From 7e966914050e66219689001ff4ab601a49eef0ac Mon Sep 17 00:00:00 2001 From: Instrumental Date: Fri, 7 Sep 2018 13:43:23 -0500 Subject: Mass whitespace changes (Style Warnings) Issue-ID: AAF-473 Change-Id: Ia1b3825a527bd56299949b5962bb9354dffbeef8 Signed-off-by: Instrumental --- cadi/core/src/main/java/org/onap/aaf/cadi/AES.java | 4 +- .../main/java/org/onap/aaf/cadi/AbsUserCache.java | 60 ++++---- .../src/main/java/org/onap/aaf/cadi/Access.java | 6 +- .../onap/aaf/cadi/BufferedServletInputStream.java | 24 ++-- .../src/main/java/org/onap/aaf/cadi/CadiWrap.java | 10 +- .../src/main/java/org/onap/aaf/cadi/Capacitor.java | 48 +++---- .../src/main/java/org/onap/aaf/cadi/CmdLine.java | 84 ++++++------ .../core/src/main/java/org/onap/aaf/cadi/Hash.java | 34 ++--- .../main/java/org/onap/aaf/cadi/PropAccess.java | 70 +++++----- .../org/onap/aaf/cadi/ServletContextAccess.java | 4 +- .../core/src/main/java/org/onap/aaf/cadi/Symm.java | 94 ++++++------- .../core/src/main/java/org/onap/aaf/cadi/User.java | 6 +- .../main/java/org/onap/aaf/cadi/config/Config.java | 152 ++++++++++----------- .../main/java/org/onap/aaf/cadi/config/Get.java | 6 +- .../java/org/onap/aaf/cadi/config/GetAccess.java | 2 +- .../java/org/onap/aaf/cadi/config/MultiGet.java | 4 +- .../org/onap/aaf/cadi/config/SecurityInfoC.java | 4 +- .../java/org/onap/aaf/cadi/config/UsersDump.java | 28 ++-- .../java/org/onap/aaf/cadi/filter/CadiFilter.java | 56 ++++---- .../org/onap/aaf/cadi/filter/CadiHTTPManip.java | 24 ++-- .../main/java/org/onap/aaf/cadi/filter/FCGet.java | 10 +- .../org/onap/aaf/cadi/lur/ConfigPrincipal.java | 4 +- .../main/java/org/onap/aaf/cadi/lur/EpiLur.java | 34 ++--- .../main/java/org/onap/aaf/cadi/lur/LocalLur.java | 4 +- .../onap/aaf/cadi/principal/BasicPrincipal.java | 10 +- .../aaf/cadi/principal/CachedBasicPrincipal.java | 2 +- .../java/org/onap/aaf/cadi/principal/Kind.java | 8 +- .../aaf/cadi/principal/OAuth2FormPrincipal.java | 2 +- .../onap/aaf/cadi/principal/TaggedPrincipal.java | 2 +- .../onap/aaf/cadi/principal/TrustPrincipal.java | 4 +- .../org/onap/aaf/cadi/principal/X509Principal.java | 10 +- .../main/java/org/onap/aaf/cadi/taf/EpiTaf.java | 6 +- .../java/org/onap/aaf/cadi/taf/HttpEpiTaf.java | 2 +- .../org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java | 32 ++--- .../java/org/onap/aaf/cadi/taf/cert/X509Taf.java | 52 +++---- .../onap/aaf/cadi/taf/dos/DenialOfServiceTaf.java | 76 +++++------ .../src/main/java/org/onap/aaf/cadi/util/FQI.java | 6 +- .../org/onap/aaf/cadi/util/JsonOutputStream.java | 10 +- .../main/java/org/onap/aaf/cadi/util/NetMask.java | 12 +- .../main/java/org/onap/aaf/cadi/util/Split.java | 24 ++-- .../org/onap/aaf/cadi/util/SubStandardConsole.java | 2 +- .../java/org/onap/aaf/cadi/util/TheConsole.java | 2 +- .../org/onap/aaf/cadi/util/UserChainManip.java | 18 +-- .../src/main/java/org/onap/aaf/cadi/util/Vars.java | 30 ++-- .../main/java/org/onap/aaf/cadi/wsse/Match.java | 20 +-- .../main/java/org/onap/aaf/cadi/wsse/XReader.java | 70 +++++----- 46 files changed, 586 insertions(+), 586 deletions(-) (limited to 'cadi/core/src/main') diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/AES.java b/cadi/core/src/main/java/org/onap/aaf/cadi/AES.java index 142dde26..c4f3d504 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/AES.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/AES.java @@ -100,7 +100,7 @@ public class AES implements Encryption { public CipherOutputStream outputStream(OutputStream os, boolean encrypt) { try { Cipher c = Cipher.getInstance(AES); - if(encrypt) { + if (encrypt) { c.init(Cipher.ENCRYPT_MODE,aeskeySpec); } else { c.init(Cipher.DECRYPT_MODE,aeskeySpec); @@ -116,7 +116,7 @@ public class AES implements Encryption { public CipherInputStream inputStream(InputStream is, boolean encrypt) { try { Cipher c = Cipher.getInstance(AES); - if(encrypt) { + if (encrypt) { c.init(Cipher.ENCRYPT_MODE,aeskeySpec); } else { c.init(Cipher.DECRYPT_MODE,aeskeySpec); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/AbsUserCache.java b/cadi/core/src/main/java/org/onap/aaf/cadi/AbsUserCache.java index d9d4474d..e6d24dab 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/AbsUserCache.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/AbsUserCache.java @@ -76,10 +76,10 @@ public abstract class AbsUserCache { userMap = new ConcurrentHashMap<>(); - if(cleanInterval>0) { + if (cleanInterval>0) { cleanInterval = Math.max(MIN_INTERVAL, cleanInterval); synchronized(AbsUserCache.class) { // Lazy instantiate.. in case there is no cleanup needed - if(timer==null) { + if (timer==null) { timer = new Timer("CADI Cleanup Timer",true); } @@ -96,14 +96,14 @@ public abstract class AbsUserCache { missEncrypt = cache.missEncrypt; synchronized(AbsUserCache.class) { - if(cache.clean!=null && cache.clean.lur==null && this instanceof CachingLur) { + if (cache.clean!=null && cache.clean.lur==null && this instanceof CachingLur) { cache.clean.lur=(CachingLur)this; } } } protected void setLur(CachingLur lur) { - if(clean!=null)clean.lur = lur; + if (clean!=null)clean.lur = lur; } @@ -111,11 +111,11 @@ public abstract class AbsUserCache { Principal p = user.principal; String key; try { - if(p instanceof GetCred) { + if (p instanceof GetCred) { key = missKey(p.getName(), ((GetCred)p).getCred()); } else { byte[] cred; - if((cred=user.getCred())==null) { + if ((cred=user.getCred())==null) { key = user.name + NO_CRED; } else { key = missKey(user.name,cred); @@ -152,7 +152,7 @@ public abstract class AbsUserCache { return false; } Miss miss = missMap.get(mkey); - if(miss==null) { + if (miss==null) { missMap.put(mkey, new Miss(bs,clean==null?MIN_INTERVAL:clean.timeInterval,key)); return true; } @@ -165,7 +165,7 @@ public abstract class AbsUserCache { protected User getUser(Principal principal) { String key; - if(principal instanceof GetCred) { + if (principal instanceof GetCred) { GetCred gc = (GetCred)principal; try { key = missKey(principal.getName(), gc.getCred()); @@ -177,7 +177,7 @@ public abstract class AbsUserCache { key = principal.getName()+NO_CRED; } User u = userMap.get(key); - if(u!=null) { + if (u!=null) { u.incCount(); } return u; @@ -197,8 +197,8 @@ public abstract class AbsUserCache { return null; } u = userMap.get(key); - if(u!=null) { - if(u.permExpired()) { + if (u!=null) { + if (u.permExpired()) { userMap.remove(key); u=null; } else { @@ -223,7 +223,7 @@ public abstract class AbsUserCache { */ public void remove(String user) { Object o = userMap.remove(user); - if(o!=null) { + if (o!=null) { access.log(Level.INFO, user,"removed from Client Cache by Request"); } } @@ -237,7 +237,7 @@ public abstract class AbsUserCache { public final List dumpInfo() { List rv = new ArrayList<>(); - for(User user : userMap.values()) { + for (User user : userMap.values()) { rv.add(new DumpInfo(user)); } return rv; @@ -256,7 +256,7 @@ public abstract class AbsUserCache { * If overloading in Derived class, be sure to call "super.destroy()" */ public void destroy() { - if(timer!=null) { + if (timer!=null) { timer.purge(); timer.cancel(); } @@ -318,13 +318,13 @@ public abstract class AbsUserCache { ArrayList> al = new ArrayList<>(userMap.values().size()); al.addAll(0, userMap.values()); long now = System.currentTimeMillis() + advance; - for(User user : al) { + for (User user : al) { ++total; - if(user.count>usageTriggerCount) { + if (user.count>usageTriggerCount) { boolean touched = false, removed=false; - if(user.principal instanceof CachedPrincipal) { + if (user.principal instanceof CachedPrincipal) { CachedPrincipal cp = (CachedPrincipal)user.principal; - if(cp.expires() < now) { + if (cp.expires() < now) { switch(cp.revalidate(null)) { case INACCESSIBLE: access.log(Level.AUDIT, "AAF Inaccessible. Keeping credentials"); @@ -343,20 +343,20 @@ public abstract class AbsUserCache { } } - if(!removed && lur!=null && user.permExpires<= now ) { - if(lur.reload(user).equals(Resp.REVALIDATED)) { + if (!removed && lur!=null && user.permExpires<= now ) { + if (lur.reload(user).equals(Resp.REVALIDATED)) { user.renewPerm(); access.log(Level.DEBUG, "Reloaded Perms for",user); touched = true; } } user.resetCount(); - if(touched) { + if (touched) { ++renewed; } } else { - if(user.permExpired()) { + if (user.permExpired()) { remove(user); ++count; } @@ -366,14 +366,14 @@ public abstract class AbsUserCache { // Clean out Misses int missTotal = missMap.keySet().size(); int miss = 0; - if(missTotal>0) { + if (missTotal>0) { ArrayList keys = new ArrayList<>(missTotal); keys.addAll(missMap.keySet()); - for(String key : keys) { + for (String key : keys) { Miss m = missMap.get(key); - if(m!=null) { + if (m!=null) { long timeLeft = m.timestamp - System.currentTimeMillis(); - if(timeLeft<0) { + if (timeLeft<0) { synchronized(missMap) { missMap.remove(key); } @@ -386,14 +386,14 @@ public abstract class AbsUserCache { } } - if(count+renewed+miss>0) { + if (count+renewed+miss>0) { access.log(Level.INFO, (lur==null?"Cache":lur.getClass().getSimpleName()), "removed",count, "and renewed",renewed,"expired Permissions out of", total,"and removed", miss, "password misses out of",missTotal); } // If High (total) is reached during this period, increase the number of expired services removed for next time. // There's no point doing it again here, as there should have been cleaned items. - if(total>high) { + if (total>high) { // advance cleanup by 10%, without getting greater than timeInterval. advance = Math.min(timeInterval, advance+(timeInterval/10)); } else { @@ -432,10 +432,10 @@ public abstract class AbsUserCache { public synchronized boolean mayContinue() { long ts = System.currentTimeMillis(); - if(ts>timestamp) { + if (ts>timestamp) { tries = 0; timestamp = ts + timetolive; - } else if(MAX_TRIES <= ++tries) { + } else if (MAX_TRIES <= ++tries) { return false; } return true; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java index 76d9bb2a..a673ab4f 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java @@ -57,7 +57,7 @@ public interface Access { } public int toggle(int mask) { - if(inMask(mask)) { + if (inMask(mask)) { return delFromMask(mask); } else { return addToMask(mask); @@ -67,8 +67,8 @@ public interface Access { public int maskOf() { int mask=0; - for(Level l : values()) { - if(ordinal()<=l.ordinal() && l!=NONE) { + for (Level l : values()) { + if (ordinal()<=l.ordinal() && l!=NONE) { mask|=l.bit; } } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/BufferedServletInputStream.java b/cadi/core/src/main/java/org/onap/aaf/cadi/BufferedServletInputStream.java index 3f47351b..8202183d 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/BufferedServletInputStream.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/BufferedServletInputStream.java @@ -63,19 +63,19 @@ public class BufferedServletInputStream extends ServletInputStream { public int read() throws IOException { int value=-1; - if(capacitor==null) { + if (capacitor==null) { value=is.read(); } else { switch(state) { case STORE: value = is.read(); - if(value>=0) { + if (value>=0) { capacitor.put((byte)value); } break; case READ: value = capacitor.read(); - if(value<0) { + if (value<0) { capacitor.done(); capacitor=null; // all done with buffer value = is.read(); @@ -92,27 +92,27 @@ public class BufferedServletInputStream extends ServletInputStream { public int read(byte[] b, int off, int len) throws IOException { int count = -1; - if(capacitor==null) { + if (capacitor==null) { count = is.read(b,off,len); } else { switch(state) { case STORE: count = is.read(b, off, len); - if(count>0) { + if (count>0) { capacitor.put(b, off, count); } break; case READ: count = capacitor.read(b, off, len); - if(count<=0) { + if (count<=0) { capacitor.done(); capacitor=null; // all done with buffer } - if(count0) { // watch for -1 + if (temp>0) { // watch for -1 count+=temp; - } else if(count<=0) { + } else if (count<=0) { count = temp; // must account for Stream coming back -1 } } @@ -124,7 +124,7 @@ public class BufferedServletInputStream extends ServletInputStream { public long skip(long n) throws IOException { long skipped = capacitor.skip(n); - if(skipped)lur).remove(id); } } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Capacitor.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Capacitor.java index 5ca1ce30..f3a2a7fa 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Capacitor.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Capacitor.java @@ -46,7 +46,7 @@ public class Capacitor { public void put(byte b) { - if(curr == null || curr.remaining()==0) { // ensure we have a "curr" buffer ready for data + if (curr == null || curr.remaining()==0) { // ensure we have a "curr" buffer ready for data curr = ringGet(); bbs.add(curr); } @@ -54,10 +54,10 @@ public class Capacitor { } public int read() { - if(curr!=null) { - if(curr.remaining()>0) { // have a buffer, use it! + if (curr!=null) { + if (curr.remaining()>0) { // have a buffer, use it! return curr.get(); - } else if(idx0) { // loop through while there's data needed - if((len=curr.remaining())>length) { // if enough data in curr buffer, use this code + while (length>0) { // loop through while there's data needed + if ((len=curr.remaining())>length) { // if enough data in curr buffer, use this code curr.get(array,offset,length); count+=length; length=0; @@ -87,7 +87,7 @@ public class Capacitor { count+=len; offset+=len; length-=len; - if(idx0) { - if((len=curr.remaining())>length) { + while (length>0) { + if ((len=curr.remaining())>length) { curr.put(array,offset,length); length=0; } else { @@ -130,10 +130,10 @@ public class Capacitor { * Move state from Storage mode into Read mode, changing all internal buffers to read mode, etc */ public void setForRead() { - for(ByteBuffer bb : bbs) { + for (ByteBuffer bb : bbs) { bb.flip(); } - if(bbs.isEmpty()) { + if (bbs.isEmpty()) { curr = null; idx = 0; } else { @@ -146,7 +146,7 @@ public class Capacitor { * reuse all the buffers */ public void done() { - for(ByteBuffer bb : bbs) { + for (ByteBuffer bb : bbs) { ringPut(bb); } bbs.clear(); @@ -160,7 +160,7 @@ public class Capacitor { */ public int available() { int count = 0; - for(ByteBuffer bb : bbs) { + for (ByteBuffer bb : bbs) { count+=bb.remaining(); } return count; @@ -174,11 +174,11 @@ public class Capacitor { public long skip(long n) { long skipped=0L; int skip; - if(curr==null) { + if (curr==null) { return 0; } - while(n>0) { - if(n<(skip=curr.remaining())) { + while (n>0) { + if (n<(skip=curr.remaining())) { curr.position(curr.position()+(int)n); skipped+=skip; n=0; @@ -186,7 +186,7 @@ public class Capacitor { curr.position(curr.limit()); skipped-=skip; - if(idx15)start=0; + if (bb!=null && ++start>15)start=0; } - if(bb==null) { + if (bb==null) { bb=ByteBuffer.allocate(DEFAULT_CHUNK); } else { bb.clear();// refresh reused buffer @@ -234,7 +234,7 @@ public class Capacitor { private void ringPut(ByteBuffer bb) { synchronized(ring) { ring[end]=bb; // if null or not, BB will just be Garbage collected - if(++end>15)end=0; + if (++end>15)end=0; } } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/CmdLine.java b/cadi/core/src/main/java/org/onap/aaf/cadi/CmdLine.java index 7ca9fac2..68a8db05 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/CmdLine.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/CmdLine.java @@ -48,18 +48,18 @@ public class CmdLine { * @param args */ public static void main(String[] args) { - if(args.length>0) { - if("digest".equalsIgnoreCase(args[0]) && (args.length>2 || (args.length>1 && System.console()!=null))) { + if (args.length>0) { + if ("digest".equalsIgnoreCase(args[0]) && (args.length>2 || (args.length>1 && System.console()!=null))) { String keyfile; String password; - if(args.length>2) { + if (args.length>2) { password = args[1]; keyfile = args[2]; - if("-i".equals(password)) { + if ("-i".equals(password)) { int c; StringBuilder sb = new StringBuilder(); try { - while((c=System.in.read())>=0) { + while ((c=System.in.read())>=0) { sb.append((char)c); } } catch (IOException e) { @@ -86,7 +86,7 @@ public class CmdLine { return; /* testing code... don't want it exposed System.out.println(" ******** Testing *********"); - for(int i=0;i<100000;++i) { + for (int i=0;i<100000;++i) { System.out.println(args[1]); ByteArrayOutputStream baos = new ByteArrayOutputStream(); b64.enpass(args[1], baos); @@ -96,7 +96,7 @@ public class CmdLine { b64.depass(pass, reconstituted); String r = reconstituted.toString(); System.out.println(r); - if(!r.equals(args[1])) { + if (!r.equals(args[1])) { System.err.println("!!!!! STOP - ERROR !!!!!"); return; } @@ -113,7 +113,7 @@ public class CmdLine { // Jonathan. Oh, well, Deployment services need this behavior. I will put this code in, but leave it undocumented. // One still needs access to the keyfile to read. // July 2016 - thought of a tool "CMPass" to regurgitate from properties, but only if allowed. - } else if("regurgitate".equalsIgnoreCase(args[0]) && args.length>2) { + } else if ("regurgitate".equalsIgnoreCase(args[0]) && args.length>2) { try { Symm symm; FileInputStream fis = new FileInputStream(args[2]); @@ -123,10 +123,10 @@ public class CmdLine { fis.close(); } boolean isFile = false; - if("-i".equals(args[1]) || (isFile="-f".equals(args[1]))) { + if ("-i".equals(args[1]) || (isFile="-f".equals(args[1]))) { BufferedReader br; - if(isFile) { - if(args.length<4) { + if (isFile) { + if (args.length<4) { System.err.println("Filename in 4th position"); return; } @@ -139,10 +139,10 @@ public class CmdLine { boolean cont = false; StringBuffer sb = new StringBuffer(); JsonOutputStream jw = new JsonOutputStream(System.out); - while((line=br.readLine())!=null) { - if(cont) { + while ((line=br.readLine())!=null) { + if (cont) { int end; - if((end=line.indexOf('"'))>=0) { + if ((end=line.indexOf('"'))>=0) { sb.append(line,0,end); cont=false; } else { @@ -150,34 +150,34 @@ public class CmdLine { } } else { int idx; - if((idx = line.indexOf(' '))>=0 + if ((idx = line.indexOf(' '))>=0 && (idx = line.indexOf(' ',++idx))>0 && (idx = line.indexOf('=',++idx))>0 ) { System.out.println(line.substring(0, idx-5)); int start = idx+2; int end; - if((end=line.indexOf('"',start))<0) { + if ((end=line.indexOf('"',start))<0) { end = line.length(); cont = true; } sb.append(line,start,end); } } - if(sb.length()>0) { + if (sb.length()>0) { symm.depass(sb.toString(),jw); - if(!cont) { + if (!cont) { System.out.println(); } } System.out.flush(); sb.setLength(0); - if(!cont) { + if (!cont) { jw.resetIndent(); } } } finally { - if(isFile) { + if (isFile) { br.close(); } } @@ -191,7 +191,7 @@ public class CmdLine { System.err.println("Cannot regurgitate password"); System.err.println(" \""+ e.getMessage() + '"'); } - } else if("encode64".equalsIgnoreCase(args[0]) && args.length>1) { + } else if ("encode64".equalsIgnoreCase(args[0]) && args.length>1) { try { Symm.base64.encode(args[1], System.out); System.out.println(); @@ -201,7 +201,7 @@ public class CmdLine { System.err.println("Cannot encode Base64 with " + args[1]); System.err.println(" \""+ e.getMessage() + '"'); } - } else if("decode64".equalsIgnoreCase(args[0]) && args.length>1) { + } else if ("decode64".equalsIgnoreCase(args[0]) && args.length>1) { try { Symm.base64.decode(args[1], System.out); System.out.println(); @@ -211,7 +211,7 @@ public class CmdLine { System.err.println("Cannot decode Base64 text from " + args[1]); System.err.println(" \""+ e.getMessage() + '"'); } - } else if("encode64url".equalsIgnoreCase(args[0]) && args.length>1) { + } else if ("encode64url".equalsIgnoreCase(args[0]) && args.length>1) { try { Symm.base64url.encode(args[1], System.out); System.out.println(); @@ -221,7 +221,7 @@ public class CmdLine { System.err.println("Cannot encode Base64url with " + args[1]); System.err.println(" \""+ e.getMessage() + '"'); } - } else if("decode64url".equalsIgnoreCase(args[0]) && args.length>1) { + } else if ("decode64url".equalsIgnoreCase(args[0]) && args.length>1) { try { Symm.base64url.decode(args[1], System.out); System.out.println(); @@ -231,7 +231,7 @@ public class CmdLine { System.err.println("Cannot decode Base64url text from " + args[1]); System.err.println(" \""+ e.getMessage() + '"'); } - } else if("md5".equalsIgnoreCase(args[0]) && args.length>1) { + } else if ("md5".equalsIgnoreCase(args[0]) && args.length>1) { try { System.out.println(Hash.hashMD5asStringHex(args[1])); System.out.flush(); @@ -240,11 +240,11 @@ public class CmdLine { System.err.println(" \""+ e.getMessage() + '"'); } return; - } else if("sha256".equalsIgnoreCase(args[0]) && args.length>1) { + } else if ("sha256".equalsIgnoreCase(args[0]) && args.length>1) { try { - if(args.length>2) { + if (args.length>2) { int max = args.length>7?7:args.length; - for(int i=2;i1) { + if (args.length>1) { File f = new File(args[1]); FileOutputStream fos = new FileOutputStream(f); try { @@ -280,13 +280,13 @@ public class CmdLine { System.err.println(" \""+ e.getMessage() + '"'); } - } else if("passgen".equalsIgnoreCase(args[0])) { + } else if ("passgen".equalsIgnoreCase(args[0])) { int numDigits; - if(args.length <= 1) { + if (args.length <= 1) { numDigits = 24; } else { numDigits = Integer.parseInt(args[1]); - if(numDigits<8)numDigits = 8; + if (numDigits<8)numDigits = 8; } String pass; boolean noLower,noUpper,noDigits,noSpecial,repeatingChars,missingChars; @@ -295,33 +295,33 @@ public class CmdLine { missingChars=noLower=noUpper=noDigits=noSpecial=true; repeatingChars=false; int c=-1,last; - for(int i=0;i=0x61 && c<=0x7A); } - if(noUpper) { + if (noUpper) { noUpper=!(c>=0x41 && c<=0x5A); } - if(noDigits) { + if (noDigits) { noDigits=!(c>=0x30 && c<=0x39); } - if(noSpecial) { + if (noSpecial) { noSpecial = "+!@#$%^&*(){}[]?:;,.".indexOf(c)<0; } missingChars = (noLower || noUpper || noDigits || noSpecial); } - } while(missingChars || repeatingChars); + } while (missingChars || repeatingChars); System.out.println(pass.substring(0,numDigits)); - } else if("urlgen".equalsIgnoreCase(args[0])) { + } else if ("urlgen".equalsIgnoreCase(args[0])) { int numDigits; - if(args.length <= 1) { + if (args.length <= 1) { numDigits = 24; } else { numDigits = Integer.parseInt(args[1]); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Hash.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Hash.java index acd45019..3027fd74 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Hash.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Hash.java @@ -132,9 +132,9 @@ public class Hash { * @return */ public static boolean isEqual(byte ba1[], byte ba2[]) { - if(ba1.length!=ba2.length)return false; - for(int i = 0;i=0x30 && c<=0x39) { + if (c>=0x30 && c<=0x39) { b=(byte)(c-0x30); - } else if(c>=0x61 && c<=0x66) { + } else if (c>=0x61 && c<=0x66) { b=(byte)(c-0x57); // account for "A" - } else if(c>=0x41 && c<=0x46) { + } else if (c>=0x41 && c<=0x46) { b=(byte)(c-0x37); } else { throw new CadiException("Invalid char '" + c + "' in HexString"); } idx = (i-2)/2; - if(high) { + if (high) { ba[idx]=(byte)(b<<4); high = false; } else { @@ -222,7 +222,7 @@ public class Hash { byte[] ba; boolean high; int start; - if(s.length()%2==0) { + if (s.length()%2==0) { ba = new byte[s.length()/2]; high=true; start=0; @@ -232,19 +232,19 @@ public class Hash { start=1; } int idx; - for(int i=start;i=0x30 && c<=0x39) { + if (c>=0x30 && c<=0x39) { b=(byte)(c-0x30); - } else if(c>=0x61 && c<=0x66) { + } else if (c>=0x61 && c<=0x66) { b=(byte)(c-0x57); // account for "A" - } else if(c>=0x41 && c<=0x46) { + } else if (c>=0x41 && c<=0x46) { b=(byte)(c-0x37); } else { return null; } idx = i/2; - if(high) { + if (high) { ba[idx]=(byte)(b<<4); high = false; } else { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java index a35777f8..8467c7c6 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java @@ -89,8 +89,8 @@ public class PropAccess implements Access { this.logIt = logIt; Properties nprops=new Properties(); int eq; - for(String arg : args) { - if((eq=arg.indexOf('='))>0) { + for (String arg : args) { + if ((eq=arg.indexOf('='))>0) { nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1)); } } @@ -104,16 +104,16 @@ public class PropAccess implements Access { props = new Properties(); // First, load related System Properties - for(Entry es : System.getProperties().entrySet()) { + for (Entry es : System.getProperties().entrySet()) { String key = es.getKey().toString(); - for(String start : new String[] {"cadi_","aaf_","cm_"}) { - if(key.startsWith(start)) { + for (String start : new String[] {"cadi_","aaf_","cm_"}) { + if (key.startsWith(start)) { props.put(key, es.getValue()); } } } // Second, overlay or fill in with Passed in Props - if(p!=null) { + if (p!=null) { props.putAll(p); } @@ -121,11 +121,11 @@ public class PropAccess implements Access { load(props.getProperty(Config.CADI_PROP_FILES)); String sLevel = props.getProperty(Config.CADI_LOGLEVEL); - if(sLevel!=null) { + if (sLevel!=null) { level=Level.valueOf(sLevel).maskOf(); } // Setup local Symmetrical key encryption - if(symm==null) { + if (symm==null) { try { symm = Symm.obtain(this); } catch (CadiException e) { @@ -142,18 +142,18 @@ public class PropAccess implements Access { private void specialConversions() { // Critical - if no Security Protocols set, then set it. We'll just get messed up if not - if(props.get(Config.CADI_PROTOCOLS)==null) { + if (props.get(Config.CADI_PROTOCOLS)==null) { props.setProperty(Config.CADI_PROTOCOLS, SecurityInfo.HTTPS_PROTOCOLS_DEFAULT); } Object temp; temp=props.get(Config.CADI_PROTOCOLS); - if(props.get(Config.HTTPS_PROTOCOLS)==null && temp!=null) { + if (props.get(Config.HTTPS_PROTOCOLS)==null && temp!=null) { props.put(Config.HTTPS_PROTOCOLS, temp); } - if(temp!=null) { - if("1.7".equals(System.getProperty("java.specification.version")) + if (temp!=null) { + if ("1.7".equals(System.getProperty("java.specification.version")) && (temp==null || (temp instanceof String && ((String)temp).contains("TLSv1.2")))) { System.setProperty(Config.HTTPS_CIPHER_SUITES, Config.HTTPS_CIPHER_SUITES_DEFAULT); } @@ -161,20 +161,20 @@ public class PropAccess implements Access { } private void load(String cadi_prop_files) { - if(cadi_prop_files==null) { + if (cadi_prop_files==null) { return; } String prevKeyFile = props.getProperty(Config.CADI_KEYFILE); int prev = 0, end = cadi_prop_files.length(); int idx; String filename; - while(prev(); recursionProtection.add(cadi_prop_files); } - if(!recursionProtection.contains(chainProp)) { + if (!recursionProtection.contains(chainProp)) { recursionProtection.add(chainProp); load(chainProp); // recurse } @@ -205,23 +205,23 @@ public class PropAccess implements Access { } // Trim - for(Entry es : props.entrySet()) { + for (Entry es : props.entrySet()) { Object value = es.getValue(); - if(value instanceof String) { + if (value instanceof String) { String trim = ((String)value).trim(); // Remove Beginning/End Quotes, which might be there if mixed with Bash Props int s = 0, e=trim.length()-1; - if(s0) { + if (l>0) { switch(s.charAt(l-1)) { case ' ': break; @@ -313,7 +313,7 @@ public class PropAccess implements Access { @Override public void printf(Level level, String fmt, Object... elements) { - if(willLog(level)) { + if (willLog(level)) { log(level,String.format(fmt, elements)); } } @@ -362,9 +362,9 @@ public class PropAccess implements Access { } public void setProperty(String tag, String value) { - if(value!=null) { + if (value!=null) { props.put(tag, value); - if(Config.CADI_KEYFILE.equals(tag)) { + if (Config.CADI_KEYFILE.equals(tag)) { // reset decryption too try { symm = Symm.obtain(this); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/ServletContextAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/ServletContextAccess.java index 518ea6dd..998b87c9 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/ServletContextAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/ServletContextAccess.java @@ -34,7 +34,7 @@ public class ServletContextAccess extends PropAccess { super(filterConfig); // protected constructor... does not have "init" called. context = filterConfig.getServletContext(); - for(Enumeration en = filterConfig.getInitParameterNames();en.hasMoreElements();) { + for (Enumeration en = filterConfig.getInitParameterNames();en.hasMoreElements();) { String name = (String)en.nextElement(); setProperty(name, filterConfig.getInitParameter(name)); } @@ -46,7 +46,7 @@ public class ServletContextAccess extends PropAccess { */ @Override public void log(Level level, Object... elements) { - if(willLog(level)) { + if (willLog(level)) { StringBuilder sb = buildMsg(level, elements); context.log(sb.toString()); } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java index fd60b0c1..28af03cd 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java @@ -139,12 +139,12 @@ public class Symm { // data (i.e. abcde...). Therefore, we'll quickly analyze the keyset. If it proves to have // too much entropy, the "Unordered" algorithm, which is faster in such cases is used. ArrayList la = new ArrayList<>(); - for(int i=0;icodeset.length/3) { + if (la.size()>codeset.length/3) { convert = new Unordered(codeset); } else { // too random to get speed enhancement from range algorithm int[][] range = new int[la.size()][]; @@ -210,10 +210,10 @@ public class Symm { public T exec(SyncExec exec) throws Exception { synchronized(LOCK) { - if(keyBytes == null) { + if (keyBytes == null) { keyBytes = new byte[AES.AES_KEY_SIZE/8]; int offset = (Math.abs(codeset[0])+47)%(codeset.length-keyBytes.length); - for(int i=0;i=0) { - if(line>=splitLinesAt) { + if (go = read>=0) { + if (line>=splitLinesAt) { os.write('\n'); line = 0; } @@ -362,7 +362,7 @@ public class Symm { // Char 1 is last 4 bits of prev plus the first 2 bits of read // Char 2 is the last 6 bits of read os.write(codeset[(((prev & 0xF)<<2) | (read>>6))]); - if(line==splitLinesAt) { // deal with line splitting for two characters + if (line==splitLinesAt) { // deal with line splitting for two characters os.write('\n'); line=0; } @@ -376,21 +376,21 @@ public class Symm { switch(idx) { case 1: // just the last 2 bits of prev os.write(codeset[(prev & 0x03)<<4]); - if(endEquals)os.write(DOUBLE_EQ); + if (endEquals)os.write(DOUBLE_EQ); break; case 2: // just the last 4 bits of prev os.write(codeset[(prev & 0xF)<<2]); - if(endEquals)os.write('='); + if (endEquals)os.write('='); break; } idx = 0; } - } while(go); + } while (go); } public void decode(InputStream is, OutputStream os, int skip) throws IOException { - if(is.skip(skip)!=skip) { + if (is.skip(skip)!=skip) { throw new IOException("Error skipping on IOStream in Symm"); } decode(is,os); @@ -405,9 +405,9 @@ public class Symm { public void decode(InputStream is, OutputStream os) throws IOException { int read, idx=0; int prev=0, index; - while((read = is.read())>=0) { + while ((read = is.read())>=0) { index = convert.convert(read); - if(index>=0) { + if (index>=0) { switch(++idx) { // 1 based cases, slightly faster ++ case 1: // index goes into first 6 bits of prev prev = index<<2; @@ -459,8 +459,8 @@ public class Symm { case '\r': return -1; } - for(int i=0;i= range[i][0] && read<=range[i][1]) { + for (int i=0;i= range[i][0] && read<=range[i][1]) { return read-range[i][2]; } } @@ -487,8 +487,8 @@ public class Symm { case '\r': return -1; } - for(int i=0;i=0) { + while (filled>=0) { index = o.next(); - if(index<0 || index>=codeset.length) { + if (index<0 || index>=codeset.length) { System.out.println("uh, oh"); } - if(right) { // alternate going left or right to find the next open slot (keeps it from taking too long to hit something) - for(int j=index;j=0;--j) { - if(seq[j]==0) { + for (int j=index;j>=0;--j) { + if (seq[j]==0) { seq[j]=codeset[filled]; --filled; break; @@ -859,7 +859,7 @@ public class Symm { try { newSymm.keyBytes = new byte[AES.AES_KEY_SIZE/8]; int offset = (Math.abs(key[(47%key.length)])+137)%(key.length-newSymm.keyBytes.length); - for(int i=0;i { } public void add(LocalPermission permission) { - if(perms==NULL_MAP) { + if (perms==NULL_MAP) { perms=newMap(); } perms.put(permission.getKey(),permission); @@ -157,8 +157,8 @@ public final class User { sb.append('|'); boolean first = true; synchronized(perms) { - for(Permission gp : perms.values()) { - if(first) { + for (Permission gp : perms.values()) { + if (first) { first = false; sb.append(':'); } else { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java index 4784d1ee..088227ed 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java @@ -233,9 +233,9 @@ public class Config { ///////////////////////////////////////////////////// Class aafConClass = loadClass(access,CADI_AAF_CON_DEF); Object aafcon = null; - if(con!=null && aafConClass!=null && aafConClass.isAssignableFrom(con.getClass())) { + if (con!=null && aafConClass!=null && aafConClass.isAssignableFrom(con.getClass())) { aafcon = con; - } else if(lur != null) { + } else if (lur != null) { Field f; try { f = lur.getClass().getField("aaf"); @@ -248,14 +248,14 @@ public class Config { boolean hasDirectAAF = hasDirect("DirectAAFLur",additionalTafLurs); // IMPORTANT! Don't attempt to load AAF Connector if there is no AAF URL String aafURL = access.getProperty(AAF_URL,null); - if(!hasDirectAAF && aafcon==null && aafURL!=null) { + if (!hasDirectAAF && aafcon==null && aafURL!=null) { aafcon = loadAAFConnector(si, aafURL); } HttpTaf taf; // Setup Host, in case Network reports an unusable Hostname (i.e. VTiers, VPNs, etc) String hostname = logProp(access, HOSTNAME,null); - if(hostname==null) { + if (hostname==null) { try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e1) { @@ -279,10 +279,10 @@ public class Config { ///////////////////////////////////////////////////// X509Taf x509TAF = null; String truststore = logProp(access, CADI_TRUSTSTORE,null); - if(truststore!=null) { + if (truststore!=null) { String truststorePwd = access.getProperty(CADI_TRUSTSTORE_PASSWORD,null); - if(truststorePwd!=null) { - if(truststorePwd.startsWith(Symm.ENC)) { + if (truststorePwd!=null) { + if (truststorePwd.startsWith(Symm.ENC)) { try { access.decrypt(truststorePwd,false); } catch (IOException e) { @@ -314,17 +314,17 @@ public class Config { long userExp = Long.parseLong(aafCleanup); boolean basicWarn = "TRUE".equals(access.getProperty(BASIC_WARN,"FALSE")); - if(!hasDirectAAF) { + if (!hasDirectAAF) { HttpTaf aaftaf=null; - if(!hasOAuthDirectTAF) { - if(basicRealm!=null) { + if (!hasOAuthDirectTAF) { + if (basicRealm!=null) { @SuppressWarnings("unchecked") Class obasicCls = (Class)loadClass(access,CADI_OBASIC_HTTP_TAF_DEF); - if(obasicCls!=null) { + if (obasicCls!=null) { try { String tokenurl = logProp(access,Config.AAF_OAUTH2_TOKEN_URL, null); String introspecturl = logProp(access,Config.AAF_OAUTH2_INTROSPECT_URL, null); - if(tokenurl==null || introspecturl==null) { + if (tokenurl==null || introspecturl==null) { access.log(Level.INIT,"Both tokenurl and introspecturl are required. Oauth Authorization is disabled."); } Constructor obasicConst = obasicCls.getConstructor(PropAccess.class,String.class, String.class, String.class); @@ -333,20 +333,20 @@ public class Config { } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { access.log(Level.INIT, e); } - } else if(up!=null) { + } else if (up!=null) { access.log(Level.INIT,"Basic Authorization is enabled using realm",basicRealm); // Allow warning about insecure channel to be turned off - if(!basicWarn) { + if (!basicWarn) { access.log(Level.INIT, "WARNING! The basicWarn property has been set to false.", " There will be no additional warning if Basic Auth is used on an insecure channel"); } BasicHttpTaf bht = new BasicHttpTaf(access, up, basicRealm, userExp, basicWarn); - for(Object o : additionalTafLurs) { - if(o instanceof CredValDomain) { + for (Object o : additionalTafLurs) { + if (o instanceof CredValDomain) { bht.add((CredValDomain)o); } } - if(x509TAF!=null) { + if (x509TAF!=null) { x509TAF.add(bht); } htlist.add(bht); @@ -359,28 +359,28 @@ public class Config { ///////////////////////////////////////////////////// // Configure AAF Driven Basic Auth ///////////////////////////////////////////////////// - if(aafcon==null) { + if (aafcon==null) { access.log(Level.INIT,"AAF Connection (AAFcon) is null. Cannot create an AAF TAF"); - } else if(aafURL==null) { + } else if (aafURL==null) { access.log(Level.INIT,"No AAF URL in properties, Cannot create an AAF TAF"); } else {// There's an AAF_URL... try to configure an AAF String aafTafClassName = logProp(access, AAF_TAF_CLASS,AAF_TAF_CLASS_DEF); // Only 2.0 available at this time - if(AAF_TAF_CLASS_DEF.equals(aafTafClassName)) { + if (AAF_TAF_CLASS_DEF.equals(aafTafClassName)) { try { Class aafTafClass = loadClass(access,aafTafClassName); - if(aafTafClass!=null) { + if (aafTafClass!=null) { Constructor cstr = aafTafClass.getConstructor(Connector.class,boolean.class,AbsUserCache.class); - if(cstr!=null) { - if(lur instanceof AbsUserCache) { + if (cstr!=null) { + if (lur instanceof AbsUserCache) { aaftaf = (HttpTaf)cstr.newInstance(aafcon,basicWarn,lur); } else { cstr = aafTafClass.getConstructor(Connector.class,boolean.class); - if(cstr!=null) { + if (cstr!=null) { aaftaf = (HttpTaf)cstr.newInstance(aafcon,basicWarn); } } - if(aaftaf==null) { + if (aaftaf==null) { access.log(Level.INIT,"ERROR! AAF TAF Failed construction. NOT Configured"); } else { access.log(Level.INIT,"AAF TAF Configured to ",aafURL); @@ -390,7 +390,7 @@ public class Config { } else { access.log(Level.INIT, "There is no AAF TAF class available: %s. AAF TAF not configured.",aafTafClassName); } - } catch(Exception e) { + } catch (Exception e) { access.log(Level.INIT,"ERROR! AAF TAF Failed construction. NOT Configured",e); } } @@ -400,7 +400,7 @@ public class Config { ///////////////////////////////////////////////////// // Configure OAuth TAF ///////////////////////////////////////////////////// - if(!hasOAuthDirectTAF) { + if (!hasOAuthDirectTAF) { String oauthTokenUrl = logProp(access,Config.AAF_OAUTH2_TOKEN_URL,null); Class oadtClss; try { @@ -409,21 +409,21 @@ public class Config { oadtClss = null; access.log(Level.INIT, e1); } - if(additionalTafLurs!=null && additionalTafLurs.length>0 && (oadtClss!=null && additionalTafLurs[0].getClass().isAssignableFrom(oadtClss))) { + if (additionalTafLurs!=null && additionalTafLurs.length>0 && (oadtClss!=null && additionalTafLurs[0].getClass().isAssignableFrom(oadtClss))) { htlist.add((HttpTaf)additionalTafLurs[0]); String[] array= new String[additionalTafLurs.length-1]; - if(array.length>0) { + if (array.length>0) { System.arraycopy(htlist, 1, array, 0, array.length); } additionalTafLurs = array; access.log(Level.INIT,"OAuth2 Direct is enabled"); - } else if(oauthTokenUrl!=null) { + } else if (oauthTokenUrl!=null) { String oauthIntrospectUrl = logProp(access,Config.AAF_OAUTH2_INTROSPECT_URL,null); @SuppressWarnings("unchecked") Class oaTCls = (Class)loadClass(access,OAUTH_HTTP_TAF); - if(oaTCls!=null) { + if (oaTCls!=null) { Class oaTTmgrCls = loadClass(access, OAUTH_TOKEN_MGR); - if(oaTTmgrCls!=null) { + if (oaTTmgrCls!=null) { try { Method oaTTmgrGI = oaTTmgrCls.getMethod("getInstance",PropAccess.class,String.class,String.class); Object oaTTmgr = oaTTmgrGI.invoke(null /*this is static method*/,access,oauthTokenUrl,oauthIntrospectUrl); @@ -444,7 +444,7 @@ public class Config { // Adding BasicAuth (AAF) last, after other primary Cookie Based // Needs to be before Cert... see below ///////////////////////////////////////////////////// - if(aaftaf!=null) { + if (aaftaf!=null) { htlist.add(aaftaf); } } @@ -452,22 +452,22 @@ public class Config { ///////////////////////////////////////////////////// // Any Additional Lurs passed in Constructor ///////////////////////////////////////////////////// - if(additionalTafLurs!=null) { - for(Object additional : additionalTafLurs) { - if(additional instanceof BasicHttpTaf) { + if (additionalTafLurs!=null) { + for (Object additional : additionalTafLurs) { + if (additional instanceof BasicHttpTaf) { BasicHttpTaf ht = (BasicHttpTaf)additional; - for(Object cv : additionalTafLurs) { - if(cv instanceof CredValDomain) { + for (Object cv : additionalTafLurs) { + if (cv instanceof CredValDomain) { ht.add((CredValDomain)cv); access.printf(Level.INIT,"%s Authentication is enabled",cv); } } htlist.add(ht); - } else if(additional instanceof HttpTaf) { + } else if (additional instanceof HttpTaf) { HttpTaf ht = (HttpTaf)additional; htlist.add(ht); access.printf(Level.INIT,"%s Authentication is enabled",additional.getClass().getSimpleName()); - } else if(hasOAuthDirectTAF) { + } else if (hasOAuthDirectTAF) { Class daupCls; try { daupCls = Class.forName("org.onap.aaf.auth.direct.DirectAAFUserPass"); @@ -475,7 +475,7 @@ public class Config { daupCls = null; access.log(Level.INIT, e); } - if(daupCls != null && additional.getClass().isAssignableFrom(daupCls)) { + if (daupCls != null && additional.getClass().isAssignableFrom(daupCls)) { htlist.add(new BasicHttpTaf(access, (CredVal)additional , basicRealm, userExp, basicWarn)); access.printf(Level.INIT,"Direct BasicAuth Authentication is enabled",additional.getClass().getSimpleName()); } @@ -484,9 +484,9 @@ public class Config { } // Add BasicAuth, if any, to x509Taf - if(x509TAF!=null) { - for( HttpTaf ht : htlist) { - if(ht instanceof BasicHttpTaf) { + if (x509TAF!=null) { + for ( HttpTaf ht : htlist) { + if (ht instanceof BasicHttpTaf) { x509TAF.add((BasicHttpTaf)ht); } } @@ -494,7 +494,7 @@ public class Config { ///////////////////////////////////////////////////// // Create EpiTaf from configured TAFs ///////////////////////////////////////////////////// - if(htlist.size()==1) { + if (htlist.size()==1) { // just return the one taf = htlist.get(0); } else { @@ -504,7 +504,7 @@ public class Config { taf = new HttpEpiTaf(access,locator, tc, htarray); // ok to pass locator == null String level = logProp(access, CADI_LOGLEVEL, null); - if(level!=null) { + if (level!=null) { access.setLogLevel(Level.valueOf(level)); } } @@ -514,7 +514,7 @@ public class Config { public static String logProp(Access access,String tag, String def) { String rv = access.getProperty(tag, def); - if(rv == null) { + if (rv == null) { access.log(Level.INIT,tag,"is not explicitly set"); } else { access.log(Level.INIT,tag,"is set to",rv); @@ -533,14 +533,14 @@ public class Config { String users = access.getProperty(USERS,null); String groups = access.getProperty(GROUPS,null); - if(groups!=null || users!=null) { + if (groups!=null || users!=null) { LocalLur ll = new LocalLur(access, users, groups); // note b64==null is ok.. just means no encryption. lurs.add(ll); String writeto = access.getProperty(WRITE_TO,null); - if(writeto!=null) { + if (writeto!=null) { String msg = UsersDump.updateUsers(writeto, ll); - if(msg!=null) { + if (msg!=null) { access.log(Level.INIT,"ERROR! Error Updating ",writeto,"with roles and users:",msg); } } @@ -554,10 +554,10 @@ public class Config { ///////////////////////////////////////////////////// String tokenUrl = logProp(access,AAF_OAUTH2_TOKEN_URL, null); String introspectUrl = logProp(access,AAF_OAUTH2_INTROSPECT_URL, null); - if(tokenUrl!=null && introspectUrl !=null) { + if (tokenUrl!=null && introspectUrl !=null) { try { Class olurCls = loadClass(access, CADI_OLUR_CLASS_DEF); - if(olurCls!=null) { + if (olurCls!=null) { Constructor olurCnst = olurCls.getConstructor(PropAccess.class,String.class,String.class); Lur olur = (Lur)olurCnst.newInstance(access,tokenUrl,introspectUrl); lurs.add(olur); @@ -567,7 +567,7 @@ public class Config { } } catch (NoSuchMethodException| SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { String msg = e.getMessage(); - if(msg==null && e.getCause()!=null) { + if (msg==null && e.getCause()!=null) { msg = e.getCause().getMessage(); } access.log(Level.INIT,"AAF/OAuth LUR is not instantiated.",msg,e); @@ -576,7 +576,7 @@ public class Config { access.log(Level.INIT, "OAuth2 Lur disabled"); } - if(con!=null) { // try to reutilize connector + if (con!=null) { // try to reutilize connector lurs.add(con.newLur()); } else { ///////////////////////////////////////////////////// @@ -584,12 +584,12 @@ public class Config { ///////////////////////////////////////////////////// String aafURL = logProp(access,AAF_URL,null); // Trigger Property String aafEnv = access.getProperty(AAF_ENV,null); - if(aafEnv == null && aafURL!=null && access instanceof PropAccess) { // set AAF_ENV from AAF_URL + if (aafEnv == null && aafURL!=null && access instanceof PropAccess) { // set AAF_ENV from AAF_URL int ec = aafURL.indexOf("envContext="); - if(ec>0) { + if (ec>0) { ec += 11; // length of envContext= int slash = aafURL.indexOf('/', ec); - if(slash>0) { + if (slash>0) { aafEnv = aafURL.substring(ec, slash); ((PropAccess)access).setProperty(AAF_ENV, aafEnv); access.printf(Level.INIT, "Setting aafEnv to %s from aaf_url value",aafEnv); @@ -598,30 +598,30 @@ public class Config { } // Don't configure AAF if it is using DirectAccess - if(!hasDirect("DirectAAFLur",additionalTafLurs)) { - if(aafURL==null) { + if (!hasDirect("DirectAAFLur",additionalTafLurs)) { + if (aafURL==null) { access.log(Level.INIT,"No AAF LUR properties, AAF will not be loaded"); } else {// There's an AAF_URL... try to configure an AAF String aafLurClassStr = logProp(access,AAF_LUR_CLASS,AAF_V2_0_AAF_LUR_PERM); ////////////AAF Lur 2.0 ///////////// - if(aafLurClassStr!=null && aafLurClassStr.startsWith(AAF_V2_0)) { + if (aafLurClassStr!=null && aafLurClassStr.startsWith(AAF_V2_0)) { try { Object aafcon = loadAAFConnector(si, aafURL); - if(aafcon==null) { + if (aafcon==null) { access.log(Level.INIT,"AAF LUR class,",aafLurClassStr,"cannot be constructed without valid AAFCon object."); } else { Class aafAbsAAFCon = loadClass(access, AAF_V2_0_AAFCON); - if(aafAbsAAFCon!=null) { + if (aafAbsAAFCon!=null) { Method mNewLur = aafAbsAAFCon.getMethod("newLur"); Object aaflur = mNewLur.invoke(aafcon); - if(aaflur==null) { + if (aaflur==null) { access.log(Level.INIT,"ERROR! AAF LUR Failed construction. NOT Configured"); } else { access.log(Level.INIT,"AAF LUR Configured to ",aafURL); lurs.add((Lur)aaflur); String debugIDs = logProp(access,Config.AAF_DEBUG_IDS, null); - if(debugIDs !=null && aaflur instanceof CachingLur) { + if (debugIDs !=null && aaflur instanceof CachingLur) { ((CachingLur)aaflur).setDebug(debugIDs); } } @@ -638,9 +638,9 @@ public class Config { ///////////////////////////////////////////////////// // Any Additional passed in Constructor ///////////////////////////////////////////////////// - if(additionalTafLurs!=null) { - for(Object additional : additionalTafLurs) { - if(additional instanceof Lur) { + if (additionalTafLurs!=null) { + for (Object additional : additionalTafLurs) { + if (additional instanceof Lur) { lurs.add((Lur)additional); access.log(Level.INIT, additional); } @@ -666,9 +666,9 @@ public class Config { } private static boolean hasDirect(String simpleClassName, Object[] additionalTafLurs) { - if(additionalTafLurs!=null) { - for(Object tf : additionalTafLurs) { - if(tf.getClass().getSimpleName().equals(simpleClassName)) { + if (additionalTafLurs!=null) { + for (Object tf : additionalTafLurs) { + if (tf.getClass().getSimpleName().equals(simpleClassName)) { return true; } } @@ -746,15 +746,15 @@ public class Config { public static Locator loadLocator(SecurityInfoC si, final String _url) throws LocatorException { Access access = si.access; Locator locator = null; - if(_url==null) { + if (_url==null) { access.log(Level.INIT,"No URL passed to 'loadLocator'. Disabled"); } else { String url = _url; String replacement; int idxAAFLocateUrl; - if((idxAAFLocateUrl=_url.indexOf(AAF_LOCATE_URL_TAG))>0 && ((replacement=access.getProperty(AAF_LOCATE_URL, null))!=null)) { + if ((idxAAFLocateUrl=_url.indexOf(AAF_LOCATE_URL_TAG))>0 && ((replacement=access.getProperty(AAF_LOCATE_URL, null))!=null)) { StringBuilder sb = new StringBuilder(replacement); - if(!replacement.endsWith("/locate")) { + if (!replacement.endsWith("/locate")) { sb.append("/locate"); } sb.append(_url,idxAAFLocateUrl+AAF_LOCATE_URL_TAG.length(),_url.length()); @@ -763,7 +763,7 @@ public class Config { try { Class lcls = loadClass(access,AAF_LOCATOR_CLASS_DEF); - if(lcls==null) { + if (lcls==null) { throw new CadiException("Need to include aaf-cadi-aaf jar for AAFLocator"); } // First check for preloaded @@ -773,7 +773,7 @@ public class Config { } catch (Exception e) { access.log(Level.INIT, e); } - if(locator==null) { + if (locator==null) { URI locatorURI = new URI(url); Constructor cnst = lcls.getConstructor(SecurityInfoC.class,URI.class); locator = (Locator)cnst.newInstance(new Object[] {si,locatorURI}); @@ -785,7 +785,7 @@ public class Config { access.log(Level.INFO, "AAFLocator enabled using preloaded " + locator.getClass().getSimpleName()); } } catch (InvocationTargetException e) { - if(e.getTargetException() instanceof LocatorException) { + if (e.getTargetException() instanceof LocatorException) { throw (LocatorException)e.getTargetException(); } access.log(Level.INIT,e.getTargetException().getMessage(),"AAFLocator for",url,"could not be created.",e); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Get.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Get.java index 56ac4dd5..b48dd74d 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Get.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Get.java @@ -59,7 +59,7 @@ public interface Get { } // Take def if nothing else - if(str==null) { + if (str==null) { str = def; // don't log defaults } else { @@ -83,8 +83,8 @@ public interface Get { } public String get(String name, String def, boolean print) { String gotten = access.getProperty(name, def); - if(print) { - if(gotten == null) { + if (print) { + if (gotten == null) { access.log(Level.INIT,name, "is not set"); } else { access.log(Level.INIT,name, "is set to", gotten); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/GetAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/GetAccess.java index 4655dfa1..30adcc97 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/GetAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/GetAccess.java @@ -38,7 +38,7 @@ public class GetAccess extends PropAccess { public String getProperty(String tag, String def) { String rv; rv = super.getProperty(tag, null); - if(rv==null && getter!=null) { + if (rv==null && getter!=null) { rv = getter.get(tag, null, true); } return rv==null?def:rv; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/MultiGet.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/MultiGet.java index a73df14e..c5e5a50e 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/MultiGet.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/MultiGet.java @@ -31,9 +31,9 @@ public class MultiGet implements Get { @Override public String get(String name, String def, boolean print) { String str; - for(Get getter : getters) { + for (Get getter : getters) { str = getter.get(name, null, print); - if(str!=null) + if (str!=null) return str; } return def; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java index 45e1dd1c..4e365fba 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/SecurityInfoC.java @@ -44,7 +44,7 @@ public class SecurityInfoC extends SecurityInfo { @SuppressWarnings("unchecked") public static synchronized SecurityInfoC instance(Access access, Class cls) throws CadiException { SecurityInfoInit sii; - if(cls.isAssignableFrom(HttpURLConnection.class)) { + if (cls.isAssignableFrom(HttpURLConnection.class)) { try { @SuppressWarnings("rawtypes") Class initCls = (Class)Class.forName("org.onap.aaf.cadi.http.HSecurityInfoInit"); @@ -62,7 +62,7 @@ public class SecurityInfoC extends SecurityInfo { } SecurityInfoC sic = (SecurityInfoC) sicMap.get(cls); - if(sic==null) { + if (sic==null) { sic = new SecurityInfoC(access); sic.set(sii.bestDefault(sic)); sicMap.put(cls, sic); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java index de25cb7f..98ab4706 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/UsersDump.java @@ -41,7 +41,7 @@ public class UsersDump { */ public static boolean write(OutputStream os, AbsUserCache lur) { PrintStream ps; - if(os instanceof PrintStream) { + if (os instanceof PrintStream) { ps = (PrintStream)os; } else { ps = new PrintStream(os); @@ -59,14 +59,14 @@ public class UsersDump { // Obtain all unique role names HashSet groups = new HashSet<>(); - for(AbsUserCache.DumpInfo di : lur.dumpInfo()) { + for (AbsUserCache.DumpInfo di : lur.dumpInfo()) { sb.append("\n "); @@ -104,15 +104,15 @@ public class UsersDump { */ public static String updateUsers(String writeto, LocalLur up) { // Dump a Tomcat-user.xml lookalike (anywhere) - if(writeto!=null) { + if (writeto!=null) { // First read content ByteArrayOutputStream baos = new ByteArrayOutputStream(); - if(UsersDump.write(baos, up)) { + if (UsersDump.write(baos, up)) { byte[] postulate = baos.toByteArray(); // now get contents of file File file = new File(writeto); boolean writeIt; - if(file.exists()) { + if (file.exists()) { try { FileInputStream fis = new FileInputStream(file); byte[] orig = new byte[(int)file.length()]; @@ -122,17 +122,17 @@ public class UsersDump { } finally { fis.close(); } - if(read<=0) { + if (read<=0) { writeIt = false; } else { // Starting at third "<" ( line) int startA=0, startB=0; - for(int i=0;startA ctc = (Class) Class.forName("org.onap.aaf.cadi.aaf.v2_0.AAFTrustChecker"); - if(ctc!=null) { + if (ctc!=null) { Constructor contc = ctc.getConstructor(Access.class); - if(contc!=null) { + if (contc!=null) { tc = contc.newInstance(access); } } @@ -184,8 +184,8 @@ public class CadiFilter implements Filter { // In this case, the epiTaf will be changed to a non-NullTaf, and thus not instantiate twice. synchronized(CadiHTTPManip.noAdditional /*will always remain same Object*/) { ++count; - if(httpChecker == null) { - if(access==null) { + if (httpChecker == null) { + if (access==null) { access = new PropAccess(); } try { @@ -193,16 +193,16 @@ public class CadiFilter implements Filter { } catch (CadiException | LocatorException e1) { throw new ServletException(e1); } - } else if(access==null) { + } else if (access==null) { access= httpChecker.getAccess(); } /* * Setup Authn Path Exceptions */ - if(pathExceptions==null) { + if (pathExceptions==null) { String str = getter.get(Config.CADI_NOAUTHN, null, true); - if(str!=null) { + if (str!=null) { pathExceptions = str.split("\\s*:\\s*"); } } @@ -210,22 +210,22 @@ public class CadiFilter implements Filter { /* * SETUP Permission Converters... those that can take Strings from a Vendor Product, and convert to appropriate AAF Permissions */ - if(mapPairs==null) { + if (mapPairs==null) { String str = getter.get(Config.AAF_PERM_MAP, null, true); - if(str!=null) { + if (str!=null) { String mstr = getter.get(Config.AAF_PERM_MAP, null, true); - if(mstr!=null) { + if (mstr!=null) { String map[] = mstr.split("\\s*:\\s*"); - if(map.length>0) { + if (map.length>0) { MapPermConverter mpc=null; int idx; mapPairs = new ArrayList<>(); - for(String entry : map) { - if((idx=entry.indexOf('='))<0) { // it's a Path, so create a new converter + for (String entry : map) { + if ((idx=entry.indexOf('='))<0) { // it's a Path, so create a new converter access.log(Level.INIT,"Loading Perm Conversions for:",entry); mapPairs.add(new Pair(entry,mpc=new MapPermConverter())); } else { - if(mpc!=null) { + if (mpc!=null) { mpc.map().put(entry.substring(0,idx),entry.substring(idx+1)); } else { access.log(Level.ERROR,"cadi_perm_map is malformed; ",entry, "is skipped"); @@ -248,7 +248,7 @@ public class CadiFilter implements Filter { public void destroy() { // Synchronize, in case multiCadiFilters are used. synchronized(CadiHTTPManip.noAdditional) { - if(--count<=0 && httpChecker!=null) { + if (--count<=0 && httpChecker!=null) { httpChecker.destroy(); httpChecker=null; access=null; @@ -272,7 +272,7 @@ public class CadiFilter implements Filter { String tag = ""; try { HttpServletRequest hreq = (HttpServletRequest)request; - if(noAuthn(hreq)) { + if (noAuthn(hreq)) { startCode=System.nanoTime(); chain.doFilter(request, response); code = Timing.millis(startCode); @@ -281,11 +281,11 @@ public class CadiFilter implements Filter { startValidate=System.nanoTime(); TafResp tresp = httpChecker.validate(hreq, hresp, hreq); validate = Timing.millis(startValidate); - if(tresp.isAuthenticated()==RESP.IS_AUTHENTICATED) { + if (tresp.isAuthenticated()==RESP.IS_AUTHENTICATED) { user = tresp.getPrincipal().personalName(); tag = tresp.getPrincipal().tag(); CadiWrap cw = new CadiWrap(hreq, tresp, httpChecker.getLur(),getConverter(hreq)); - if(httpChecker.notCadi(cw, hresp)) { + if (httpChecker.notCadi(cw, hresp)) { startCode=System.nanoTime(); oauthFilter.doFilter(cw,response,chain); code = Timing.millis(startCode); @@ -308,11 +308,11 @@ public class CadiFilter implements Filter { * @return */ private boolean noAuthn(HttpServletRequest hreq) { - if(pathExceptions!=null) { + if (pathExceptions!=null) { String pi = hreq.getPathInfo(); - if(pi==null) return false; // JBoss sometimes leaves null - for(String pe : pathExceptions) { - if(pi.startsWith(pe))return true; + if (pi==null) return false; // JBoss sometimes leaves null + for (String pe : pathExceptions) { + if (pi.startsWith(pe))return true; } } return false; @@ -322,11 +322,11 @@ public class CadiFilter implements Filter { * Get Converter by Path */ private PermConverter getConverter(HttpServletRequest hreq) { - if(mapPairs!=null) { + if (mapPairs!=null) { String pi = hreq.getPathInfo(); - if(pi !=null) { - for(Pair p: mapPairs) { - if(pi.startsWith(p.name))return p.pc; + if (pi !=null) { + for (Pair p: mapPairs) { + if (pi.startsWith(p.name))return p.pc; } } } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java b/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java index 3c0f139b..bab758ec 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/filter/CadiHTTPManip.java @@ -78,18 +78,18 @@ public class CadiHTTPManip { Config.setDefaultRealm(access); aaf_id = access.getProperty(Config.CADI_ALIAS,access.getProperty(Config.AAF_APPID, null)); - if(aaf_id==null) { + if (aaf_id==null) { access.printf(Level.INIT, "%s is not set. %s can be used instead",Config.AAF_APPID,Config.CADI_ALIAS); } else { access.printf(Level.INIT, "%s is set to %s",Config.AAF_APPID,aaf_id); } String ns = aaf_id==null?null:UserChainManip.idToNS(aaf_id); - if(ns!=null) { + if (ns!=null) { thisPerm = ns+ACCESS_CADI_CONTROL; int dot = ns.indexOf('.'); - if(dot>=0) { + if (dot>=0) { int dot2=ns.indexOf('.',dot+1); - if(dot2<0) { + if (dot2<0) { dot2=dot; } companyPerm = ns.substring(0, dot2)+ACCESS_CADI_CONTROL; @@ -105,9 +105,9 @@ public class CadiHTTPManip { lur = Config.configLur(si, con, additionalTafLurs); tc.setLur(lur); - if(lur instanceof EpiLur) { + if (lur instanceof EpiLur) { up = ((EpiLur)lur).getUserPassImpl(); - } else if(lur instanceof CredVal) { + } else if (lur instanceof CredVal) { up = (CredVal)lur; } else { up = null; @@ -160,20 +160,20 @@ public class CadiHTTPManip { public boolean notCadi(CadiWrap req, HttpServletResponse resp) { String pathInfo = req.getPathInfo(); - if(METH.equalsIgnoreCase(req.getMethod()) && pathInfo!=null && pathInfo.contains(CADI)) { - if(req.getUser().equals(aaf_id) || req.isUserInRole(thisPerm) || req.isUserInRole(companyPerm)) { + if (METH.equalsIgnoreCase(req.getMethod()) && pathInfo!=null && pathInfo.contains(CADI)) { + if (req.getUser().equals(aaf_id) || req.isUserInRole(thisPerm) || req.isUserInRole(companyPerm)) { try { - if(pathInfo.contains(CADI_CACHE_PRINT)) { + if (pathInfo.contains(CADI_CACHE_PRINT)) { resp.getOutputStream().println(lur.toString()); resp.setStatus(200); return false; - } else if(pathInfo.contains(CADI_CACHE_CLEAR)) { + } else if (pathInfo.contains(CADI_CACHE_CLEAR)) { StringBuilder report = new StringBuilder(); lur.clear(req.getUserPrincipal(), report); resp.getOutputStream().println(report.toString()); resp.setStatus(200); return false; - } else if(pathInfo.contains(CADI_LOG_SET)) { + } else if (pathInfo.contains(CADI_LOG_SET)) { Level l; int slash = pathInfo.lastIndexOf('/'); String level = pathInfo.substring(slash+1); @@ -200,7 +200,7 @@ public class CadiHTTPManip { public void destroy() { access.log(Level.INFO,"CadiHttpChecker destroyed."); - if(lur!=null) { + if (lur!=null) { lur.destroy(); lur=null; } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/filter/FCGet.java b/cadi/core/src/main/java/org/onap/aaf/cadi/filter/FCGet.java index f56cbf27..cf7c922d 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/filter/FCGet.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/filter/FCGet.java @@ -49,25 +49,25 @@ class FCGet implements Get { public String get(String name, String def, boolean print) { String str = null; // Try Server Context First - if(context!=null) { + if (context!=null) { str = context.getInitParameter(name); } // Try Filter Context next - if(str==null && filterConfig != null) { + if (str==null && filterConfig != null) { str = filterConfig.getInitParameter(name); } - if(str==null) { + if (str==null) { str = access.getProperty(name, def); } // Take def if nothing else - if(str==null) { + if (str==null) { str = def; // don't log defaults } else { str = str.trim(); // this is vital in Property File based values, as spaces can hide easily - if(print) { + if (print) { access.log(Level.INFO,"Setting", name, "to", str); } } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/lur/ConfigPrincipal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/lur/ConfigPrincipal.java index c1b477b1..a41c5eb7 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/lur/ConfigPrincipal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/lur/ConfigPrincipal.java @@ -57,10 +57,10 @@ public class ConfigPrincipal implements Principal, GetCred { } public String getAsBasicAuthHeader() throws IOException { - if(content ==null) { + if (content ==null) { String s = name + ':' + new String(cred); content = "Basic " + Symm.base64.encode(s); - } else if(!content.startsWith("Basic ")) { // content is the saved password from construction + } else if (!content.startsWith("Basic ")) { // content is the saved password from construction String s = name + ':' + content; content = "Basic " + Symm.base64.encode(s); } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/lur/EpiLur.java b/cadi/core/src/main/java/org/onap/aaf/cadi/lur/EpiLur.java index 2c5e1957..5443dec2 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/lur/EpiLur.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/lur/EpiLur.java @@ -57,30 +57,30 @@ public final class EpiLur implements Lur { */ public EpiLur(Lur ... lurs) throws CadiException{ this.lurs = lurs; - if(lurs.length==0) throw new CadiException("Need at least one Lur implementation in constructor"); + if (lurs.length==0) throw new CadiException("Need at least one Lur implementation in constructor"); } public boolean fish(Principal bait, Permission ... pond) { - if(pond==null) { + if (pond==null) { return false; } boolean rv = false; Lur lur; - for(int i=0;!rv && i permissions) { - for(Lur lur : lurs) { + for (Lur lur : lurs) { lur.fishAll(bait, permissions); } } public void destroy() { - for(Lur lur : lurs) { + for (Lur lur : lurs) { lur.destroy(); } } @@ -90,8 +90,8 @@ public final class EpiLur implements Lur { * @return */ public CredVal getUserPassImpl() { - for(Lur lur : lurs) { - if(lur instanceof CredVal) { + for (Lur lur : lurs) { + if (lur instanceof CredVal) { return (CredVal)lur; } } @@ -109,15 +109,15 @@ public final class EpiLur implements Lur { * @return */ public Lur get(int idx) { - if(idx>=0 && idx=0 && idx)l).remove(id); } } } public Lur subLur(Class cls ) { - for(Lur l : lurs) { - if(l.getClass().isAssignableFrom(cls)) { + for (Lur l : lurs) { + if (l.getClass().isAssignableFrom(cls)) { return l; } } @@ -151,14 +151,14 @@ public final class EpiLur implements Lur { */ @Override public void clear(Principal p, StringBuilder report) { - for(Lur lur : lurs) { + for (Lur lur : lurs) { lur.clear(p, report); } } public String toString() { StringBuilder sb = new StringBuilder(); - for(Lur lur : lurs) { + for (Lur lur : lurs) { sb.append(lur.getClass().getSimpleName()); sb.append(": Report\n"); sb.append(lur.toString()); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/lur/LocalLur.java b/cadi/core/src/main/java/org/onap/aaf/cadi/lur/LocalLur.java index d2b6f1aa..f8fa02e5 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/lur/LocalLur.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/lur/LocalLur.java @@ -98,7 +98,7 @@ public final class LocalLur extends AbsUserCache implements Lur if (pond == null) { return false; } - for(Permission p : pond) { + for (Permission p : pond) { if (handles(bait) && p instanceof LocalPermission) { // local Users only have LocalPermissions User user = getUser(bait); if (user != null) { @@ -134,7 +134,7 @@ public final class LocalLur extends AbsUserCache implements Lur public boolean handlesExclusively(Permission ... pond) { boolean rv = false; for (Permission p : pond) { - if(rv=supportingGroups.contains(p.getKey())) { + if (rv=supportingGroups.contains(p.getKey())) { break; } } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java index d3c1e236..746e67d8 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/BasicPrincipal.java @@ -45,8 +45,8 @@ public class BasicPrincipal extends BearerPrincipal implements GetCred { created = System.currentTimeMillis(); ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes()); // Read past "Basic ", ensuring it starts with it. - for(int i=0;i0) { + if ((at=name.indexOf('@'))>0) { domain=name.substring(at+1); shortName=name.substring(0, at); } else { @@ -83,7 +83,7 @@ public class BasicPrincipal extends BearerPrincipal implements GetCred { @Override public void write(int b) throws IOException { - if(b==':' && first) { + if (b==':' && first) { first = false; name = new String(baos.toByteArray()); baos.reset(); // diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java index f81e160d..4a6e4cda 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/CachedBasicPrincipal.java @@ -54,7 +54,7 @@ public class CachedBasicPrincipal extends BasicPrincipal implements CachedPrinci public CachedPrincipal.Resp revalidate(Object state) { Resp resp = creator.revalidate(this, state); - if(resp.equals(Resp.REVALIDATED))expires = System.currentTimeMillis()+timeToLive; + if (resp.equals(Resp.REVALIDATED))expires = System.currentTimeMillis()+timeToLive; return resp; } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/Kind.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/Kind.java index 8c75701f..20f22846 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/Kind.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/Kind.java @@ -33,19 +33,19 @@ public class Kind { public static char getKind(final Principal principal) { Principal check; - if(principal instanceof TrustPrincipal) { + if (principal instanceof TrustPrincipal) { check = ((TrustPrincipal)principal).original(); } else { check = principal; } - if(check instanceof X509Principal) { + if (check instanceof X509Principal) { return X509; } - if(check instanceof OAuth2FormPrincipal) { + if (check instanceof OAuth2FormPrincipal) { // Note: if AAF, will turn into 'A' return OAUTH; } - if(check instanceof BasicPrincipal) { + if (check instanceof BasicPrincipal) { return BASIC_AUTH; } return UNKNOWN; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/OAuth2FormPrincipal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/OAuth2FormPrincipal.java index 4d13de87..01326054 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/OAuth2FormPrincipal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/OAuth2FormPrincipal.java @@ -49,7 +49,7 @@ public class OAuth2FormPrincipal extends TaggedPrincipal { @Override public String personalName() { - if(username!=null && username!=client_id) { + if (username!=null && username!=client_id) { StringBuilder sb = new StringBuilder(); sb.append(username); sb.append('|'); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TaggedPrincipal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TaggedPrincipal.java index 9dddcd63..7bb4ff52 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TaggedPrincipal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TaggedPrincipal.java @@ -47,7 +47,7 @@ public abstract class TaggedPrincipal implements Principal { } public String personalName() { - if(tagLookup == null) { + if (tagLookup == null) { return getName(); } try { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java index 5d4a0586..7e92aaca 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/TrustPrincipal.java @@ -33,10 +33,10 @@ public class TrustPrincipal extends BearerPrincipal implements UserChain { public TrustPrincipal(final Principal actual, final String asName) { this.original = actual; name = asName.trim(); - if(actual instanceof UserChain) { + if (actual instanceof UserChain) { UserChain uc = (UserChain)actual; userChain = uc.userChain(); - } else if(actual instanceof TaggedPrincipal) { + } else if (actual instanceof TaggedPrincipal) { userChain=((TaggedPrincipal)actual).tag(); } else { userChain = actual.getClass().getSimpleName(); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java index 1cd114a0..0348cd1f 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/principal/X509Principal.java @@ -55,17 +55,17 @@ public class X509Principal extends BearerPrincipal implements GetCred { String _name = null; String subj = cert.getSubjectDN().getName(); int cn = subj.indexOf("OU="); - if(cn>=0) { + if (cn>=0) { cn+=3; int space = subj.indexOf(',',cn); - if(space>=0) { + if (space>=0) { String id = subj.substring(cn, space); - if(pattern.matcher(id).matches()) { + if (pattern.matcher(id).matches()) { _name = id; } } } - if(_name==null) { + if (_name==null) { throw new IOException("X509 does not have Identity as CN"); } name = _name; @@ -74,7 +74,7 @@ public class X509Principal extends BearerPrincipal implements GetCred { public String getAsHeader() throws IOException { try { - if(content==null) { + if (content==null) { content=cert.getEncoded(); } } catch (CertificateEncodingException e) { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/EpiTaf.java b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/EpiTaf.java index b248e553..d2cbf3fa 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/EpiTaf.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/EpiTaf.java @@ -47,7 +47,7 @@ public class EpiTaf implements Taf { */ public EpiTaf(Taf ... tafs) throws CadiException{ this.tafs = tafs; - if(tafs.length==0) throw new CadiException("Need at least one Taf implementation in constructor"); + if (tafs.length==0) throw new CadiException("Need at least one Taf implementation in constructor"); } /** @@ -63,13 +63,13 @@ public class EpiTaf implements Taf { */ public TafResp validate(LifeForm reading, String... info) { TafResp tresp,firstTryAuth=null; - for(Taf taf : tafs) { + for (Taf taf : tafs) { tresp = taf.validate(reading, info); switch(tresp.isAuthenticated()) { case TRY_ANOTHER_TAF: break; case TRY_AUTHENTICATING: - if(firstTryAuth==null)firstTryAuth=tresp; + if (firstTryAuth==null)firstTryAuth=tresp; break; default: return tresp; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/HttpEpiTaf.java b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/HttpEpiTaf.java index b0f56603..6334164e 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/HttpEpiTaf.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/HttpEpiTaf.java @@ -94,7 +94,7 @@ public class HttpEpiTaf implements HttpTaf { TafResp firstTry = null; List redirectables = null; List log; - if(access.willLog(Level.DEBUG)) { + if (access.willLog(Level.DEBUG)) { log = new ArrayList<>(); } else { log = null; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java index 21830b01..d5f6b032 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java @@ -85,23 +85,23 @@ public class BasicHttpTaf implements HttpTaf { */ public TafResp validate(Taf.LifeForm reading, HttpServletRequest req, HttpServletResponse resp) { // See if Request implements BasicCred (aka CadiWrap or other), and if User/Pass has already been set separately - if(req instanceof BasicCred) { + if (req instanceof BasicCred) { BasicCred bc = (BasicCred)req; - if(bc.getUser()!=null) { // CadiWrap, if set, makes sure User & Password are both valid, or both null - if(DenialOfServiceTaf.isDeniedID(bc.getUser())!=null) { + if (bc.getUser()!=null) { // CadiWrap, if set, makes sure User & Password are both valid, or both null + if (DenialOfServiceTaf.isDeniedID(bc.getUser())!=null) { return DenialOfServiceTaf.respDenyID(access,bc.getUser()); } CachedBasicPrincipal bp = new CachedBasicPrincipal(this,bc,realm,timeToLive); // Be able to do Organizational specific lookups by Domain CredVal cv = rbacs.get(bp.getDomain()); - if(cv==null) { + if (cv==null) { cv = rbac; } // ONLY FOR Last Ditch DEBUGGING... // access.log(Level.WARN,bp.getName() + ":" + new String(bp.getCred())); - if(cv.validate(bp.getName(),Type.PASSWORD,bp.getCred(),req)) { + if (cv.validate(bp.getName(),Type.PASSWORD,bp.getCred(),req)) { return new BasicHttpTafResp(access,bp,bp.getName()+" authenticated by password",RESP.IS_AUTHENTICATED,resp,realm,false); } else { //TODO may need timed retries in a given time period @@ -112,25 +112,25 @@ public class BasicHttpTaf implements HttpTaf { } // Get User/Password from Authorization Header value String authz = req.getHeader("Authorization"); - if(authz != null && authz.startsWith("Basic ")) { - if(warn&&!req.isSecure()) { + if (authz != null && authz.startsWith("Basic ")) { + if (warn&&!req.isSecure()) { access.log(Level.WARN,"WARNING! BasicAuth has been used over an insecure channel"); } try { CachedBasicPrincipal ba = new CachedBasicPrincipal(this,authz,realm,timeToLive); - if(DenialOfServiceTaf.isDeniedID(ba.getName())!=null) { + if (DenialOfServiceTaf.isDeniedID(ba.getName())!=null) { return DenialOfServiceTaf.respDenyID(access,ba.getName()); } final int at = ba.getName().indexOf('@'); CredVal cv = rbacs.get(ba.getName().substring(at+1)); - if(cv==null) { + if (cv==null) { cv = rbac; // default } // ONLY FOR Last Ditch DEBUGGING... // access.log(Level.WARN,ba.getName() + ":" + new String(ba.getCred())); - if(cv.validate(ba.getName(), Type.PASSWORD, ba.getCred(), req)) { + if (cv.validate(ba.getName(), Type.PASSWORD, ba.getCred(), req)) { return new BasicHttpTafResp(access,ba, ba.getName()+" authenticated by BasicAuth password",RESP.IS_AUTHENTICATED,resp,realm,false); } else { //TODO may need timed retries in a given time period @@ -148,7 +148,7 @@ public class BasicHttpTaf implements HttpTaf { protected String buildMsg(Principal pr, HttpServletRequest req, Object ... msg) { StringBuilder sb = new StringBuilder(); - if(pr!=null) { + if (pr!=null) { sb.append("user="); sb.append(pr.getName()); sb.append(','); @@ -157,9 +157,9 @@ public class BasicHttpTaf implements HttpTaf { sb.append(req.getRemoteAddr()); sb.append(",port="); sb.append(req.getRemotePort()); - if(msg.length>0) { + if (msg.length>0) { sb.append(",msg=\""); - for(Object s : msg) { + for (Object s : msg) { sb.append(s.toString()); } sb.append('"'); @@ -173,7 +173,7 @@ public class BasicHttpTaf implements HttpTaf { public CredVal getCredVal(String key) { CredVal cv = rbacs.get(key); - if(cv==null) { + if (cv==null) { cv = rbac; } return cv; @@ -181,9 +181,9 @@ public class BasicHttpTaf implements HttpTaf { @Override public Resp revalidate(CachedPrincipal prin, Object state) { - if(prin instanceof BasicPrincipal) { + if (prin instanceof BasicPrincipal) { BasicPrincipal ba = (BasicPrincipal)prin; - if(DenialOfServiceTaf.isDeniedID(ba.getName())!=null) { + if (DenialOfServiceTaf.isDeniedID(ba.getName())!=null) { return Resp.UNVALIDATED; } return rbac.validate(ba.getName(), Type.PASSWORD, ba.getCred(), state)?Resp.REVALIDATED:Resp.UNVALIDATED; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java index d0034c76..0f252e39 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/cert/X509Taf.java @@ -81,18 +81,18 @@ public class X509Taf implements HttpTaf { public X509Taf(Access access, Lur lur, CertIdentity ... cis) throws CertificateException, NoSuchAlgorithmException, CadiException { this.access = access; env = access.getProperty(Config.AAF_ENV,null); - if(env==null) { + if (env==null) { throw new CadiException("X509Taf requires Environment ("+Config.AAF_ENV+") to be set."); } // this.lur = lur; this.cadiIssuers = new ArrayList<>(); - for(String ci : access.getProperty(Config.CADI_X509_ISSUERS, "").split(":")) { + for (String ci : access.getProperty(Config.CADI_X509_ISSUERS, "").split(":")) { access.printf(Level.INIT, "Trusting Identity for Certificates signed by \"%s\"",ci); cadiIssuers.add(ci); } try { Class dci = access.classLoader().loadClass("org.onap.aaf.auth.direct.DirectCertIdentity"); - if(dci==null) { + if (dci==null) { certIdents = cis; } else { CertIdentity temp[] = new CertIdentity[cis.length+1]; @@ -129,28 +129,28 @@ public class X509Taf implements HttpTaf { // Check for Mutual SSL try { X509Certificate[] certarr = (X509Certificate[])req.getAttribute("javax.servlet.request.X509Certificate"); - if(certarr!=null && certarr.length>0) { + if (certarr!=null && certarr.length>0) { si.checkClientTrusted(certarr); // Note: If the Issuer is not in the TrustStore, it's not added to the Cert list String issuer = certarr[0].getIssuerDN().toString(); - if(cadiIssuers.contains(issuer)) { + if (cadiIssuers.contains(issuer)) { String subject = certarr[0].getSubjectDN().getName(); // avoiding extra object creation, since this is validated EVERY transaction with a Cert int at = subject.indexOf('@'); - if(at>=0) { + if (at>=0) { int start = subject.lastIndexOf(',', at); - if(start<0) { + if (start<0) { start = 0; } int end = subject.indexOf(',', at); - if(end<0) { + if (end<0) { end=subject.length(); } int temp; - if(((temp=subject.indexOf("OU=",start))>=0 && temp=0 && temp=0 && temp1 && env!=null && env.equals(sa[1]))) { // Check Environment + if (sa.length==1 || (sa.length>1 && env!=null && env.equals(sa[1]))) { // Check Environment return new X509HttpTafResp(access, new X509Principal(sa[0], certarr[0],(byte[])null,bht), "X509Taf validated " + sa[0] + (sa.length<2?"":" for aaf_env " + env ), RESP.IS_AUTHENTICATED); @@ -168,10 +168,10 @@ public class X509Taf implements HttpTaf { String responseText=null; String authHeader = req.getHeader("Authorization"); - if(certarr!=null) { // If cert !=null, Cert is Tested by Mutual Protocol. - if(authHeader!=null) { // This is only intended to be a Secure Connection, not an Identity - for(String auth : Split.split(',',authHeader)) { - if(auth.startsWith("Bearer ")) { // Bearer = OAuth... Don't use as Authenication + if (certarr!=null) { // If cert !=null, Cert is Tested by Mutual Protocol. + if (authHeader!=null) { // This is only intended to be a Secure Connection, not an Identity + for (String auth : Split.split(',',authHeader)) { + if (auth.startsWith("Bearer ")) { // Bearer = OAuth... Don't use as Authenication return new X509HttpTafResp(access, null, "Certificate verified, but Bearer Token is presented", RESP.TRY_ANOTHER_TAF); } } @@ -179,9 +179,9 @@ public class X509Taf implements HttpTaf { cert = certarr[0]; responseText = ", validated by Mutual SSL Protocol"; } else { // If cert == null, Get Declared Cert (in header), but validate by having them sign something - if(authHeader != null) { - for(String auth : Split.splitTrim(',',authHeader)) { - if(auth.startsWith("x509 ")) { + if (authHeader != null) { + for (String auth : Split.splitTrim(',',authHeader)) { + if (auth.startsWith("x509 ")) { ByteArrayOutputStream baos = new ByteArrayOutputStream(auth.length()); try { array = auth.getBytes(); @@ -197,10 +197,10 @@ public class X509Taf implements HttpTaf { // cert.checkValidity(); // cert.--- GET FINGERPRINT? String stuff = req.getHeader("Signature"); - if(stuff==null) + if (stuff==null) return new X509HttpTafResp(access, null, "Header entry 'Signature' required to validate One way X509 Certificate", RESP.TRY_ANOTHER_TAF); String data = req.getHeader("Data"); - // if(data==null) + // if (data==null) // return new X509HttpTafResp(access, null, "No signed Data to validate with X509 Certificate", RESP.TRY_ANOTHER_TAF); // Note: Data Pos shows is " " @@ -215,7 +215,7 @@ public class X509Taf implements HttpTaf { Signature sig = Signature.getInstance(cert.getSigAlgName()); sig.initVerify(cert.getPublicKey()); sig.update(data.getBytes()); - if(!sig.verify(array)) { + if (!sig.verify(array)) { access.log(Level.ERROR, "Signature doesn't Match"); return new X509HttpTafResp(access, null, CERTIFICATE_NOT_VALID_FOR_AUTHENTICATION, RESP.TRY_ANOTHER_TAF); } @@ -227,21 +227,21 @@ public class X509Taf implements HttpTaf { } } } - if(cert==null) { + if (cert==null) { return new X509HttpTafResp(access, null, "No Certificate Info on Transaction", RESP.TRY_ANOTHER_TAF); } // A cert has been found, match Identify TaggedPrincipal prin=null; - for(int i=0;prin==null && i(); deniedIP.put(ip, new Counter(ip)); // Noted duplicated for minimum time spent rv= true; - } else if(deniedIP.get(ip)==null) { + } else if (deniedIP.get(ip)==null) { deniedIP.put(ip, new Counter(ip)); rv = true; } - if(rv) { + if (rv) { writeIP(); } return rv; } private static void writeIP() { - if(dosIP!=null && deniedIP!=null) { - if(deniedIP.isEmpty()) { - if(dosIP.exists()) { + if (dosIP!=null && deniedIP!=null) { + if (deniedIP.isEmpty()) { + if (dosIP.exists()) { dosIP.delete(); } } else { @@ -150,7 +150,7 @@ public class DenialOfServiceTaf implements HttpTaf { try { fos = new PrintStream(new FileOutputStream(dosIP,false)); try { - for(String ip: deniedIP.keySet()) { + for (String ip: deniedIP.keySet()) { fos.println(ip); } } finally { @@ -164,17 +164,17 @@ public class DenialOfServiceTaf implements HttpTaf { } private static void readIP() { - if(dosIP!=null && dosIP.exists()) { + if (dosIP!=null && dosIP.exists()) { BufferedReader br; try { br = new BufferedReader(new FileReader(dosIP)); try { - if(deniedIP==null) { + if (deniedIP==null) { deniedIP=new HashMap<>(); } String line; - while((line=br.readLine())!=null) { + while ((line=br.readLine())!=null) { deniedIP.put(line, new Counter(line)); } } finally { @@ -195,9 +195,9 @@ public class DenialOfServiceTaf implements HttpTaf { * @return */ public static synchronized boolean removeDenyIP(String ip) { - if(deniedIP!=null && deniedIP.remove(ip)!=null) { + if (deniedIP!=null && deniedIP.remove(ip)!=null) { writeIP(); - if(deniedIP.isEmpty()) { + if (deniedIP.isEmpty()) { deniedIP=null; } return true; @@ -214,15 +214,15 @@ public class DenialOfServiceTaf implements HttpTaf { */ public static synchronized boolean denyID(String id) { boolean rv = false; - if(deniedID==null) { + if (deniedID==null) { deniedID = new HashMap<>(); deniedID.put(id, new Counter(id)); // Noted duplicated for minimum time spent rv = true; - } else if(deniedID.get(id)==null) { + } else if (deniedID.get(id)==null) { deniedID.put(id, new Counter(id)); rv = true; } - if(rv) { + if (rv) { writeID(); } return rv; @@ -230,9 +230,9 @@ public class DenialOfServiceTaf implements HttpTaf { } private static void writeID() { - if(dosID!=null && deniedID!=null) { - if(deniedID.isEmpty()) { - if(dosID.exists()) { + if (dosID!=null && deniedID!=null) { + if (deniedID.isEmpty()) { + if (dosID.exists()) { dosID.delete(); } } else { @@ -240,7 +240,7 @@ public class DenialOfServiceTaf implements HttpTaf { try { fos = new PrintStream(new FileOutputStream(dosID,false)); try { - for(String ip: deniedID.keySet()) { + for (String ip: deniedID.keySet()) { fos.println(ip); } } finally { @@ -254,17 +254,17 @@ public class DenialOfServiceTaf implements HttpTaf { } private static void readID() { - if(dosID!=null && dosID.exists()) { + if (dosID!=null && dosID.exists()) { BufferedReader br; try { br = new BufferedReader(new FileReader(dosID)); try { - if(deniedID==null) { + if (deniedID==null) { deniedID=new HashMap<>(); } String line; - while((line=br.readLine())!=null) { + while ((line=br.readLine())!=null) { deniedID.put(line, new Counter(line)); } } finally { @@ -284,9 +284,9 @@ public class DenialOfServiceTaf implements HttpTaf { * @return */ public static synchronized boolean removeDenyID(String id) { - if(deniedID!=null && deniedID.remove(id)!=null) { + if (deniedID!=null && deniedID.remove(id)!=null) { writeID(); - if(deniedID.isEmpty()) { + if (deniedID.isEmpty()) { deniedID=null; } @@ -297,16 +297,16 @@ public class DenialOfServiceTaf implements HttpTaf { public List report() { int initSize = 0; - if(deniedIP!=null)initSize+=deniedIP.size(); - if(deniedID!=null)initSize+=deniedID.size(); + if (deniedIP!=null)initSize+=deniedIP.size(); + if (deniedID!=null)initSize+=deniedID.size(); ArrayList al = new ArrayList<>(initSize); - if(deniedID!=null) { - for(Counter c : deniedID.values()) { + if (deniedID!=null) { + for (Counter c : deniedID.values()) { al.add(c.toString()); } } - if(deniedIP!=null) { - for(Counter c : deniedIP.values()) { + if (deniedIP!=null) { + for (Counter c : deniedIP.values()) { al.add(c.toString()); } } @@ -344,13 +344,13 @@ public class DenialOfServiceTaf implements HttpTaf { private synchronized void inc() { ++count; last = System.currentTimeMillis(); - if(first==null) { + if (first==null) { first = new Date(last); } } public String toString() { - if(count==0) + if (count==0) return name + " is on the denied list, but has not attempted Access"; else return diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/FQI.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/FQI.java index f0b8d38d..07389aad 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/FQI.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/FQI.java @@ -31,14 +31,14 @@ public class FQI { StringBuilder sb = null; String[] split = Split.split('.',fqi); int at; - for(int i=split.length-1;i>=0;--i) { - if(sb == null) { + for (int i=split.length-1;i>=0;--i) { + if (sb == null) { sb = new StringBuilder(); } else { sb.append('.'); } - if((at = split[i].indexOf('@'))>0) { + if ((at = split[i].indexOf('@'))>0) { sb.append(split[i].subSequence(at+1, split[i].length())); } else { sb.append(split[i]); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/JsonOutputStream.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/JsonOutputStream.java index 7c3ac30d..e790766b 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/JsonOutputStream.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/JsonOutputStream.java @@ -39,11 +39,11 @@ public class JsonOutputStream extends OutputStream { @Override public void write(int b) throws IOException { - if(ret=='\n') { + if (ret=='\n') { ret = 0; - if(prev!=',' || (b!='{' && b!='[')) { + if (prev!=',' || (b!='{' && b!='[')) { os.write('\n'); - for(int i=0;i=0?slash:str.length(); int bits = slash>=0?Integer.parseInt(str.substring(slash+1)):32; - if(check && bits>32) { + if (check && bits>32) { throw new MaskFormatException("Invalid Mask Offset in IPV4 Address"); } int prev = 0; long lbyte; - while(prev255 || lbyte<0)) { + if (check && (lbyte>255 || lbyte<0)) { throw new MaskFormatException("Invalid Byte in IPV4 Address"); } rv|=lbyte<=0 && idx=0 && idx=0 && idx=0 && idx=0 && idx=0 && idx=0 && idx=0 && idx=0 && count=0 && count0) { + if (idx>0) { rv[++count]=value.substring(last,idx).trim(); } else { rv[++count]=value.substring(last).trim(); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/SubStandardConsole.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/SubStandardConsole.java index 5cab15f6..a85020ff 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/SubStandardConsole.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/SubStandardConsole.java @@ -40,7 +40,7 @@ public class SubStandardConsole implements MyConsole { try { System.out.printf(fmt,args); rv = br.readLine(); - if(args.length==1 && rv.length()==0) { + if (args.length==1 && rv.length()==0) { rv = args[0].toString(); } } catch (IOException e) { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/TheConsole.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/TheConsole.java index 9ddd0626..da99d06d 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/TheConsole.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/TheConsole.java @@ -25,7 +25,7 @@ public class TheConsole implements MyConsole { @Override public String readLine(String fmt, Object... args) { String rv = System.console().readLine(fmt, args); - if(args.length>0 && args[0]!=null && rv.length()==0) { + if (args.length>0 && args[0]!=null && rv.length()==0) { rv = args[0].toString(); } return rv; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/UserChainManip.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/UserChainManip.java index ff74f39c..d42aaf55 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/UserChainManip.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/UserChainManip.java @@ -31,7 +31,7 @@ public class UserChainManip { */ public static StringBuilder build(StringBuilder sb, String app, String id, UserChain.Protocol proto, boolean as) { boolean mayAs; - if(!(mayAs=sb.length()==0)) { + if (!(mayAs=sb.length()==0)) { sb.append(','); } sb.append(app); @@ -39,34 +39,34 @@ public class UserChainManip { sb.append(id); sb.append(':'); sb.append(proto.name()); - if(as && mayAs) { + if (as && mayAs) { sb.append(":AS"); } return sb; } public static String idToNS(String id) { - if(id==null) { + if (id==null) { return ""; } else { StringBuilder sb = new StringBuilder(); char c; int end; boolean first = true; - for(int idx = end = id.length()-1;idx>=0;--idx) { - if((c = id.charAt(idx))=='@' || c=='.') { - if(idx=0;--idx) { + if ((c = id.charAt(idx))=='@' || c=='.') { + if (idx=0) { + while ((idx=text.indexOf('%',prev))>=0) { replace = false; - if(clearIndex) { + if (clearIndex) { index=0; } - if(sb!=null) { + if (sb!=null) { sb.append(text,prev,idx); } - if(holder!=null) { + if (holder!=null) { holder.append(text,prev,idx); } boolean go = true; - while(go) { - if(text.length()>++idx) { + while (go) { + if (text.length()>++idx) { switch(c=text.charAt(idx)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -87,19 +87,19 @@ public class Vars { } prev = idx; go=false; - if(replace) { - if(sb!=null) { + if (replace) { + if (sb!=null) { sb.append('%'); sb.append(index); } - if(index<=vars.length) { - if(holder!=null) { + if (index<=vars.length) { + if (holder!=null) { holder.append(vars[index-1]); } } } else { - for(StringBuilder s : sbs) { - if(s!=null) { + for (StringBuilder s : sbs) { + if (s!=null) { s.append("%"); } } @@ -107,10 +107,10 @@ public class Vars { } } - if(sb!=null) { + if (sb!=null) { sb.append(text,prev,text.length()); } - if(holder!=null) { + if (holder!=null) { holder.append(text,prev,text.length()); } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/Match.java b/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/Match.java index 38322307..d0a7da47 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/Match.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/Match.java @@ -57,42 +57,42 @@ public class Match { this.qname = new QName(ns,name); this.next = next; stopAfter = exclusive = false; - for(Match m : next) { // add the possible tags to look for - if(!m.stopAfter)m.prev = this; + for (Match m : next) { // add the possible tags to look for + if (!m.stopAfter)m.prev = this; } } public Match onMatch(OUTPUT output, XReader reader) throws XMLStreamException { - while(reader.hasNext()) { + while (reader.hasNext()) { XEvent event = reader.nextEvent(); switch(event.getEventType()) { case XMLEvent.START_ELEMENT: QName e_qname = event.asStartElement().getName(); //System.out.println("Start - " + e_qname); boolean match = false; - for(Match m : next) { - if(e_qname.equals(m.qname)) { + for (Match m : next) { + if (e_qname.equals(m.qname)) { match=true; - if(m.onMatch(output, reader)==null) { + if (m.onMatch(output, reader)==null) { return null; // short circuit Parsing } break; } } - if(exclusive && !match) // When Tag MUST be present, i.e. the Root Tag, versus info we're not interested in + if (exclusive && !match) // When Tag MUST be present, i.e. the Root Tag, versus info we're not interested in return null; break; case XMLEvent.CHARACTERS: //System.out.println("Data - " +event.asCharacters().getData()); - if(action!=null) { - if(!action.content(output,event.asCharacters().getData())) { + if (action!=null) { + if (!action.content(output,event.asCharacters().getData())) { return null; } } break; case XMLEvent.END_ELEMENT: //System.out.println("End - " + event.asEndElement().getName()); - if(event.asEndElement().getName().equals(qname)) { + if (event.asEndElement().getName().equals(qname)) { return prev; } break; diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/XReader.java b/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/XReader.java index b7cc40ad..aa46bec5 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/XReader.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/wsse/XReader.java @@ -66,7 +66,7 @@ public class XReader { } public boolean hasNext() throws XMLStreamException { - if(curr==null) { + if (curr==null) { curr = parse(); } return curr!=null; @@ -106,7 +106,7 @@ public class XReader { Map nss = nsses.isEmpty()?null:nsses.peek(); XEvent rv; - if((rv=another)!=null) { // "another" is a tag that may have needed to be created, but not + if ((rv=another)!=null) { // "another" is a tag that may have needed to be created, but not // immediately returned. Save for next parse. If necessary, this could be turned into // a FIFO storage, but a single reference is enough for now. another = null; // "rv" is now set for the Event, and will be returned. Set to Null. @@ -115,15 +115,15 @@ public class XReader { int c=0; try { - while(go && (c=is.read())>=0) { + while (go && (c=is.read())>=0) { ++count; switch(c) { case '<': // Tag is opening state|=~BEGIN_DOC; // remove BEGIN_DOC flag, this is possibly an XML Doc XEvent cxe = null; - if(baos.size()>0) { // If there are any characters between tags, we send as Character Event + if (baos.size()>0) { // If there are any characters between tags, we send as Character Event String chars = baos.toString().trim(); // Trim out WhiteSpace before and after - if(chars.length()>0) { // don't send if Characters were only whitespace + if (chars.length()>0) { // don't send if Characters were only whitespace cxe = new XEvent.Characters(chars); baos.reset(); go = false; @@ -145,7 +145,7 @@ public class XReader { default: ns = ""; } - if(ns==null) + if (ns==null) throw new XMLStreamException("Invalid Namespace Prefix at " + count); go = false; switch(t.state) { // based on @@ -165,9 +165,9 @@ public class XReader { break; case START_TAG|END_TAG: // This tag is both start/end aka rv = new XEvent.StartElement(ns,t.name); - if(last=='/')another = new XEvent.EndElement(ns,t.name); + if (last=='/')another = new XEvent.EndElement(ns,t.name); } - if(cxe!=null) { // if there is a Character Event, it actually should go first. ow. + if (cxe!=null) { // if there is a Character Event, it actually should go first. ow. another = rv; // Make current Event the "another" or next event, and rv = cxe; // send Character Event now } @@ -175,12 +175,12 @@ public class XReader { case ' ': case '\t': case '\n': - if((state&BEGIN_DOC)==BEGIN_DOC) { // if Whitespace before doc, just ignore + if ((state&BEGIN_DOC)==BEGIN_DOC) { // if Whitespace before doc, just ignore break; } // fallthrough on purpose default: - if((state&BEGIN_DOC)==BEGIN_DOC) { // if there is any data at the start other than XML Tag, it's not XML + if ((state&BEGIN_DOC)==BEGIN_DOC) { // if there is any data at the start other than XML Tag, it's not XML throw new XMLStreamException("Parse Error: This is not an XML Doc"); } baos.write(c); // save off Characters @@ -190,7 +190,7 @@ public class XReader { } catch (IOException e) { throw new XMLStreamException(e); // all errors parsing will be treated as XMLStreamErrors (like StAX) } - if(c==-1 && (state&BEGIN_DOC)==BEGIN_DOC) { // Normally, end of stream is ok, however, we need to know if the + if (c==-1 && (state&BEGIN_DOC)==BEGIN_DOC) { // Normally, end of stream is ok, however, we need to know if the throw new XMLStreamException("Premature End of File"); // document isn't an XML document, so we throw exception if it } // hasn't yet been determined to be an XML Doc } @@ -214,15 +214,15 @@ public class XReader { String prefix=null,name=null,value=null; baos.reset(); - while(go && (c=is.read())>=0) { + while (go && (c=is.read())>=0) { ++count; - if(quote!=0) { // If we're in a quote, we only end if we hit another quote of the same time, not preceded by \ - if(c==quote && last!='\\') { + if (quote!=0) { // If we're in a quote, we only end if we hit another quote of the same time, not preceded by \ + if (c==quote && last!='\\') { quote=0; } else { baos.write(c); } - } else if((state&COMMENT)==COMMENT) { // similar to Quote is being in a comment + } else if ((state&COMMENT)==COMMENT) { // similar to Quote is being in a comment switch(c) { case '-': switch(state) { // XML has a complicated Quote set... ... we keep track if each has been met with flags. @@ -244,7 +244,7 @@ public class XReader { } break; case '>': // Tag indicator has been found, do we have all the comment characters in line? - if((state&COMPLETE_COMMENT)==COMPLETE_COMMENT) { + if ((state&COMPLETE_COMMENT)==COMPLETE_COMMENT) { byte ba[] = baos.toByteArray(); tag = new Tag(null,null, new String(ba,0,ba.length-2)); baos.reset(); @@ -254,7 +254,7 @@ public class XReader { // fall through on purpose default: state&=~(COMMENT_D3|COMMENT_D4); - if((state&IN_COMMENT)!=IN_COMMENT) state&=~IN_COMMENT; // false alarm, it's not actually a comment + if ((state&IN_COMMENT)!=IN_COMMENT) state&=~IN_COMMENT; // false alarm, it's not actually a comment baos.write(c); } } else { // Normal Tag Processing loop @@ -273,7 +273,7 @@ public class XReader { } break; case '!': - if(last=='<') { + if (last=='<') { state|=COMMENT|COMMENT_E; // likely a comment, continue processing in Comment Loop } baos.write(c); @@ -296,15 +296,15 @@ public class XReader { case ' ': case '\t': case '\n': // white space indicates change in internal tag state, ex between name and between attributes - if((state&VALUE)==VALUE) { + if ((state&VALUE)==VALUE) { value = baos.toString(); // we're in VALUE state, add characters to Value - } else if(name==null) { + } else if (name==null) { name = baos.toString(); // we're in Name state (default) add characters to Name } baos.reset(); // we've assigned chars, reset buffer - if(name!=null) { // Name is not null, there's a tag in the offing here... + if (name!=null) { // Name is not null, there's a tag in the offing here... Tag t = new Tag(prefix,name,value); - if(tag==null) { // Set as the tag to return, if not exists + if (tag==null) { // Set as the tag to return, if not exists tag = t; } else { // if we already have a Tag, then we'll treat this one as an attribute tag.add(t); @@ -314,7 +314,7 @@ public class XReader { break; case '\'': // is the character one of two kinds of quote? case '"': - if(last!='\\') { + if (last!='\\') { quote=c; break; } @@ -327,10 +327,10 @@ public class XReader { last = c; } int type = state&(DOC_TYPE|COMMENT|END_TAG|START_TAG); // get just the Tag states and turn into Type for Tag - if(type==0) { + if (type==0) { type=START_TAG; } - if(tag!=null) { + if (tag!=null) { tag.state|=type; // add the appropriate Tag States } return tag; @@ -350,20 +350,20 @@ public class XReader { */ private Map getNss(Map nss, Tag t) { Map newnss = null; - if(t.attribs!=null) { - for(Tag tag : t.attribs) { - if("xmlns".equals(tag.prefix)) { - if(newnss==null) { + if (t.attribs!=null) { + for (Tag tag : t.attribs) { + if ("xmlns".equals(tag.prefix)) { + if (newnss==null) { newnss = new HashMap<>(); - if(nss!=null)newnss.putAll(nss); + if (nss!=null)newnss.putAll(nss); } newnss.put(tag.name, tag.value); } } } //return newnss==null?(nss==null?new HashMap():nss):newnss; - if(newnss==null) { - if(nss==null) { + if (newnss==null) { + if (nss==null) { newnss = new HashMap<>(); } else { newnss = nss; @@ -399,7 +399,7 @@ public class XReader { * @param tag */ public void add(Tag attrib) { - if(attribs == null) { + if (attribs == null) { attribs = new ArrayList<>(); } attribs.add(attrib); @@ -407,14 +407,14 @@ public class XReader { public String toString() { StringBuffer sb = new StringBuffer(); - if(prefix!=null) { + if (prefix!=null) { sb.append(prefix); sb.append(':'); } sb.append(name==null?"!!ERROR!!":name); char quote = ((state&DOC_TYPE)==DOC_TYPE)?'\'':'"'; - if(value!=null) { + if (value!=null) { sb.append('='); sb.append(quote); sb.append(value); -- cgit 1.2.3-korg