+ public static void main(String[] args) {
+ int exitCode = 0;
+ doExit = true;
+ if (args.length>0 && "cadi".equals(args[0])) {
+ String[] newArgs = new String[args.length-1];
+ System.arraycopy(args, 1, newArgs, 0, newArgs.length);
+ if (newArgs.length==0) {
+ System.out.println(HASHES);
+ System.out.println("Note: Cadi CmdLine is a separate component. When running with\n\t"
+ + "Agent, always preface with \"cadi\",\n\tex: cadi keygen [<keyfile>]");
+ System.out.println(HASHES);
+ }
+ CmdLine.main(newArgs);
+ } else {
+ try {
+ AAFSSO aafsso=null;
+ PropAccess access;
+
+ if (args.length>1 && args[0].equals("validate") ) {
+ int idx = args[1].indexOf('=');
+ aafsso = null;
+ access = new PropAccess(
+ (idx<0?Config.CADI_PROP_FILES:args[1].substring(0, idx))+
+ '='+
+ (idx<0?args[1]:args[1].substring(idx+1)));
+ } else {
+ aafsso= new AAFSSO(args, new AAFSSO.ProcessArgs() {
+ @Override
+ public Properties process(String[] args, Properties props) {
+ if (args.length>1) {
+ if (!args[0].equals("keypairgen")) {
+ props.put(Config.AAF_APPID, args[1]);
+ }
+ }
+ return props;
+ }
+ });
+ access = aafsso.access();
+ }
+
+ if (aafsso!=null && aafsso.loginOnly()) {
+ aafsso.setLogDefault();
+ aafsso.writeFiles();
+ System.out.println("AAF SSO information created in ~/.aaf");
+ } else {
+ env = new RosettaEnv(access.getProperties());
+ Deque<String> cmds = new ArrayDeque<String>();
+ for (String p : args) {
+ int eq;
+ if ("-noexit".equalsIgnoreCase(p)) {
+ doExit = false;
+ } else if ((eq=p.indexOf('=')) < 0) {
+ cmds.add(p);
+ } else {
+ access.setProperty(p.substring(0,eq), p.substring(eq+1));
+ }
+ }
+
+ if (cmds.size()==0) {
+ if (aafsso!=null) {
+ aafsso.setLogDefault();
+ }
+ // NOTE: CHANGE IN CMDS should be reflected in AAFSSO constructor, to get FQI->aaf-id or not
+ System.out.println("Usage: java -jar <cadi-aaf-*-full.jar> cmd [<tag=value>]*");
+ System.out.println(" create <FQI> [<machine>]");
+ System.out.println(" read <FQI> [<machine>]");
+ System.out.println(" update <FQI> [<machine>]");
+ System.out.println(" delete <FQI> [<machine>]");
+ System.out.println(" copy <FQI> <machine> <newmachine>[,<newmachine>]*");
+ System.out.println(" place <FQI> [<machine>]");
+ System.out.println(" showpass <FQI> [<machine>]");
+ System.out.println(" check <FQI> [<machine>]");
+ System.out.println(" keypairgen <FQI>");
+ System.out.println(" config <FQI>");
+ System.out.println(" validate <NS>.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\"");
+ System.out.println(" cadi <cadi tool params, see -?>");
+
+ if (doExit) {
+ System.exit(1);
+ }
+ }
+
+ TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, "5000"));
+
+ reqDF = env.newDataFactory(CertificateRequest.class);
+ artifactsDF = env.newDataFactory(Artifacts.class);
+ certDF = env.newDataFactory(CertInfo.class);
+ configDF = env.newDataFactory(Configuration.class);
+ permDF = env.newDataFactory(Perms.class);
+ errMsg = new ErrMessage(env);
+
+ placeArtifact = new HashMap<>();
+ placeArtifact.put(JKS, new PlaceArtifactInKeystore(JKS));
+ placeArtifact.put(PKCS12, new PlaceArtifactInKeystore(PKCS12));
+ placeArtifact.put(FILE, new PlaceArtifactInFiles());
+ placeArtifact.put(PRINT, new PlaceArtifactOnStream(System.out));
+ placeArtifact.put(SCRIPT, new PlaceArtifactScripts());
+
+ Trans trans = env.newTrans();
+ String token;
+ if ((token=access.getProperty("oauth_token"))!=null) {
+ trans.setProperty("oauth_token", token);
+ }
+ try {
+ if (aafsso!=null) {
+ // show Std out again
+ aafsso.setLogDefault();
+ aafsso.setStdErrDefault();
+
+ /*urls=*/loadURLs(access);
+ aafsso.writeFiles();
+ }
+
+
+
+ String cmd = cmds.removeFirst();
+ switch(cmd) {
+ case "place":
+ placeCerts(trans,aafcon(access),cmds);
+ break;
+ case "create":
+ createArtifact(trans, aafcon(access),cmds);
+ break;
+ case "read":
+ readArtifact(trans, aafcon(access), cmds);
+ break;
+ case "copy":
+ copyArtifact(trans, aafcon(access), cmds);
+ break;
+ case "update":
+ updateArtifact(trans, aafcon(access), cmds);
+ break;
+ case "delete":
+ deleteArtifact(trans, aafcon(access), cmds);
+ break;
+ case "showpass":
+ showPass(trans, aafcon(access), cmds);
+ break;
+ case "keypairgen":
+ keypairGen(trans, access, cmds);
+ break;
+ case "config":
+ config(trans,access,args,cmds);
+ break;
+ case "validate":
+ validate(access);
+ break;
+ case "check":
+ try {
+ exitCode = check(trans,aafcon(access),cmds);
+ } catch (Exception e) {
+ exitCode = 1;
+ throw e;
+ }
+ break;
+ default:
+ AAFSSO.cons.printf("Unknown command \"%s\"\n", cmd);
+ }
+ } finally {
+ StringBuilder sb = new StringBuilder();
+ trans.auditTrail(4, sb, Trans.REMOTE);
+ if (sb.length()>0) {
+ trans.info().log("Trans Info\n",sb);
+ }
+ }
+ if (aafsso!=null) {
+ aafsso.close();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ if (exitCode != 0 && doExit) {
+ System.exit(exitCode);
+ }
+ }
+
+ public synchronized static Map<String,String> loadURLs(Access access) throws UnknownHostException, CadiException {
+ if(aaf_urls==null) {
+ Map<String,String> rv = new HashMap<>();
+ RegistrationPropHolder rph = new RegistrationPropHolder(access, 0);
+ String dot_le = access.getProperty(Config.AAF_LOCATOR_CONTAINER,null);
+ dot_le=dot_le==null?"":'.'+dot_le;
+ String version = access.getProperty(Config.AAF_API_VERSION,Config.AAF_DEFAULT_API_VERSION);
+ for(String u : new String[] {"aaf","locate","oauth","cm","gui","fs","hello","token","introspect"}) {
+ String tag;
+ String append=null;
+ switch(u) {
+ case "aaf": tag = Config.AAF_URL; break;
+ case "locate":tag = Config.AAF_LOCATE_URL; break;
+ case "oauth": tag = Config.AAF_URL_OAUTH; break;
+ case "token": tag = Config.AAF_OAUTH2_TOKEN_URL; append="/token"; break;
+ case "introspect": tag = Config.AAF_OAUTH2_INTROSPECT_URL; append="/introspect"; break;
+ case "cm": tag = Config.AAF_URL_CM; break;
+ case "gui": tag = Config.AAF_URL_GUI; break;
+ case "fs": tag = Config.AAF_URL_FS; break;
+ case "hello": tag = Config.AAF_URL_HELLO; break;
+ default:
+ tag = "aaf_url_" + u;
+ }
+ String value;
+ if((value=access.getProperty(tag,null))==null) {
+ String proto = "fs".equals(u)?"http://":"https://";
+ String lhost;
+ if("locate".equals(u)) {
+ lhost=rph.default_fqdn;
+ } else {
+ lhost=Config.AAF_LOCATE_URL_TAG;
+ }
+ value = rph.replacements("Agent:loadURLs",
+ proto + lhost + "/%CNS.%AAF_NS." + ("aaf".equals(u)?"service":u) + ':' + version,
+ null,dot_le);
+ if(append!=null) {
+ value+=append;
+ }
+ }
+ rv.put(tag, value);
+ };
+ aaf_urls = rv;