@Test public void testConnectSharedAccessSignaturePrompt() throws Exception { final Host host = new Host(new AzureProtocol() { @Override public boolean isUsernameConfigurable() { return false; } @Override public boolean isPasswordConfigurable() { return false; } @Override public boolean isTokenConfigurable() { return true; } }, "kahy9boj3eib.blob.core.windows.net", new Credentials( null, null, "?sv=2017-07-29&ss=bfqt&srt=sco&sp=rwdlacup&se=2030-05-20T04:29:30Z&st=2018-05-09T20:29:30Z&spr=https&sig=invalidbMKAZ3tXmX%2B56%2Bb5JhHAeWnMOpMp%2BoYlHDIAZVAjHzE%3D")); final AzureSession session = new AzureSession(host); final AtomicBoolean prompt = new AtomicBoolean(); final LoginConnectionService connect = new LoginConnectionService(new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException { if(prompt.get()) { throw new LoginCanceledException(); } try { return new Credentials(null, "?sv=2017-07-29&ss=bfqt&srt=sco&sp=rwdlacup&se=2030-05-20T04:29:30Z&st=2018-05-09T20:29:30Z&spr=https&sig=bMKAZ3tXmX%2B56%2Bb5JhHAeWnMOpMp%2BoYlHDIAZVAjHzE%3D"); } finally { prompt.set(true); } } }, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()); connect.connect(session, PathCache.empty(), new DisabledCancelCallback()); assertTrue(session.isConnected()); session.close(); assertFalse(session.isConnected()); }
@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);  }