public Builder password(String password) { this.password = Optional.fromNullable(password); if (privateKey == null) noPrivateKey(); return this; }
public Builder password(String password) { this.password = Optional.fromNullable(password); if (privateKey == null) noPrivateKey(); return this; }
public Builder password(String password) { this.password = Optional.fromNullable(password); if (privateKey == null) noPrivateKey(); return this; }
@Override public Builder toBuilder() { Builder builder = new Builder().user(identity).authenticateSudo(authenticateSudo); if (password != null) { if (password.isPresent()) { builder = builder.password(password.get()); } else { builder = builder.noPassword(); } } if (privateKey != null) { if (privateKey.isPresent()) { builder = builder.privateKey(privateKey.get()); } else { builder = builder.noPrivateKey(); } } return builder; }
@Override public Builder toBuilder() { Builder builder = new Builder().user(identity).authenticateSudo(authenticateSudo); if (password != null) { if (password.isPresent()) { builder = builder.password(password.get()); } else { builder = builder.noPassword(); } } if (privateKey != null) { if (privateKey.isPresent()) { builder = builder.privateKey(privateKey.get()); } else { builder = builder.noPrivateKey(); } } return builder; }
@Override public LoginCredentials apply(@Nullable PasswordDataAndPrivateKey dataAndKey) { if (dataAndKey == null) return null; try { KeySpec keySpec = Pems.privateKeySpec(dataAndKey.getPrivateKey()); KeyFactory kf = crypto.rsaKeyFactory(); PrivateKey privKey = kf.generatePrivate(keySpec); Cipher cipher = crypto.cipher("RSA"); cipher.init(Cipher.DECRYPT_MODE, privKey); byte[] cipherText = base64().decode(dataAndKey.getPasswordData().getPasswordData()); byte[] plainText = cipher.doFinal(cipherText); String password = new String(plainText, Charsets.US_ASCII); return LoginCredentials.builder() .user("Administrator") .password(password) .noPrivateKey() .build(); } catch(Exception e) { throw Throwables.propagate(e); } } }
protected NodeMetadata updateNodeWithCredentialsIfPresent(NodeMetadata node, RunScriptOptions options) { checkNotNull(node, "node"); Builder builder = LoginCredentials.builder(node.getCredentials()); if (options.getLoginUser() != null) builder.user(options.getLoginUser()); if (options.hasLoginPasswordOption()) { if (options.hasLoginPassword()) { builder.password(options.getLoginPassword()); } else { builder.noPassword(); } } if (options.hasLoginPrivateKeyOption()) { if (options.hasLoginPrivateKey()) { builder.privateKey(options.getLoginPrivateKey()); } else { builder.noPrivateKey(); } } if (options.shouldAuthenticateSudo() != null) builder.authenticateSudo(true); return NodeMetadataBuilder.fromNodeMetadata(node).credentials(builder.build()).build(); }
@Override public Builder toBuilder() { Builder builder = new Builder().user(identity).authenticateSudo(authenticateSudo); if (password != null) { if (password.isPresent()) { builder = builder.password(password.get()); } else { builder = builder.noPassword(); } } if (privateKey != null) { if (privateKey.isPresent()) { builder = builder.privateKey(privateKey.get()); } else { builder = builder.noPrivateKey(); } } return builder; }
@Override public Builder toBuilder() { Builder builder = new Builder().user(identity).authenticateSudo(authenticateSudo); if (password != null) { if (password.isPresent()) { builder = builder.password(password.get()); } else { builder = builder.noPassword(); } } if (privateKey != null) { if (privateKey.isPresent()) { builder = builder.privateKey(privateKey.get()); } else { builder = builder.noPrivateKey(); } } return builder; }
@Test(enabled = false) protected void tryBadPassword(String group, Credentials good) throws AssertionError { try { Map<? extends NodeMetadata, ExecResponse> responses = client.runScriptOnNodesMatching( runningInGroup(group), "echo I put a bad password", wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials( LoginCredentials.builder().user(good.identity).noPrivateKey().password("romeo").build())); assert responses.size() == 0 : "shouldn't pass with a bad password\n" + responses; } catch (AssertionError e) { throw e; } catch (RunScriptOnNodesException e) { assert Iterables.any(e.getNodeErrors().values(), Predicates.instanceOf(AuthorizationException.class)) : e + " not authexception!"; } }
@Override public Builder toBuilder() { Builder builder = new Builder().user(identity).authenticateSudo(authenticateSudo); if (password != null) { if (password.isPresent()) { builder = builder.password(password.get()); } else { builder = builder.noPassword(); } } if (privateKey != null) { if (privateKey.isPresent()) { builder = builder.privateKey(privateKey.get()); } else { builder = builder.noPrivateKey(); } } return builder; }
@Override public Builder toBuilder() { Builder builder = new Builder().user(identity).authenticateSudo(authenticateSudo); if (password != null) { if (password.isPresent()) { builder = builder.password(password.get()); } else { builder = builder.noPassword(); } } if (privateKey != null) { if (privateKey.isPresent()) { builder = builder.privateKey(privateKey.get()); } else { builder = builder.noPrivateKey(); } } return builder; }
@Test(enabled = false) protected void tryBadPassword(String group, Credentials good) throws AssertionError { try { Map<? extends NodeMetadata, ExecResponse> responses = client.runScriptOnNodesMatching( runningInGroup(group), "echo I put a bad password", wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials( LoginCredentials.builder().user(good.identity).noPrivateKey().password("romeo").build())); assert responses.size() == 0 : "shouldn't pass with a bad password\n" + responses; } catch (AssertionError e) { throw e; } catch (RunScriptOnNodesException e) { assert Iterables.any(e.getNodeErrors().values(), Predicates.instanceOf(AuthorizationException.class)) : e + " not authexception!"; } }
@Test public void testReboundConfigDoesNotContainId() throws Exception { rebind(); JcloudsLocation newLoc = (JcloudsLocation) newManagementContext.getLocationManager().getLocation(origLoc.getId()); ConfigBag newLocConfig = newLoc.config().getBag(); ConfigBag config = ConfigBag.newInstanceCopying(newLocConfig); assertNull(newLocConfig.getStringKey(("id"))); SshMachineLocation tempMachine = newLoc.createTemporarySshMachineLocation( HostAndPort.fromParts("localhost", 1234), LoginCredentials.builder().identity("myuser").password("mypass").noPrivateKey().build(), config); assertNotEquals(tempMachine.getId(), newLoc.getId()); } }
public Builder credential(String credential) { if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); return this; }
public Builder credential(String credential) { if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); return this; }
public Builder credential(String credential) { if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); return this; }
public Builder credential(String credential) { if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); return this; }
public Builder credential(String credential) { if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); return this; }
public Builder credential(String credential) { if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); return this; }