public LensClient(Credentials cred) { this(cred.getUsername(), cred.getPassword()); }
/** * Prompt. * * @return the credentials */ public static Credentials prompt() { Console console = System.console(); if (console == null) { System.err.println("Couldn't get Console instance"); System.exit(-1); } console.printf("username:"); String username = console.readLine().trim(); char[] passwordArray = console.readPassword("password for %s:", username); String password = new String(passwordArray); return new Credentials(username, password); } }
public LensClient getClient() { if (client == null) { try { client = new LensClient(); } catch (LensClientServerConnectionException e) { if (e.getErrorCode() != 401) { explainFailedAttempt(e); throw e; } // Connecting without password prompt failed. for (int i = 0; i < MAX_RETRIES; i++) { try { client = new LensClient(Credentials.prompt()); break; } catch (LensClientServerConnectionException lensClientServerConnectionException) { explainFailedAttempt(lensClientServerConnectionException); if (i == MAX_RETRIES - 1) { throw lensClientServerConnectionException; } } } } } return client; }
/** * Prompt. * * @return the credentials */ public static Credentials prompt() { Console console = System.console(); if (console == null) { System.err.println("Couldn't get Console instance"); System.exit(-1); } console.printf("username:"); String username = console.readLine().trim(); char[] passwordArray = console.readPassword("password for %s:", username); String password = new String(passwordArray); return new Credentials(username, password); } }
public LensClient getClient() { if (client == null) { try { client = new LensClient(); } catch (LensClientServerConnectionException e) { if (e.getErrorCode() != 401) { explainFailedAttempt(e); throw e; } // Connecting without password prompt failed. for (int i = 0; i < MAX_RETRIES; i++) { try { client = new LensClient(Credentials.prompt()); break; } catch (LensClientServerConnectionException lensClientServerConnectionException) { explainFailedAttempt(lensClientServerConnectionException); if (i == MAX_RETRIES - 1) { throw lensClientServerConnectionException; } } } } } return client; }
public LensClient(Credentials cred) { this(cred.getUsername(), cred.getPassword()); }