Clean up Sonar results 1 93/40293/1
authorInstrumental <jcgmisc@stl.gathman.org>
Fri, 30 Mar 2018 00:02:24 +0000 (19:02 -0500)
committerInstrumental <jcgmisc@stl.gathman.org>
Fri, 30 Mar 2018 00:02:44 +0000 (19:02 -0500)
Issue-ID: AAF-206
Change-Id: If1fced5b528490a52691508fb1e30962dbe28856
Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
25 files changed:
auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
auth/auth-batch/src/main/java/org/onap/aaf/auth/actions/Email.java
auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/AbsCassDAO.java
auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java
auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CertDAO.java
auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java
auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java
auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/ca/CA.java
auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/ca/JscepCA.java
auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/service/CMService.java
auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/AAFcli.java
auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/ns/Attrib.java
auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/Cred.java
auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/user/List.java
auth/auth-core/src/main/java/org/onap/aaf/auth/local/AbsData.java
auth/auth-core/src/main/java/org/onap/aaf/auth/local/TextIndex.java
auth/auth-core/src/main/java/org/onap/aaf/auth/validation/Validator.java
auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java
auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
auth/auth-service/src/main/java/org/onap/aaf/auth/service/AuthzCassServiceImpl.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/TestConnectivity.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/ArtifactDir.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/cm/Factory.java
cadi/cass/src/main/java/com/att/aaf/cadi/cass/AAFAuthenticator.java
cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java

