當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyManagementException類代碼示例

本文整理匯總了Java中java.security.KeyManagementException的典型用法代碼示例。如果您正苦於以下問題:Java KeyManagementException類的具體用法?Java KeyManagementException怎麽用?Java KeyManagementException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KeyManagementException類屬於java.security包,在下文中一共展示了KeyManagementException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSocketFactory

import java.security.KeyManagementException; //導入依賴的package包/類
public SocketFactory createSocketFactory() {
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { this }, null);
        return sslContext.getSocketFactory();
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new RuntimeException("Failed to create a SSL socket factory");
    }
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:10,代碼來源:UserOverrideTrustManager.java

示例2: getConnctionManager

import java.security.KeyManagementException; //導入依賴的package包/類
public static PoolingHttpClientConnectionManager getConnctionManager(){

        Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
        try {
            SSLConnectionSocketFactory trustSelfSignedSocketFactory = new SSLConnectionSocketFactory(
                        new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
                        new TrustAllHostNameVerifier());
            socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory> create()
                    .register("http", new PlainConnectionSocketFactory())
                    .register("https", trustSelfSignedSocketFactory)
                    .build();
        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
            Data.logger.warn("", e);
        }
        
        PoolingHttpClientConnectionManager cm = (socketFactoryRegistry != null) ? 
                new PoolingHttpClientConnectionManager(socketFactoryRegistry):
                new PoolingHttpClientConnectionManager();
        
        // twitter specific options
        cm.setMaxTotal(2000);
        cm.setDefaultMaxPerRoute(200);
        
        return cm;
    }
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:27,代碼來源:ClientConnection.java

示例3: restTemplate

import java.security.KeyManagementException; //導入依賴的package包/類
@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .build();

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslConnectionSocketFactory)
            .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
            new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}
 
開發者ID:borysfan,項目名稱:websocket-poc,代碼行數:20,代碼來源:App.java

示例4: buildCertificateIgnoringSslContext

import java.security.KeyManagementException; //導入依賴的package包/類
/**
 * Will create a certificate-ignoring {@link SSLContext}. Please use with utmost caution as it undermines security,
 * but may be useful in certain testing or development scenarios.
 *
 * @return The SSLContext
 */
public static SSLContext buildCertificateIgnoringSslContext() {
	try {
		return SSLContexts
			.custom()
			.loadTrustMaterial(new TrustStrategy() {
				@Override
				public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
					return true;
				}
			})
			.build();
	}
	catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		throw new IllegalStateException("Unexpected exception while building the certificate-ignoring SSLContext.", e);
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:23,代碼來源:HttpClientUtils.java

示例5: prepare

import java.security.KeyManagementException; //導入依賴的package包/類
/**
		 * Prepare.
		 *
		 * @param requestURL the request URL
		 * @return the URL processor
		 * @throws IOException Signals that an I/O exception has occurred.
		 * @throws KeyStoreException 
		 * @throws CertificateException 
		 * @throws NoSuchAlgorithmException 
		 * @throws KeyManagementException 
		 */
		public URLProcessor prepare(URL requestURL) throws IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
//			System.out.println("requestURL=");
//			System.out.println(requestURL);

			connection = (HttpsURLConnection) requestURL.openConnection();
			connection.setInstanceFollowRedirects(false);
			Trust.trustSpecific(connection, truststoreFile);

			connection.setRequestMethod("GET");
			if (accessToken != null) {
				connection.setRequestProperty("Authorization", "Bearer " + accessToken);
			}

			if (uploadFile != null) {
				injectUpload();
			}

			return this;
		}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:31,代碼來源:OIDCAuthorization.java

示例6: createSslContext

import java.security.KeyManagementException; //導入依賴的package包/類
/**
 * Creates a SSLContext instance using the given information.
 *
 * @param keystore the full path to the keystore
 * @param keystorePasswd the keystore password
 * @param keystoreType the type of keystore (e.g., PKCS12, JKS)
 * @param protocol the protocol to use for the SSL connection
 *
 * @return a SSLContext instance
 * @throws KeyStoreException if any issues accessing the keystore
 * @throws IOException for any problems loading the keystores
 * @throws NoSuchAlgorithmException if an algorithm is found to be used but is unknown
 * @throws CertificateException if there is an issue with the certificate
 * @throws UnrecoverableKeyException if the key is insufficient
 * @throws KeyManagementException if unable to manage the key
 */
