From 9ec2895301056a9e8967eadb139e56f03776fe26 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Thu, 12 Jul 2018 11:14:10 -0500 Subject: Configuration Agent and MS for AAF Issue-ID: AAF-361 Change-Id: I26f3d49e3d7eae4a932489bd677cf0b903fb7977 Signed-off-by: Instrumental --- cadi/aaf/pom.xml | 2 +- .../java/org/onap/aaf/cadi/configure/Agent.java | 139 +++++++++++++++++---- 2 files changed, 113 insertions(+), 28 deletions(-) (limited to 'cadi') diff --git a/cadi/aaf/pom.xml b/cadi/aaf/pom.xml index aa3899aa..2a7cd058 100644 --- a/cadi/aaf/pom.xml +++ b/cadi/aaf/pom.xml @@ -194,7 +194,7 @@ tests - org.onap.aaf.cadi.cm.CmAgent + org.onap.aaf.cadi.configure.Agent true 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(); -- cgit 1.2.3-korg