Example usage for java.security Security getProperty

List of usage examples for java.security Security getProperty

Introduction

In this page you can find the example usage for java.security Security getProperty.

Prototype

public static String getProperty(String key) 

Source Link

Document

Gets a security property value.

Usage

From source file:org.springframework.security.authentication.jaas.JaasAuthenticationProvider.java

/**
 * Loops through the login.config.url.1,login.config.url.2 properties looking for the
 * login configuration. If it is not set, it will be set to the last available
 * login.config.url.X property.//from ww  w  . j a va 2  s . com
 *
 */
private void configureJaasUsingLoop() throws IOException {
    String loginConfigUrl = convertLoginConfigToUrl();
    boolean alreadySet = false;

    int n = 1;
    final String prefix = "login.config.url.";
    String existing;

    while ((existing = Security.getProperty(prefix + n)) != null) {
        alreadySet = existing.equals(loginConfigUrl);

        if (alreadySet) {
            break;
        }

        n++;
    }

    if (!alreadySet) {
        String key = prefix + n;
        log.debug("Setting security property [" + key + "] to: " + loginConfigUrl);
        Security.setProperty(key, loginConfigUrl);
    }
}

From source file:org.wso2.msf4j.conf.SSLHandlerFactory.java

public SSLHandlerFactory(SSLConfig sslConfig) {
    String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
    if (algorithm == null) {
        algorithm = "SunX509";
    }//from w  w  w  .  j av  a2  s  . c om
    try {
        KeyStore ks = getKeyStore(sslConfig.getKeyStore(), sslConfig.getKeyStorePassword());
        // Set up key manager factory to use our key store
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(ks,
                sslConfig.getCertificatePassword() != null ? sslConfig.getCertificatePassword().toCharArray()
                        : sslConfig.getKeyStorePassword().toCharArray());
        KeyManager[] keyManagers = kmf.getKeyManagers();
        TrustManager[] trustManagers = null;
        if (sslConfig.getTrustKeyStore() != null) {
            this.needClientAuth = true;
            KeyStore tks = getKeyStore(sslConfig.getTrustKeyStore(), sslConfig.getTrustKeyStorePassword());
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
            tmf.init(tks);
            trustManagers = tmf.getTrustManagers();
        }
        serverContext = SSLContext.getInstance(protocol);
        serverContext.init(keyManagers, trustManagers, null);
    } catch (UnrecoverableKeyException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException
            | IOException e) {
        throw new IllegalArgumentException("Failed to initialize the server-side SSLContext", e);
    }
}

From source file:software.betamax.util.DynamicSelfSignedSslEngineSource.java

private void initializeSSLContext() {
    String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
    if (algorithm == null) {
        algorithm = "SunX509";
    }/*from ww w  . j  a  va2s.  co  m*/

    try {
        final KeyStore ks = KeyStore.getInstance("JKS");
        // ks.load(new FileInputStream("keystore.jks"),
        // "changeit".toCharArray());
        ks.load(new FileInputStream(keyStoreFile), PASSWORD.toCharArray());

        // Set up key manager factory to use our key store
        final KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(ks, PASSWORD.toCharArray());

        // Set up a trust manager factory to use our key store
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
        tmf.init(ks);

        TrustManager[] trustManagers = new TrustManager[] { new X509TrustManager() {
            // TrustManager that trusts all servers
            @Override
            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        } };

        KeyManager[] keyManagers = kmf.getKeyManagers();

        // Initialize the SSLContext to work with our key managers.
        sslContext = SSLContext.getInstance(PROTOCOL);
        sslContext.init(keyManagers, trustManagers, null);
    } catch (final Exception e) {
        throw new Error("Failed to initialize the server-side SSLContext", e);
    }
}