List of usage examples for org.apache.commons.httpclient.auth CredentialsNotAvailableException getMessage
public String getMessage()
From source file:ucar.nc2.util.net.EasySSLProtocolSocketFactory.java
private SSLContext createSSLContext(HttpConnectionParams params, String host, int port) throws HTTPException { SSLContext sslcontext = null; KeyManager[] keymanagers = null; KeyStore keystore = null;// www . j av a 2 s. co m KeyStore truststore = null; TrustManager[] trustmanagers = null; String keypassword = null; String keypath = null; String trustpassword = null; String trustpath = null; try { // Get the HTTPAuthProvider HTTPAuthProvider provider; provider = (HTTPAuthProvider) params.getParameter(CredentialsProvider.PROVIDER); if (provider == null) return stdauthenticate(); // Abuse the getCredentials() api Credentials creds = null; try { creds = provider.getCredentials(HTTPSSLScheme.Default, null, 0, false); if (creds == null) return stdauthenticate(); } catch (CredentialsNotAvailableException e) { return stdauthenticate(); } HTTPSSLProvider sslprovider = (creds == null ? null : (HTTPSSLProvider) creds); if (sslprovider == null) return stdauthenticate(); keypath = (String) sslprovider.getKeystore(); keypassword = (String) sslprovider.getKeypassword(); trustpath = (String) sslprovider.getTruststore(); trustpassword = (String) sslprovider.getTrustpassword(); keystore = buildstore(keypath, keypassword, "key"); if (keystore != null) { KeyManagerFactory kmfactory = KeyManagerFactory.getInstance("SunX509"); kmfactory.init(keystore, keypassword.toCharArray()); keymanagers = kmfactory.getKeyManagers(); } truststore = buildstore(trustpath, trustpassword, "trust"); if (truststore != null) { //TrustManagerFactory trfactory = TrustManagerFactory.getInstance("SunX509"); //trfactory.init(truststore, trustpassword.toCharArray()); //trustmanagers = trfactory.getTrustManagers(); trustmanagers = new TrustManager[] { new EasyX509TrustManager(truststore) }; } else { trustmanagers = new TrustManager[] { new EasyX509TrustManager(null) }; } sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; } catch (KeyManagementException e) { throw new HTTPException("Key Management exception: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { throw new HTTPException("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { throw new HTTPException("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { throw new HTTPException("Key management exception: " + e.getMessage()); } catch (IOException e) { throw new HTTPException("I/O error reading keystore/truststore file: " + e.getMessage()); } }