X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fconfigure%2FAgent.java;h=a86649db7f104e561770bc3d515c4dcb71bb67ee;hb=9ec2895301056a9e8967eadb139e56f03776fe26;hp=09f5ed7ebb5715840544cdc5fa47bde2e1cc3d59;hpb=d37b5467a3b8b375b603579d2888a4443a8b06a7;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java index 09f5ed7e..a86649db 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java @@ -176,7 +176,7 @@ public class Agent { System.out.println(" check []"); System.out.println(" keypairgen "); System.out.println(" config "); - System.out.println(" validate .props>"); + System.out.println(" validate .props>"); System.out.println(" --- Additional Tool Access ---"); System.out.println(" ** Type with no params for Tool Help"); System.out.println(" ** If using with Agent, preface with \"cadi\""); @@ -251,7 +251,13 @@ public class Agent { keypairGen(trans, access, cmds); break; case "config": - config(trans,access,aafcon(access),cmds); + if(access.getProperty(Config.CADI_PROP_FILES)!=null) { + // Get Properties from initialization Prop Files + config(trans,access,null,cmds); + } else { + // Get Properties from existing AAF Instance + config(trans,access,aafcon(access),cmds); + } break; case "validate": validate(access); @@ -721,7 +727,6 @@ public class Agent { private static void config(Trans trans, PropAccess pa, AAFCon aafcon, Deque cmds) throws Exception { final String fqi = fqi(cmds); - final String locator = getProperty(pa,aafcon.env,false,Config.AAF_LOCATE_URL,"AAF Locator URL: "); final String rootFile = FQI.reverseDomain(fqi); final File dir = new File(pa.getProperty(Config.CADI_ETCDIR, ".")); if(dir.exists()) { @@ -796,35 +801,115 @@ public class Agent { String ps = pa.decrypt(pa.getProperty(Config.AAF_APPPASS), false); ps = filesymm.enpass(ps); psCredProps.println(ps); - - psCredProps.print(Config.CADI_TRUSTSTORE); - psCredProps.print("="); - File origTruststore = new File(pa.getProperty(Config.CADI_TRUSTSTORE)); - File newTruststore = new File(dir,origTruststore.getName()); - if(!newTruststore.exists()) { - Files.copy(origTruststore.toPath(), newTruststore.toPath()); - } - psCredProps.println(newTruststore.getCanonicalPath()); + + String cts = pa.getProperty(Config.CADI_TRUSTSTORE); + if(cts!=null) { + File origTruststore = new File(cts); + if(!origTruststore.exists()) { + // Try same directory as cadi_prop_files + String cpf = pa.getProperty(Config.CADI_PROP_FILES); + if(cpf!=null) { + for(String f : Split.split(File.pathSeparatorChar, cpf)) { + File fcpf = new File(f); + if(fcpf.exists()) { + int lastSep = cts.lastIndexOf(File.pathSeparator); + origTruststore = new File(fcpf.getParentFile(),lastSep>=0?cts.substring(lastSep):cts); + if(origTruststore.exists()) { + break; + } + } + } + if(!origTruststore.exists()) { + throw new CadiException(cts + "does not exist"); + } + } + + } + File newTruststore = new File(dir,origTruststore.getName()); + if(!newTruststore.exists()) { + Files.copy(origTruststore.toPath(), newTruststore.toPath()); + } + psCredProps.print(Config.CADI_TRUSTSTORE); + psCredProps.print("="); + psCredProps.println(newTruststore.getCanonicalPath()); - psCredProps.print(Config.CADI_TRUSTSTORE_PASSWORD); - psCredProps.print("=enc:"); - ps = pa.decrypt(pa.getProperty(Config.CADI_TRUSTSTORE_PASSWORD), false); - ps = filesymm.enpass(ps); - psCredProps.println(ps); + psCredProps.print(Config.CADI_TRUSTSTORE_PASSWORD); + psCredProps.print("=enc:"); + ps = pa.decrypt(pa.getProperty(Config.CADI_TRUSTSTORE_PASSWORD), false); + ps = filesymm.enpass(ps); + psCredProps.println(ps); + } + +// String cadi_x509_issuers = pa.getProperty(Config.CADI_X509_ISSUERS); +// if(cadi_x509_issuers!=null) { +// psCredProps.print(Config.CADI_X509_ISSUERS); +// psCredProps.print('='); +// psCredProps.println(cadi_x509_issuers); +// } + try { - Future acf = aafcon.client(new SingleEndpointLocator(locator)) - .read("/configure/"+fqi+"/aaf", configDF); - if(acf.get(TIMEOUT)) { - // out.println(acf.value.getName()); - for(Props props : acf.value.getProps()) { - psProps.println(props.getTag() + '=' + props.getValue()); + if(aafcon!=null) { // get Properties from Remote AAF + final String locator = getProperty(pa,aafcon.env,false,Config.AAF_LOCATE_URL,"AAF Locator URL: "); + + Future acf = aafcon.client(new SingleEndpointLocator(locator)) + .read("/configure/"+fqi+"/aaf", configDF); + if(acf.get(TIMEOUT)) { + PrintStream pstemp; + for(Props props : acf.value.getProps()) { + if(Config.CADI_X509_ISSUERS.equals(props.getTag())) { + pstemp=psCredProps; + } else { + pstemp = psProps; + } + pstemp.print(props.getTag()); + pstemp.print('='); + pstemp.println(props.getValue()); + } + ok = true; + } else if(acf.code()==401){ + trans.error().log("Bad Password sent to AAF"); + } else { + trans.error().log(errMsg.toMsg(acf)); } - ok = true; - } else if(acf.code()==401){ - trans.error().log("Bad Password sent to AAF"); } else { - trans.error().log(errMsg.toMsg(acf)); + String cpf = pa.getProperty(Config.CADI_PROP_FILES); + if(cpf!=null){ + for(String f : Split.split(File.pathSeparatorChar, cpf)) { + System.out.format("Reading %s\n",f); + FileInputStream fis = new FileInputStream(f); + try { + Properties props = new Properties(); + props.load(fis); + PrintStream pstemp; + String key,value; + for(Entry prop : props.entrySet()) { + key = prop.getKey().toString(); + if(Config.CADI_X509_ISSUERS.equals(key)) { + pstemp=psCredProps; + value = prop.getValue().toString(); + } else if(key.endsWith("_password")){ + if(Config.AAF_APPPASS.equals(key) || Config.CADI_TRUSTSTORE_PASSWORD.equals(key)) { + continue; + } + value = "enc:" + filesymm.enpass(prop.getValue().toString()); + pstemp = psCredProps; + } else if(Config.CADI_TRUSTSTORE.equals(key)) { + continue; + } else { + value = prop.getValue().toString(); + pstemp = psProps; + } + pstemp.print(key); + pstemp.print('='); + pstemp.println(value); + } + } finally { + fis.close(); + } + } + } + ok = true; } } finally { psProps.close();