diff options
author | Instrumental <jcgmisc@stl.gathman.org> | 2018-03-29 19:02:24 -0500 |
---|---|---|
committer | Instrumental <jcgmisc@stl.gathman.org> | 2018-03-29 19:02:44 -0500 |
commit | d86dd644e1543743cfcbc83b230bd4f2cb2e5d4e (patch) | |
tree | 698e12f7c0142441cd494cd68da03437e510d0b0 /cadi | |
parent | 17ca744723bd652f15d59d6c8555824f6e49018d (diff) |
Clean up Sonar results 1
Issue-ID: AAF-206
Change-Id: If1fced5b528490a52691508fb1e30962dbe28856
Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
Diffstat (limited to 'cadi')
5 files changed, 48 insertions, 41 deletions
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java index 101fd607..b4bca20d 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java @@ -223,17 +223,20 @@ public class TestConnectivity { if((uri = dl.get(li)) == null) { System.out.println("Locator Item empty"); } else { + socket = new Socket(); try { - socket = new Socket(); - socket.connect(new InetSocketAddress(uri.getHost(), uri.getPort()),3000); - System.out.printf("Can Connect a Socket to %s %d\n",uri.getHost(),uri.getPort()); + try { + socket.connect(new InetSocketAddress(uri.getHost(), uri.getPort()),3000); + System.out.printf("Can Connect a Socket to %s %d\n",uri.getHost(),uri.getPort()); + } catch (IOException e) { + System.out.printf("Cannot Connect a Socket to %s %d: %s\n",uri.getHost(),uri.getPort(),e.getMessage()); + } + } finally { try { socket.close(); } catch (IOException e1) { System.out.printf("Could not close Socket Connection: %s\n",e1.getMessage()); } - } catch (IOException e) { - System.out.printf("Cannot Connect a Socket to %s %d: %s\n",uri.getHost(),uri.getPort(),e.getMessage()); } } } diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/ArtifactDir.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/ArtifactDir.java index 3669d04f..7259d68e 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/ArtifactDir.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/ArtifactDir.java @@ -216,35 +216,35 @@ public abstract class ArtifactDir implements PlaceArtifact { f.setWritable(true); } } + // Append if not first PrintWriter pw = new PrintWriter(new FileWriter(f,!first)); - - // Write a Header - if(first) { - for(int i=0;i<60;++i) { - pw.print('#'); - } - pw.println(); - pw.println("# Properties Generated by AT&T Certificate Manager"); - pw.print("# by "); - pw.println(System.getProperty("user.name")); - pw.print("# on "); - pw.println(Chrono.dateStamp()); - pw.println("# @copyright 2016, AT&T"); - for(int i=0;i<60;++i) { - pw.print('#'); - } - pw.println(); - for(String prop : encodeds) { - if( prop.startsWith("cm_") - || prop.startsWith(Config.HOSTNAME) - || prop.startsWith(Config.AAF_ENV)) { - pw.println(prop); + try { + // Write a Header + if(first) { + for(int i=0;i<60;++i) { + pw.print('#'); + } + pw.println(); + pw.println("# Properties Generated by AT&T Certificate Manager"); + pw.print("# by "); + pw.println(System.getProperty("user.name")); + pw.print("# on "); + pw.println(Chrono.dateStamp()); + pw.println("# @copyright 2016, AT&T"); + for(int i=0;i<60;++i) { + pw.print('#'); + } + pw.println(); + for(String prop : encodeds) { + if( prop.startsWith("cm_") + || prop.startsWith(Config.HOSTNAME) + || prop.startsWith(Config.AAF_ENV)) { + pw.println(prop); + } } } - } - try { for(String prop : encodeds) { if(prop.startsWith("cadi")) { pw.println(prop); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java index 8933963d..e969fab3 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java @@ -229,13 +229,13 @@ public class Factory { public static Collection<? extends Certificate> toX509Certificate(Trans trans, File file) throws CertificateException, FileNotFoundException { FileInputStream fis = new FileInputStream(file); try { - return toX509Certificate(fis); - } finally { try { - fis.close(); - } catch (IOException e) { - throw new CertificateException(e); + return toX509Certificate(fis); + } finally { + fis.close(); } + } catch (IOException e) { + throw new CertificateException(e); } } diff --git a/cadi/cass/src/main/java/com/att/aaf/cadi/cass/AAFAuthenticator.java b/cadi/cass/src/main/java/com/att/aaf/cadi/cass/AAFAuthenticator.java index 1f50280c..3e87a366 100644 --- a/cadi/cass/src/main/java/com/att/aaf/cadi/cass/AAFAuthenticator.java +++ b/cadi/cass/src/main/java/com/att/aaf/cadi/cass/AAFAuthenticator.java @@ -141,14 +141,15 @@ public class AAFAuthenticator extends AAFBase implements ISaslAwareAuthenticator byte[] user = null; byte[] pass = null; int end = bytes.length; - for (int i = bytes.length - 1; i >= 0; i--) - { - if (bytes[i] != 0) + for (int i = bytes.length - 1; i >= 0; i--) { + if (bytes[i] != 0) { continue; - if (pass == null) + } + if (pass == null) { pass = Arrays.copyOfRange(bytes, i + 1, end); - else if (user == null) + } else if (user == null) { user = Arrays.copyOfRange(bytes, i + 1, end); + } end = i; } 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 095f6e97..65cb81a5 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 @@ -71,6 +71,7 @@ import org.onap.aaf.cadi.config.Config; public class Symm { private static final byte[] DOUBLE_EQ = new byte[] {'=','='}; public static final String ENC = "enc:"; + private static final Object LOCK = new Object(); private static final SecureRandom random = new SecureRandom(); public final char[] codeset; @@ -207,7 +208,7 @@ public class Symm { } public <T> T exec(SyncExec<T> exec) throws Exception { - synchronized(ENC) { + synchronized(LOCK) { if(keyBytes == null) { keyBytes = new byte[AES.AES_KEY_SIZE/8]; int offset = (Math.abs(codeset[0])+47)%(codeset.length-keyBytes.length); @@ -388,7 +389,9 @@ public class Symm { } public void decode(InputStream is, OutputStream os, int skip) throws IOException { - is.skip(skip); + if(is.skip(skip)!=skip) { + throw new IOException("Error skipping on IOStream in Symm"); + } decode(is,os); } |