/** throws if there are any problems */ public OsCredential checkNotEmpty() { checkNoErrors(); if (!hasKey() && !hasPassword()) { if (warningMessages.size()>0) throw new IllegalStateException("Could not find credentials: "+warningMessages); else throw new IllegalStateException("Could not find credentials"); } return this; }
public void testPreferPublicKeyDataOverFileAndNoPrivateKeyRequired() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PUBLIC_KEY_DATA, "mydata"); config.put(LocationConfigKeys.PUBLIC_KEY_FILE, SSH_PUBLIC_KEY_FILE); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, ""); LocationConfigUtils.OsCredential creds = LocationConfigUtils.getOsCredential(config); String data = creds.getPublicKeyData(); assertEquals(data, "mydata"); Assert.assertNull(creds.getPreferredCredential()); Assert.assertFalse(creds.hasPassword()); Assert.assertFalse(creds.hasKey()); // and not even any warnings here Assert.assertTrue(creds.getWarningMessages().isEmpty()); }
/** if a password is available, and either this is preferred over a key or there is no key */ public boolean isUsingPassword() { return hasPassword() && (!hasKey() || preferPassword); }
/** if there is no credential (ignores public key) */ public boolean isEmpty() { return !hasKey() && !hasPassword(); } public boolean hasKey() {