DefaultConnectivityResolver extends InitializerPatternForConfigurable implements ConnectivityResolver, EntityInitializer { protected boolean checkCredential( JcloudsLocation location, HostAndPort hostAndPort, LoginCredentials credentials, ConfigBag config, boolean isWindows) { try { if (isWindows) { location.waitForWinRmAvailable(credentials, hostAndPort, config); } else { location.waitForSshable(hostAndPort, ImmutableList.of(credentials), config); } return true; } catch (IllegalStateException e) { return false; } } DefaultConnectivityResolver();  DefaultConnectivityResolver(Map<?, ?> params);  DefaultConnectivityResolver(final ConfigBag params); @Override void apply(EntityLocal entity); @Override ManagementAddressResolveResult resolve(
            JcloudsLocation location, NodeMetadata node, ConfigBag config, ConnectivityResolverOptions options); @Override String toString(); static final ConfigKey<NetworkMode> NETWORK_MODE; @Beta
    static final ConfigKey<Boolean> CHECK_CREDENTIALS; static final ConfigKey<Boolean> PUBLISH_NETWORKS; }
@Test public void testTestCredentialWithLinuxMachine() throws Exception { final String allowedUser = "Mr. Big"; RecordingSshTool.setCustomResponse(".*", new RecordingSshTool.CustomResponseGenerator() { @Override public RecordingSshTool.CustomResponse generate(RecordingSshTool.ExecParams execParams) throws Exception { boolean valid = allowedUser.equals(execParams.constructorProps.get("user")); return new RecordingSshTool.CustomResponse(valid ? 0 : 1, "", ""); } }); initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of()); DefaultConnectivityResolver customizer = new DefaultConnectivityResolver(); final ConfigBag config = ConfigBag.newInstanceExtending(jcloudsLocation.config().getBag(), ImmutableMap.of( JcloudsLocationConfig.WAIT_FOR_SSHABLE, "1ms", JcloudsLocationConfig.POLL_FOR_FIRST_REACHABLE_ADDRESS, "1ms")); assertTrue(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), LoginCredentials.builder().user(allowedUser).password("password1").build(), config, false)); assertFalse(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), credential, config, false)); }
@Test public void testTestCredentialWithWindowsMachine() throws Exception { final String allowedUser = "Mr. Big"; RecordingWinRmTool.setCustomResponse(".*", new RecordingWinRmTool.CustomResponseGenerator() { @Override public RecordingWinRmTool.CustomResponse generate(RecordingWinRmTool.ExecParams execParams) { boolean valid = allowedUser.equals(execParams.constructorProps.get("user")); return new RecordingWinRmTool.CustomResponse(valid ? 0 : 1, "", ""); } }); initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of()); DefaultConnectivityResolver customizer = new DefaultConnectivityResolver(); final ConfigBag config = ConfigBag.newInstanceExtending(jcloudsLocation.config().getBag(), ImmutableMap.of( JcloudsLocationConfig.WAIT_FOR_WINRM_AVAILABLE, "1ms", JcloudsLocationConfig.POLL_FOR_FIRST_REACHABLE_ADDRESS, "1ms")); assertTrue(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), LoginCredentials.builder().user(allowedUser).password("password1").build(), config, true)); assertFalse(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), credential, config, true)); }