X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fsso%2FAAFSSO.java;h=a6a74103d10d40fce9fe9ef99915841138273acc;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=7c589ae3561706945353b11f7f606ab5454febf0;hpb=ff1417ff60baee231a28272f9a16ef2c9c8ea0a2;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java index 7c589ae3..a6a74103 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java @@ -36,14 +36,24 @@ import java.util.Properties; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.Symm; import org.onap.aaf.cadi.aaf.Defaults; +import org.onap.aaf.cadi.aaf.v2_0.AAFCon; +import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.configure.ArtifactDir; +import org.onap.aaf.cadi.locator.SingleEndpointLocator; import org.onap.aaf.cadi.util.MyConsole; import org.onap.aaf.cadi.util.SubStandardConsole; import org.onap.aaf.cadi.util.TheConsole; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.rosetta.env.RosettaDF; +import org.onap.aaf.misc.rosetta.env.RosettaEnv; + +import locate.v1_1.Configuration; +import locate.v1_1.Configuration.Props; public class AAFSSO { public static final MyConsole cons = TheConsole.implemented() ? new TheConsole() : new SubStandardConsole(); @@ -73,7 +83,7 @@ public class AAFSSO { public AAFSSO(String[] args) throws IOException, CadiException { this(args,new Properties()); } - + public AAFSSO(String[] args, ProcessArgs pa) throws IOException, CadiException { this(args,pa.process(args, new Properties())); } @@ -104,7 +114,7 @@ public class AAFSSO { propStream.close(); } } - + File dot_aaf_kf = new File(dot_aaf, "keyfile"); if (removeSSO) { @@ -133,9 +143,9 @@ public class AAFSSO { System.out.println("AAF SSO information removed"); } else { // Config.setDefaultRealm(access); - + if (!dot_aaf_kf.exists()) { - // This will create, as required, or reuse + // This will create, as required, or reuse ArtifactDir.getSymm(dot_aaf_kf); } @@ -145,9 +155,9 @@ public class AAFSSO { String[] naargs = new String[nargs.size()]; nargs.toArray(naargs); access = new PropAccess(os, naargs); - + if (loginOnly) { - for (String tag : new String[] {Config.AAF_APPID, Config.AAF_APPPASS, + for (String tag : new String[] {Config.AAF_APPID, Config.AAF_APPPASS, Config.CADI_ALIAS, Config.CADI_KEYSTORE,Config.CADI_KEYSTORE_PASSWORD,Config.CADI_KEY_PASSWORD}) { access.getProperties().remove(tag); diskprops.remove(tag); @@ -161,14 +171,14 @@ public class AAFSSO { // } // touchDiskprops=true; } - + String keyfile = access.getProperty(Config.CADI_KEYFILE); // in case its CertificateMan props if (keyfile == null) { access.setProperty(Config.CADI_KEYFILE, dot_aaf_kf.getAbsolutePath()); addProp(Config.CADI_KEYFILE,dot_aaf_kf.getAbsolutePath()); } - - + + String alias, appID; alias = access.getProperty(Config.CADI_ALIAS); if (alias==null) { @@ -178,22 +188,26 @@ public class AAFSSO { user=alias; appID=null; } - + + String aaf_container_ns = ""; if (appID!=null) { - diskprops.setProperty(Config.AAF_APPID,appID); - if( access.getProperty(Config.AAF_APPPASS)==null) { - char[] password = cons.readPassword("Password for %s: ", appID); - if(password.length>0) { - String app_pass = access.encrypt(new String(password)); - access.setProperty(Config.AAF_APPPASS,app_pass); - diskprops.setProperty(Config.AAF_APPPASS,app_pass); - } - } + if( access.getProperty(Config.AAF_APPPASS)==null) { + appID = user = cons.readLine("Deployer ID [%s]: ", user); + access.setProperty(Config.AAF_APPID,appID); + char[] password = cons.readPassword("Password for %s: ", user); + if(password.length>0) { + String app_pass = access.encrypt(new String(password)); + access.setProperty(Config.AAF_APPPASS,app_pass); + diskprops.setProperty(Config.AAF_APPPASS,app_pass); + } + aaf_container_ns = cons.readLine("Container Namespace (blank if none)? [\"\"]: ", aaf_container_ns); + } + diskprops.setProperty(Config.AAF_APPID,appID); } - + String keystore=access.getProperty(Config.CADI_KEYSTORE); String keystore_pass=access.getProperty(Config.CADI_KEYSTORE_PASSWORD); - + if (user==null || (alias!=null && (keystore==null || keystore_pass==null))) { String select = null; String name; @@ -210,7 +224,7 @@ public class AAFSSO { encrypted_pass= access.encrypt(new String(password)); access.setProperty(Config.CADI_KEYSTORE_PASSWORD, encrypted_pass); addProp(Config.CADI_KEYSTORE_PASSWORD, encrypted_pass); - + // TODO READ Aliases out of Keystore? user = alias = cons.readLine("Keystore alias: "); access.setProperty(Config.CADI_ALIAS, user); @@ -237,8 +251,8 @@ public class AAFSSO { keystore_pass = encrypted_pass; } } - - + + if (alias!=null) { use_X509 = true; } else { @@ -288,7 +302,7 @@ public class AAFSSO { if (user == null) { err = new StringBuilder("Add -D" + Config.AAF_APPID + "= "); } - + if (encrypted_pass == null && alias == null) { if (err == null) { err = new StringBuilder(); @@ -297,37 +311,7 @@ public class AAFSSO { } err.append("-D" + Config.AAF_APPPASS + "= "); } - - String locateUrl = access.getProperty(Config.AAF_LOCATE_URL); - if (locateUrl==null) { - locateUrl=AAFSSO.cons.readLine("AAF Locator URL=https://"); - if (locateUrl==null || locateUrl.length()==0) { - err = new StringBuilder(Config.AAF_LOCATE_URL); - err.append(" is required."); - ok = false; - return; - } else { - locateUrl="https://"+locateUrl; - } - access.setProperty(Config.AAF_LOCATE_URL, locateUrl); - addProp(Config.AAF_LOCATE_URL, locateUrl); - } - - final String apiVersion = access.getProperty(Config.AAF_API_VERSION, Config.AAF_DEFAULT_API_VERSION); - final String aaf_root_ns = access.getProperty(Config.AAF_ROOT_NS); - String locateRoot; - if(aaf_root_ns==null) { - locateRoot=Defaults.AAF_ROOT; - } else { - locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS." + aaf_root_ns; - } - if(access.getProperty(Config.AAF_URL)==null) { - - access.setProperty(Config.AAF_URL, locateRoot+".service:"+apiVersion); - } - if(access.getProperty(Config.AAF_URL_CM)==null) { - access.setProperty(Config.AAF_URL_CM, locateRoot+".cm:"+apiVersion); - } + String cadiLatitude = access.getProperty(Config.CADI_LATITUDE); if (cadiLatitude==null) { System.out.println("# If you do not know your Global Coordinates, we suggest bing.com/maps"); @@ -337,7 +321,7 @@ public class AAFSSO { } access.setProperty(Config.CADI_LATITUDE, cadiLatitude); addProp(Config.CADI_LATITUDE, cadiLatitude); - + } String cadiLongitude = access.getProperty(Config.CADI_LONGITUDE); if (cadiLongitude==null) { @@ -348,14 +332,14 @@ public class AAFSSO { access.setProperty(Config.CADI_LONGITUDE, cadiLongitude); addProp(Config.CADI_LONGITUDE, cadiLongitude); } - + String cadi_truststore = access.getProperty(Config.CADI_TRUSTSTORE); if (cadi_truststore==null) { - String name; + String name; String select; for (File tsf : dot_aaf.listFiles()) { name = tsf.getName(); - if (name.contains("trust") && + if (name.contains("trust") && (name.endsWith(".jks") || name.endsWith(".p12"))) { select = cons.readLine("Use %s for TrustStore? (y/n):",tsf.getName()); if ("y".equalsIgnoreCase(select)) { @@ -381,6 +365,55 @@ public class AAFSSO { } ok = err==null; } + String locateUrl = Config.getAAFLocateUrl(access); + if (locateUrl==null) { + locateUrl=AAFSSO.cons.readLine("AAF Locator URL=https://"); + if (locateUrl==null || locateUrl.length()==0) { + err = new StringBuilder(Config.AAF_LOCATE_URL); + err.append(" is required."); + ok = false; + return; + } else { + locateUrl="https://"+locateUrl; + } + access.setProperty(Config.AAF_LOCATE_URL, locateUrl); + addProp(Config.AAF_LOCATE_URL, locateUrl); + try { + if(access.getProperty(Config.AAF_URL)==null) { + access.setProperty(Config.AAF_URL, Defaults.AAF_ROOT+".service:"+Defaults.AAF_VERSION); + } + AAFCon aafCon = AAFCon.newInstance(access); + Future acf; + RosettaDF configDF = new RosettaEnv().newDataFactory(Configuration.class); + acf = aafCon.client(new SingleEndpointLocator(locateUrl)) + .read("/configure/"+user+"/aaf", configDF); + if (acf.get(aafCon.connTimeout)) { + for(Props p : acf.value.getProps()) { + addProp(p.getTag(),p.getValue()); + if(access.getProperty(p.getTag())==null) { + access.setProperty(p.getTag(), p.getValue()); + } + } + } else { + access.log(Level.INFO,acf.body()); + } + } catch (LocatorException | APIException e) { + access.log(e); + } + } + + final String apiVersion = access.getProperty(Config.AAF_API_VERSION, Config.AAF_DEFAULT_API_VERSION); + final String aaf_root_ns = access.getProperty(Config.AAF_ROOT_NS); + String locateRoot; + if(aaf_root_ns==null) { + locateRoot=Defaults.AAF_ROOT; + } else { + locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS." + aaf_root_ns; + } + if(access.getProperty(Config.AAF_URL)==null) { + access.setProperty(Config.AAF_URL, locateRoot+".service:"+apiVersion); + } + writeFiles(); } @@ -488,7 +521,7 @@ public class AAFSSO { } return larg; } - + private void setReadonly(File file) { file.setExecutable(false, false); file.setWritable(false, false); @@ -499,7 +532,7 @@ public class AAFSSO { public boolean ok() { return ok; } - + public static interface ProcessArgs { public Properties process(final String[] args, final Properties props); }