index 6d9252e..ad2de10 100644 (file)
@@ -369,11 +369,15 @@ public abstract class Batch {
        return ld;
     }
        protected int count(String str, char c) {
-               int count=str==null||str.isEmpty()?0:1;
-               for(int i=str.indexOf(c);i>=0;i=str.indexOf(c,i+1)) {
-                       ++count;
+               if(str==null || str.isEmpty()) {
+                       return 0;
+               } else {
+                       int count=1;
+                       for(int i=str.indexOf(c);i>=0;i=str.indexOf(c,i+1)) {
+                               ++count;
+                       }
+                       return count;
                }
-               return count;
        }
 
        public final void close(AuthzTrans trans) {
index 346e517..0687364 100644 (file)
@@ -167,6 +167,7 @@ public class Email implements Action<Organization,Void, String>{
                        try {
                                Thread.sleep(wait);
                        } catch (InterruptedException e) {
+                               return exec(trans,org,sb);
                        }
                }
                return exec(trans,org,sb);
index 9794b2e..89fb12f 100644 (file)
@@ -357,6 +357,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> {
        private static final String NEW_CASSANDRA_SESSION_CREATED = "New Cassandra Session Created";
        private static final String NEW_CASSANDRA_CLUSTER_OBJECT_CREATED = "New Cassandra Cluster Object Created";
        private static final String NEW_CASSANDRA_SESSION = "New Cassandra Session";
+       private static final Object LOCK = new Object();
 
        private static class ResetRequest {
                //package on purpose
@@ -398,7 +399,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> {
                        Cluster tempCluster = null;
                        Session tempSession = null;
                        try {
-                               synchronized(NEW_CASSANDRA_SESSION_CREATED) {
+                               synchronized(LOCK) {
                                        boolean reset = false;
                                        for(ResetRequest r : resetDeque) {
                                                if(r.session == session) {
index bd6d086..f7cdec5 100644 (file)
@@ -185,7 +185,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS
         */
        public Result<DATA> create(TRANS trans, DATA data)  {
                if(createPS==null) {
-                       Result.err(Result.ERR_NotImplemented,"Create is disabled for %s",getClass().getSimpleName());
+                       return Result.err(Result.ERR_NotImplemented,"Create is disabled for %s",getClass().getSimpleName());
                }
                if(async) /*ResultSetFuture */ {
                        Result<ResultSetFuture> rs = createPS.execAsync(trans, C_TEXT, data);
@@ -207,21 +207,21 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS
         */
        public Result<List<DATA>> read(TRANS trans, DATA data) {
                if(readPS==null) {
-                       Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
+                       return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
                }
                return readPS.read(trans, R_TEXT, data);
        }
 
        public Result<List<DATA>> read(TRANS trans, Object ... key) {
                if(readPS==null) {
-                       Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
+                       return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
                }
                return readPS.read(trans, R_TEXT, key);
        }
        
        public Result<DATA> readPrimKey(TRANS trans, Object ... key) {
                if(readPS==null) {
-                       Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
+                       return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
                }
                Result<List<DATA>> rld = readPS.read(trans, R_TEXT, key);
                if(rld.isOK()) {
@@ -241,7 +241,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS
 
        public Result<Void> update(TRANS trans, DATA data, boolean async) {
                if(updatePS==null) {
-                       Result.err(Result.ERR_NotImplemented,"Update is disabled for %s",getClass().getSimpleName());
+                       return Result.err(Result.ERR_NotImplemented,"Update is disabled for %s",getClass().getSimpleName());
                }
                if(async)/* ResultSet rs =*/ {
                        Result<ResultSetFuture> rs = updatePS.execAsync(trans, U_TEXT, data);
@@ -262,7 +262,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS
        // This method Sig for Cached...
        public Result<Void> delete(TRANS trans, DATA data, boolean reread) {
                if(deletePS==null) {
-                       Result.err(Result.ERR_NotImplemented,"Delete is disabled for %s",getClass().getSimpleName());
+                       return Result.err(Result.ERR_NotImplemented,"Delete is disabled for %s",getClass().getSimpleName());
                }
                // Since Deleting will be stored off, for possible re-constitution, need the whole thing
                if(reread) {
index a47b8c9..28e2749 100644 (file)
@@ -163,12 +163,12 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> {
                        data.x509 = readString(is,buff);
                        data.ca = readString(is,buff);
                        int i = is.readInt();
-                       if(i<0) {
-                               data.serial=null;
-                       } else {
+                       data.serial=null;
+                       if(i>=0) {
                                byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads
-                               is.read(bytes);
-                               data.serial = new BigInteger(bytes);
+                               if(is.read(bytes)>0) {
+                                       data.serial = new BigInteger(bytes);
+                               }
                        }
                }
     }
index 46dc12b..7a85ae1 100644 (file)
@@ -182,9 +182,8 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> {
                        data.notes = readString(is,buff);
                        
                        int i = is.readInt();
-                       if(i<0) {
-                               data.cred=null;
-                       } else {
+                       data.cred=null;
+                       if(i>=0) {
                                byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads
                                is.read(bytes);
                                data.cred = ByteBuffer.wrap(bytes);
index 6b0bb17..3634af9 100644 (file)
@@ -367,10 +367,14 @@ public class Question {
                if (r.isOKhasData()) {
                        return Result.ok(r.value.get(0));
                } else {
-                       int dot = child == null ? -1 : child.lastIndexOf('.');
+                       int dot;
+                       if(child==null) {
+                               return Result.err(Status.ERR_NsNotFound, "No Namespace");
+                       } else {
+                               dot = child.lastIndexOf('.');
+                       }
                        if (dot < 0) {
-                               return Result.err(Status.ERR_NsNotFound,
-                                               "No Namespace for [%s]", child);
+                               return Result.err(Status.ERR_NsNotFound, "No Namespace for [%s]", child);
                        } else {
                                return deriveNs(trans, child.substring(0, dot));
                        }
index 521c501..00b0b37 100644 (file)
@@ -115,8 +115,10 @@ public abstract class CA {
                                                        bytes = new byte[(int)crt.length()];
                                                        FileInputStream fis = new FileInputStream(crt);
                                                        try {
-                                                               fis.read(bytes);
-                                                               addTrustedCA(new String(bytes));
+                                                               int read = fis.read(bytes);
+                                                               if(read>0) {    
+                                                                       addTrustedCA(new String(bytes));
+                                                               }
                                                        } finally {
                                                                fis.close();
                                                        }
index ae4e21a..0d494ac 100644 (file)
@@ -61,7 +61,7 @@ public class JscepCA extends CA {
 
        private final static String MS_PROFILE="1";
        private final static int MAX_RETRY=3;
-       public static final long INVALIDATE_TIME = 1000*60*10; // 10 mins
+       public static final long INVALIDATE_TIME = 1000*60*10L; // 10 mins
 
        // package on purpose
        private Map<String,X509ChainWithIssuer> mxcwi_s;
index f6407d9..4ef5472 100644 (file)
@@ -643,7 +643,7 @@ public class CMService {
                                || trans.user().equals(sponsor)) {
                        return artiDAO.delete(trans, add, false);
                }
-               return null;
+               return Result.err(Result.ERR_Denied, "%1 is not allowed to delete this item",trans.user());
        }
 
        public Result<Void> deleteArtifact(AuthzTrans trans, List<ArtiDAO.Data> list) {
index e8069b8..1961b1f 100644 (file)
@@ -324,7 +324,7 @@ public class AAFcli {
                                        try {
                                                ret = c.exec(++idx, largs);
                                                if (delay+globalDelay > 0) {
-                                                       Thread.sleep(delay+globalDelay);
+                                                       Thread.sleep((long)(delay+globalDelay));
                                                }
                                        } catch (Exception e) {
                                                if (expect.contains(-1)) {
index cc0d258..19caa4f 100644 (file)
@@ -83,15 +83,17 @@ public class Attrib extends BaseCmd<NS> {
                                        default:
                                                throw new CadiException("Bad Argument");
                                };
-                       
-                               if(fp.get(AAFcli.timeout())) {
-                                       pw().println(message);
+                               if(fp==null) {
+                                       return 500;
                                } else {
-                                       error(fp);
-                                       return fp.code();
+                                       if(fp.get(AAFcli.timeout())) {
+                                               pw().println(message);
+                                       } else {
+                                               error(fp);
+                                       }
+                                               
+                                       return fp.code(); 
                                }
-                                       
-                               return fp==null?500:fp.code();
                        }
                });
        }
index 4bb2ae3..1033309 100644 (file)
@@ -109,6 +109,9 @@ public class Cred extends Cmd {
 //                                             case 4:
 //                                                     return clean.exec(cleanIDX, args);
                                }
+                               if(fp==null) {
+                                       return null; // get by Sonar check.
+                               }
                                if(fp.get(AAFcli.timeout())) {
                                        pw().print(verb);
                                        pw().print(cr.getId());
index 5c87f90..a977431 100644 (file)
@@ -53,7 +53,7 @@ public class List extends BaseCmd<User> {
                Collections.sort(sorted, new Comparator<aaf.v2_0.Users.User>() {
                        @Override
                        public int compare(aaf.v2_0.Users.User u1, aaf.v2_0.Users.User u2) {
-                               if(u2==null || u2 == null) {
+                               if(u1==null || u2 == null) {
                                        return -1;
                                }
                                return u1.getId().compareTo(u2.getId());
index 40e0b22..d9f7ac9 100644 (file)
@@ -71,7 +71,7 @@ public abstract class AbsData implements Iterable<String> {
        
        public void open(AuthzTrans trans, long timeout) throws IOException {
                TimeTaken tt = trans.start("Open Data File", Env.SUB);
-               boolean opened = false, first = true;
+               boolean first = true;
                try {
                                if(!dataf.exists()) {
                                        throw new FileNotFoundException("Data File Missing:" + dataf.getCanonicalPath());
@@ -102,14 +102,10 @@ public abstract class AbsData implements Iterable<String> {
                                        throw e;
                                }
                                ti.open();
-                               opened = true;
                        
                } finally {
                        tt.done();
                }
-               if(!opened) {
-                       throw new IOException("DataFile pair for " + name + " was not able to be opened in " + timeout + "ms");
-               }
        }
        
        private synchronized void ensureIdxGood(AuthzTrans trans) throws IOException {
index 5169cf8..cbb3603 100644 (file)
@@ -132,8 +132,12 @@ public class TextIndex {
                TimeTaken tt2 = trans.start("Open Files", Env.SUB);
                try {
                        raf = new RandomAccessFile(file,"rw");
-                       raf.setLength(0L);
-                       fos = raf.getChannel();
+                       try {
+                               raf.setLength(0L);
+                               fos = raf.getChannel();
+                       } finally {
+                               raf.close();
+                       }
                } finally {
                        tt2.done();
                }
index 16c0d3b..7078cf0 100644 (file)
@@ -146,8 +146,12 @@ public class Validator {
        }
 
        public final Validator permType(String type, String ns) {
-               if(nob(type,NAME_CHARS)) {
-                       msg("Perm Type [" + (ns==null?"":ns+(type.length()==0?"":'.'))+type + "] is invalid.");
+               if(type==null) {
+                       msg("Perm Type is null");
+               } else if(ns==null) {
+                       msg("Perm NS is null");
+               } else if(nob(type,NAME_CHARS)) {
+                       msg("Perm Type [" + (ns+(type.length()==0?"":'.'))+type + "] is invalid.");
                }
                return this;
        }
@@ -175,7 +179,10 @@ public class Validator {
        }
 
        public final Validator ns(String ns) {
-               if(nob(ns,NAME_CHARS)){
+               if(ns==null) {
+                       msg("NS is null");
+                       return this;
+               } else if(nob(ns,NAME_CHARS)) {
                        msg("NS [" + ns + "] is invalid.");
                } 
                for(String s : nsKeywords) {
index 1ce9821..fdb02c7 100644 (file)
@@ -275,6 +275,7 @@ public abstract class LocateFacadeImpl<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,ERROR> ex
        }
 
        public final static String GET_ENDPOINTS = "getEndpoints";
+       private final static Object LOCK = new Object();
        /* (non-Javadoc)
         * @see org.onap.aaf.auth.locate.facade.GwFacade#getEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String)
         */
@@ -284,7 +285,7 @@ public abstract class LocateFacadeImpl<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,ERROR> ex
                try {
                        String output=null;
                        long temp=System.currentTimeMillis();
-                       synchronized(GET_ENDPOINTS) {
+                       synchronized(LOCK) {
                                if(cacheClear<temp) {
                                        epsCache.clear();
                                        cacheClear = temp+1000*60*2; // 2 mins standard cache clear
@@ -302,7 +303,7 @@ public abstract class LocateFacadeImpl<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,ERROR> ex
                                        return Result.err(reps);
                                } else {
                                        output = epDF.newData(trans).load(reps.value).asString();
-                                       synchronized(GET_ENDPOINTS) {
+                                       synchronized(LOCK) {
                                                epsCache.put(key, output);
                                        }
                                }
@@ -338,7 +339,7 @@ public abstract class LocateFacadeImpl<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,ERROR> ex
                        Result<Void> rp = service.putMgmtEndPoints(trans, rreq);
                        switch(rp.status) {
                                case OK: 
-                                       synchronized(GET_ENDPOINTS) {
+                                       synchronized(LOCK) {
                                                cacheClear = 0L;
                                        }
                                        setContentType(resp,mepDF.getOutType());
@@ -374,7 +375,7 @@ public abstract class LocateFacadeImpl<IN,OUT,ENDPOINTS,MGMT_ENDPOINTS,ERROR> ex
                        Result<Void> rp = service.removeMgmtEndPoints(trans, rreq);
                        switch(rp.status) {
                                case OK: 
-                                       synchronized(GET_ENDPOINTS) {
+                                       synchronized(LOCK) {
                                                cacheClear = 0L;
                                        }
                                        setContentType(resp,mepDF.getOutType());
index 74c9947..e602e86 100644 (file)
@@ -37,12 +37,12 @@ import org.onap.aaf.auth.layer.Result;
 import org.onap.aaf.auth.oauth.facade.DirectIntrospect;
 import org.onap.aaf.auth.rserv.TransFilter;
 import org.onap.aaf.cadi.CachedPrincipal;
+import org.onap.aaf.cadi.CachedPrincipal.Resp;
 import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.CredVal.Type;
 import org.onap.aaf.cadi.Hash;
 import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.CachedPrincipal.Resp;
-import org.onap.aaf.cadi.CredVal.Type;
 import org.onap.aaf.cadi.Taf.LifeForm;
 import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.oauth.OAuth2HttpTafResp;
@@ -50,8 +50,8 @@ import org.onap.aaf.cadi.oauth.OAuth2Principal;
 import org.onap.aaf.cadi.oauth.TokenClient;
 import org.onap.aaf.cadi.oauth.TokenClientFactory;
 import org.onap.aaf.cadi.oauth.TokenMgr;
-import org.onap.aaf.cadi.oauth.TokenPerm;
 import org.onap.aaf.cadi.oauth.TokenMgr.TokenPermLoader;
+import org.onap.aaf.cadi.oauth.TokenPerm;
 import org.onap.aaf.cadi.principal.OAuth2FormPrincipal;
 import org.onap.aaf.cadi.taf.HttpTaf;
 import org.onap.aaf.cadi.taf.TafResp;
@@ -137,7 +137,7 @@ public class DirectOAuthTAF implements HttpTaf {
                                }
                        }
                        
-                       if(client_id==null && client_secret==null) {
+                       if(client_id==null || client_secret==null) {
                                return new OAuth2HttpTafResp(access, null, "client_id and client_secret required", RESP.TRY_ANOTHER_TAF, resp, false);
                        }
                        
index fa09911..5c8526a 100644 (file)
@@ -2913,6 +2913,9 @@ public class AuthzCassServiceImpl <NSS,PERMS,PERMKEY,ROLES,USERS,USERROLES,DELGS
                                                }
                                        }
                                }
+                               if(udr==null) {
+                                       return Result.err(Result.ERR_NotFound,"No User Data found");
+                               }
                                if (udr.isOK()) {
                                        return Result.ok();
                                }
index 101fd60..b4bca20 100644 (file)
@@ -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());
                                }
                        }
                }
index 3669d04..7259d68 100644 (file)
@@ -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);
index 8933963..e969fab 100644 (file)
@@ -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);
                }
        }
 
index 1f50280..3e87a36 100644 (file)
@@ -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;
                      }
 
index 095f6e9..65cb81a 100644 (file)
@@ -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);
     }