Add Init Msg
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / filter / MapBathConverter.java
index 9307493..36372eb 100644 (file)
@@ -81,7 +81,7 @@ public class MapBathConverter {
                        @Override
                        public void visit(List<String> row) throws CadiException {
                                if(row.size()<3) {
-                                       throw new CadiException("CSV file " + csv + " must have at least 2 Basic Auth columns and an Expiration Date(YYYYMMDD) in each row");
+                                       throw new CadiException("CSV file " + csv + " must have at least 2 Basic Auth columns and an Expiration Date(YYYY-MM-DD) in each row");
                                }
                                try {
                                        Date date = sdf.parse(row.get(2));
@@ -138,48 +138,39 @@ public class MapBathConverter {
 
     public String convert(Access access, final String bath) {
        String rv = map.get(bath);
-               String cred=null;
+
+       String cred;
                String tcred=null;
                Holder<String> hpass=null;
                try {
-                       if(rv==null || !rv.startsWith(BASIC)) {
-                       if(bath.startsWith(BASIC)) {
-                               cred = idFromBasic(bath,(hpass=new Holder<String>()));
-                       }
-               }
-
-               if(cred!=null) {
+                       if(bath.startsWith(BASIC)) {
+                       cred = idFromBasic(bath,(hpass=new Holder<String>()));
                        if(rv==null) {
-                               rv = map.get(cred);
+                                       rv = map.get(cred);
                        }
-                       // for SAFETY REASONS, we WILL NOT allow a non validated cred to 
-                               // pass a password from file. Should be caught from Instation, but...
-                       if(rv!=null) {
-                                       if(!rv.startsWith(BASIC)) {
-                                               tcred = rv;
-                                               rv = BASIC + Symm.base64noSplit.encode(rv+':'+hpass.value);
-                                       }
-                       }
-                       }
+               } else {
+                       cred = bath;
+               }
+
+                       if(rv==null) {
+                               // Nothing here, just return original
+                               rv = bath;
+                       } else {
+                       if(rv.startsWith(BASIC)) {
+                               tcred = idFromBasic(rv,null);
+                       } else {
+                               if(hpass!=null) {
+                                       tcred = rv;
+                                       rv = BASIC + Symm.base64noSplit.encode(rv+':'+hpass.value);
+                               }
+                       }
+                       if(tcred != null) {
+                               access.printf(Level.AUDIT, "ID %s converted to %s",cred,tcred);
+                       }
+               }
                } catch (IOException | CadiException e) {
                        access.log(e,"Invalid Authorization");
                }
-               
-               if(rv==null) {
-                       rv=bath;
-               } else {
-                       try {
-                               if(cred==null) {
-                                       cred = idFromBasic(bath,null);
-                               }
-                               if(tcred==null) {
-                                       tcred = idFromBasic(rv,null);
-                               }
-                       } catch (IOException | CadiException e) {
-                               access.log(Level.ERROR,"Invalid Basic Authentication for conversion");
-                       }
-                       access.printf(Level.AUDIT, "ID %s converted to %s",cred,tcred);
-               }
        return rv==null?bath:rv;
     }
 }