public static SSLContext createSslContext(
    final String keystore, final char[] keystorePasswd, final char[] keyPasswd, final String keystoreType, final String protocol)
        throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
        UnrecoverableKeyException, KeyManagementException {

    // prepare the keystore
    final KeyStore keyStore = KeyStoreUtils.getKeyStore(keystoreType);
    try (final InputStream keyStoreStream = new FileInputStream(keystore)) {
        keyStore.load(keyStoreStream, keystorePasswd);
    }
    final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    if (keyPasswd == null) {
        keyManagerFactory.init(keyStore, keystorePasswd);
    } else {
        keyManagerFactory.init(keyStore, keyPasswd);
    }

    // initialize the ssl context
    final SSLContext ctx = SSLContext.getInstance(protocol);
    ctx.init(keyManagerFactory.getKeyManagers(), new TrustManager[0], new SecureRandom());

    return ctx;

}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:41,代碼來源:SslContextFactory.java

示例7: getHttpClient

import java.security.KeyManagementException; //導入依賴的package包/類
public QMailHttpClient getHttpClient() throws MessagingException {
    if (httpClient == null) {
        httpClient = httpClientFactory.create();
        // Disable automatic redirects on the http client.
        httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);

        // Setup a cookie store for forms-based authentication.
        httpContext = new BasicHttpContext();
        authCookies = new BasicCookieStore();
        httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies);

        SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry();
        try {
            Scheme s = new Scheme("https", new WebDavSocketFactory(hostname, 443), 443);
            reg.register(s);
        } catch (NoSuchAlgorithmException nsa) {
            Timber.e(nsa, "NoSuchAlgorithmException in getHttpClient");
            throw new MessagingException("NoSuchAlgorithmException in getHttpClient: ", nsa);
        } catch (KeyManagementException kme) {
            Timber.e(kme, "KeyManagementException in getHttpClient");
            throw new MessagingException("KeyManagementException in getHttpClient: ", kme);
        }
    }
    return httpClient;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:26,代碼來源:WebDavStore.java

示例8: handleInteractions

import java.security.KeyManagementException; //導入依賴的package包/類
private void handleInteractions(Socket socket) throws IOException, KeyStoreException,
        NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException,
        UnexpectedCommandException {

    ImapInteraction interaction = interactions.pop();
    if (interaction instanceof ExpectedCommand) {
        readExpectedCommand((ExpectedCommand) interaction);
    } else if (interaction instanceof CannedResponse) {
        writeCannedResponse((CannedResponse) interaction);
    } else if (interaction instanceof CloseConnection) {
        clientSocket.close();
    } else if (interaction instanceof EnableCompression) {
        enableCompression(socket);
    } else if (interaction instanceof UpgradeToTls) {
        upgradeToTls(socket);
    }
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:18,代碼來源:MockImapServer.java

示例9: upgradeToTls

import java.security.KeyManagementException; //導入依賴的package包/類
private void upgradeToTls(Socket socket) throws KeyStoreException, IOException, NoSuchAlgorithmException,
        CertificateException, UnrecoverableKeyException, KeyManagementException {

    KeyStore keyStore = keyStoreProvider.getKeyStore();

    String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(defaultAlgorithm);
    keyManagerFactory.init(keyStore, keyStoreProvider.getPassword());

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

    SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
            socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
    sslSocket.setUseClientMode(false);
    sslSocket.startHandshake();

    input = Okio.buffer(Okio.source(sslSocket.getInputStream()));
    output = Okio.buffer(Okio.sink(sslSocket.getOutputStream()));
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:22,代碼來源:MockImapServer.java

示例10: OkHttpUtils

import java.security.KeyManagementException; //導入依賴的package包/類
private OkHttpUtils(long connectTimeOut, long readTimeOut, long writeTimeOut, int retrys) {
    OkHttpClient.Builder builder = getBuilder(connectTimeOut, readTimeOut, writeTimeOut, retrys);

    this.connectTimeOut = connectTimeOut;
    this.readTimeOut = readTimeOut;
    this.writeTimeOut = writeTimeOut;
    this.retrys = retrys;

    okHttpClient = builder.build();
    try {
        ssl(builder);
        okHttpsClient = builder.build();
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage());
    }
}
 
開發者ID:HujiangTechnology,項目名稱:Juice,代碼行數:18,代碼來源:OkHttpUtils.java

示例11: retrieveProviderMetadata

import java.security.KeyManagementException; //導入依賴的package包/類
/**
	 * Retrieve provider metadata.
	 * Provider configuration information
	 * Obtaining the provider configuration information can be done either out-of-band or using the optional discovery process:
	 *
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @throws ParseException the parse exception
	 * @throws KeyStoreException
	 * @throws CertificateException
	 * @throws NoSuchAlgorithmException
	 * @throws KeyManagementException
	 */
	public void retrieveProviderMetadata() throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		
		URL providerConfigurationURL = issuerURI.resolve(URLPATH_WELL_KNOWN_OPENID).toURL();
//		System.out.println(providerConfigurationURL);
		URLConnection conn = providerConfigurationURL.openConnection();

		if (trustStoreFile != null) {
			Trust.trustSpecific((HttpsURLConnection) conn, trustStoreFile);
		}
		InputStream stream = conn.getInputStream();
		// Read all data from URL
		String providerInfo = null;
		try (java.util.Scanner s = new java.util.Scanner(stream)) {
			providerInfo = s.useDelimiter("\\A").hasNext() ? s.next() : "";
		}
		setProviderMetadata(OIDCProviderMetadata.parse(providerInfo));
	}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:30,代碼來源:SimpleOIDCClient.java

