@Test(expected = LoginCanceledException.class) public void testConnectInvalidKey() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials( System.getProperties().getProperty("azure.account"), "6h9BmTcabGajIE/AVGzgu9JcC15JjrzkjdAIe+2daRK8XlyVdYT6zHtFMwXOtrlCw74jX9R0w4GN56vKQjOpVA==" )); final AzureSession session = new AzureSession(host); new LoginConnectionService(new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, String username, String title, String reason, LoginOptions options) throws LoginCanceledException { assertEquals("Login kahy9boj3eib.blob.core.windows.net", title); assertEquals("Login failed. Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. Please contact your web hosting service provider for assistance.", reason); return super.prompt(bookmark, username, title, reason, options); } }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()).connect(session, PathCache.empty(), new DisabledCancelCallback()); }
@Override public CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException { try { final StorageCredentials credentials; if(host.getCredentials().isTokenAuthentication()) { credentials = new StorageCredentialsSharedAccessSignature(host.getCredentials().getToken()); } else { credentials = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null"); } final URI uri = new URI(String.format("%s: final CloudBlobClient client = new CloudBlobClient(uri, credentials); client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER)); final BlobRequestOptions options = new BlobRequestOptions(); options.setRetryPolicyFactory(new RetryNoRetry()); context.setLoggingEnabled(true); context.setLogger(LoggerFactory.getLogger(log.getName())); context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap( HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get())) ); context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(final SendingRequestEvent event) { if(event.getConnectionObject() instanceof HttpsURLConnection) { final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject(); connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key)); connection.setHostnameVerifier(new DisabledX509HostnameVerifier()); } } }); switch(proxy.getType()) { case SOCKS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use SOCKS proxy %s", proxy)); } final java.net.Proxy socksProxy = new java.net.Proxy( java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(socksProxy); break; } case HTTP: case HTTPS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use HTTP proxy %s", proxy)); } final java.net.Proxy httpProxy = new java.net.Proxy( java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(httpProxy); break; } } return client; } catch(URISyntaxException e) { throw new LoginFailureException(e.getMessage(), e); } }
AzureSession extends SSLSession<CloudBlobClient> { @Override public CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException { try { final StorageCredentials credentials; if(host.getCredentials().isTokenAuthentication()) { credentials = new StorageCredentialsSharedAccessSignature(host.getCredentials().getToken()); } else { credentials = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null"); } final URI uri = new URI(String.format("%s: final CloudBlobClient client = new CloudBlobClient(uri, credentials); client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER)); final BlobRequestOptions options = new BlobRequestOptions(); options.setRetryPolicyFactory(new RetryNoRetry()); context.setLoggingEnabled(true); context.setLogger(LoggerFactory.getLogger(log.getName())); context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap( HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get())) ); context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(final SendingRequestEvent event) { if(event.getConnectionObject() instanceof HttpsURLConnection) { final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject(); connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key)); connection.setHostnameVerifier(new DisabledX509HostnameVerifier()); } } }); switch(proxy.getType()) { case SOCKS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use SOCKS proxy %s", proxy)); } final java.net.Proxy socksProxy = new java.net.Proxy( java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(socksProxy); break; } case HTTP: case HTTPS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use HTTP proxy %s", proxy)); } final java.net.Proxy httpProxy = new java.net.Proxy( java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(httpProxy); break; } } return client; } catch(URISyntaxException e) { throw new LoginFailureException(e.getMessage(), e); } } }
AzureSession extends SSLSession<CloudBlobClient> { @Override public CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException { try { final StorageCredentials credentials; if(host.getCredentials().isTokenAuthentication()) { credentials = new StorageCredentialsSharedAccessSignature(host.getCredentials().getToken()); } else { credentials = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null"); } final URI uri = new URI(String.format("%s: final CloudBlobClient client = new CloudBlobClient(uri, credentials); client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER)); final BlobRequestOptions options = new BlobRequestOptions(); options.setRetryPolicyFactory(new RetryNoRetry()); context.setLoggingEnabled(true); context.setLogger(LoggerFactory.getLogger(log.getName())); context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap( HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get())) ); context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(final SendingRequestEvent event) { if(event.getConnectionObject() instanceof HttpsURLConnection) { final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject(); connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key)); connection.setHostnameVerifier(new DisabledX509HostnameVerifier()); } } }); switch(proxy.getType()) { case SOCKS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use SOCKS proxy %s", proxy)); } final java.net.Proxy socksProxy = new java.net.Proxy( java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(socksProxy); break; } case HTTP: case HTTPS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use HTTP proxy %s", proxy)); } final java.net.Proxy httpProxy = new java.net.Proxy( java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(httpProxy); break; } } return client; } catch(URISyntaxException e) { throw new LoginFailureException(e.getMessage(), e); } } AzureSession(final Host h);  AzureSession(final Host h, final X509TrustManager trust, final X509KeyManager key); }
AzureSession extends SSLSession<CloudBlobClient> { @Override public CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException { try { final StorageCredentials credentials; if(host.getCredentials().isTokenAuthentication()) { credentials = new StorageCredentialsSharedAccessSignature(host.getCredentials().getToken()); } else { credentials = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null"); } final URI uri = new URI(String.format("%s: final CloudBlobClient client = new CloudBlobClient(uri, credentials); client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER)); final BlobRequestOptions options = new BlobRequestOptions(); options.setRetryPolicyFactory(new RetryNoRetry()); context.setLoggingEnabled(true); context.setLogger(LoggerFactory.getLogger(log.getName())); context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap( HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get())) ); context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(final SendingRequestEvent event) { if(event.getConnectionObject() instanceof HttpsURLConnection) { final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject(); connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key)); connection.setHostnameVerifier(new DisabledX509HostnameVerifier()); } } }); switch(proxy.getType()) { case SOCKS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use SOCKS proxy %s", proxy)); } final java.net.Proxy socksProxy = new java.net.Proxy( java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(socksProxy); break; } case HTTP: case HTTPS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use HTTP proxy %s", proxy)); } final java.net.Proxy httpProxy = new java.net.Proxy( java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(httpProxy); break; } } return client; } catch(URISyntaxException e) { throw new LoginFailureException(e.getMessage(), e); } } AzureSession(final Host h);  AzureSession(final Host h, final X509TrustManager trust, final X509KeyManager key); @Override CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt); @Override void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type); }
AzureSession extends SSLSession<CloudBlobClient> { @Override public CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException { try { final StorageCredentials credentials; if(host.getCredentials().isTokenAuthentication()) { credentials = new StorageCredentialsSharedAccessSignature(host.getCredentials().getToken()); } else { credentials = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null"); } final URI uri = new URI(String.format("%s: final CloudBlobClient client = new CloudBlobClient(uri, credentials); client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER)); final BlobRequestOptions options = new BlobRequestOptions(); options.setRetryPolicyFactory(new RetryNoRetry()); context.setLoggingEnabled(true); context.setLogger(LoggerFactory.getLogger(log.getName())); context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap( HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get())) ); context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(final SendingRequestEvent event) { if(event.getConnectionObject() instanceof HttpsURLConnection) { final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject(); connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key)); connection.setHostnameVerifier(new DisabledX509HostnameVerifier()); } } }); switch(proxy.getType()) { case SOCKS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use SOCKS proxy %s", proxy)); } final java.net.Proxy socksProxy = new java.net.Proxy( java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(socksProxy); break; } case HTTP: case HTTPS: { if(log.isInfoEnabled()) { log.info(String.format("Configured to use HTTP proxy %s", proxy)); } final java.net.Proxy httpProxy = new java.net.Proxy( java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort())); context.setProxy(httpProxy); break; } } return client; } catch(URISyntaxException e) { throw new LoginFailureException(e.getMessage(), e); } } AzureSession(final Host h);  AzureSession(final Host h, final X509TrustManager trust, final X509KeyManager key); @Override CloudBlobClient connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt); @Override void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel); @Override @SuppressWarnings("unchecked") T _getFeature(final Class<T> type);  }