/** * Establishes a connection to a Splunk service using a map of arguments. * This member creates a new {@code Service} instance and authenticates * the session using credentials passed in from the {@code args} map. * * @param args The {@code args} map. * @return A new {@code Service} instance. */ public static Service connect(Map<String, Object> args) { Service service = new Service(args); if (args.containsKey("username")) { service.login(); } return service; }
/** * Authenticates the {@code Service} instance with the username and password * that were specified when the instance was created. * * Three cases: * 1. If we have a cookie, but are missing username and/or password, login is noop * 2. If we don't have a cookie, and are missing username and/or password we can't login * 3. Otherwise login as usual * * @return The current {@code Service} instance. */ public Service login() { if (!this.cookieStore.isEmpty() && (this.username == null || this.password == null)) { return this; } else if (this.username == null || this.password == null) { throw new IllegalStateException("Missing username or password."); } else { return login(this.username, this.password); } }