示例12: getSSLSocketFactory

import java.security.KeyManagementException; //導入依賴的package包/類
/**
 * 獲取LayeredConnectionSocketFactory 使用ssl單向認證
 * 
 * @date 2015年7月17日
 * @return
 */
private LayeredConnectionSocketFactory getSSLSocketFactory() {
	try {
		SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {

			// 信任所有
			public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
				return true;
			}
		}).build();

		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
				SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		return sslsf;
	} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		logger.error(e.getMessage(), e);
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:25,代碼來源:HttpUtils.java

示例13: getSslSocketFactory

import java.security.KeyManagementException; //導入依賴的package包/類
public static SSLParams getSslSocketFactory(InputStream[] certificates, InputStream bksFile, String password) {
    SSLParams sslParams = new SSLParams();
    try {
        TrustManager[] trustManagers = prepareTrustManager(certificates);
        KeyManager[] keyManagers = prepareKeyManager(bksFile, password);
        SSLContext sslContext = SSLContext.getInstance("TLS");
        X509TrustManager trustManager = null;
        if (trustManagers != null) {
            trustManager = new MyTrustManager(chooseTrustManager(trustManagers));
        } else {
            trustManager = new UnSafeTrustManager();
        }
        sslContext.init(keyManagers, new TrustManager[]{trustManager}, null);
        sslParams.sSLSocketFactory = sslContext.getSocketFactory();
        sslParams.trustManager = trustManager;
        return sslParams;
    } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
        throw new AssertionError(e);
    }
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:21,代碼來源:HttpsUtils.java

示例14: initTrustedSSLSocketFactory

import java.security.KeyManagementException; //導入依賴的package包/類
/**
 * Initialize the factory with custom trustStore
 * @param trustStore KeyStore
 */
public static synchronized void initTrustedSSLSocketFactory(final KeyStore trustStore)
{
    try
    {
        final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
        trustManagerFactory.init(trustStore);
        context = SSLContext.getInstance("SSL");
        context.init(null, trustManagerFactory.getTrustManagers(), SecureRandom.getInstance("SHA1PRNG"));
    }
    catch (NoSuchAlgorithmException nsae)
    {
        throw new AlfrescoRuntimeException("The SSL socket factory cannot be initialized.", nsae);
    }
    catch (KeyStoreException kse)
    {
        throw new AlfrescoRuntimeException("The SSL socket factory cannot be initialized.", kse);
    }
    catch (KeyManagementException kme)
    {
        throw new AlfrescoRuntimeException("The SSL socket factory cannot be initialized.", kme);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:27,代碼來源:AlfrescoSSLSocketFactory.java

示例15: create

import java.security.KeyManagementException; //導入依賴的package包/類
private void create(Path path)
    throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
    KeyManagementException {
  TrustManager[] trustManagers;
  KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
  keyStore.load(null, null);

  installCertificates(path, keyStore);

  String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(defaultAlgorithm);
  trustManagerFactory.init(keyStore);
  trustManagers = trustManagerFactory.getTrustManagers();
  sslContext = SSLContext.getInstance("TLS");
  sslContext.init(null, trustManagers, null);
  trustManager = (X509TrustManager) trustManagers[0];
  X509Certificate[] acceptedIssuers = trustManager.getAcceptedIssuers();
  for (X509Certificate acceptedIssuer : acceptedIssuers) {
    logger.info("installed cert details: subject={} issuer={}",
        acceptedIssuer.getSubjectX500Principal(), acceptedIssuer.getIssuerX500Principal());
  }
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:23,代碼來源:CertificateLoader.java


注:本文中的java.security.KeyManagementException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。