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:com.cws.esolutions.core.processors.impl.DNSServiceRequestProcessorImpl.java

/**
 * @see com.cws.esolutions.core.processors.interfaces.IDNSServiceRequestProcessor#performLookup(com.cws.esolutions.core.processors.dto.DNSServiceRequest)
 *///from w w w . j  ava2s  .c o  m
public DNSServiceResponse performLookup(DNSServiceRequest request) throws DNSServiceException {
    final String methodName = IDNSServiceRequestProcessor.CNAME
            + "#performLookup(final DNSServiceRequest request) throws DNSServiceException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("DNSServiceRequest: {}", request);
    }

    DNSServiceResponse response = new DNSServiceResponse();

    final DNSRecord dnsRecord = request.getRecord();
    final String currentTimeout = Security.getProperty("networkaddress.cache.ttl");

    if (DEBUG) {
        DEBUGGER.debug("DNSRecord: {}", dnsRecord);
        DEBUGGER.debug("currentTimeout: {}", currentTimeout);
    }

    try {
        // no authorization required for service lookup
        if ((StringUtils.isNotEmpty(request.getResolverHost())) || (request.getUseSystemResolver())) {
            List<List<String>> responseData = NetworkUtils.executeDNSLookup(request.getResolverHost(),
                    dnsRecord.getRecordName(), dnsRecord.getRecordType().toString(), request.getSearchPath());

            if (DEBUG) {
                DEBUGGER.debug("responseData: {}", responseData);
            }

            List<DNSRecord> responseRecords = new ArrayList<DNSRecord>();

            for (List<String> responseInfo : responseData) {
                if (DEBUG) {
                    DEBUGGER.debug("responseInfo: {}", responseInfo);
                }

                DNSRecord responseRecord = new DNSRecord();
                responseRecord.setRecordAddress(responseInfo.get(0));
                responseRecord.setRecordName(responseInfo.get(1));
                responseRecord.setRecordType(DNSRecordType.valueOf(responseInfo.get(2)));

                if (DEBUG) {
                    DEBUGGER.debug("responseRecord: {}", responseRecord);
                }

                responseRecords.add(responseRecord);

                if (DEBUG) {
                    DEBUGGER.debug("responseRecords: {}", responseRecords);
                }
            }

            response.setDnsRecords(responseRecords);
            response.setRequestStatus(CoreServicesStatus.SUCCESS);
        } else {
            // this will run through the available slave servers
            List<Object[]> serverList = dao.getServersByAttribute(ServerType.DNSSLAVE.name(), 0);

            if (DEBUG) {
                DEBUGGER.debug("serverList: {}", serverList);
            }

            if ((serverList != null) && (serverList.size() != 0)) {
                List<DNSRecord> responseRecords = new ArrayList<DNSRecord>();

                for (Object[] data : serverList) {
                    if (DEBUG) {
                        DEBUGGER.debug("Value: {}", data);
                    }

                    String serverName = (String) data[15];

                    if (DEBUG) {
                        DEBUGGER.debug("serverName: {}", serverName);
                    }

                    List<List<String>> responseData = NetworkUtils.executeDNSLookup(serverName,
                            dnsRecord.getRecordName(), dnsRecord.getRecordType().toString(),
                            request.getSearchPath());

                    if (DEBUG) {
                        DEBUGGER.debug("responseData: {}", responseData);
                    }

                    for (List<String> responseInfo : responseData) {
                        if (DEBUG) {
                            DEBUGGER.debug("responseInfo: {}", responseInfo);
                        }

                        DNSRecord responseRecord = new DNSRecord();
                        responseRecord.setRecordAddress(responseInfo.get(0));
                        responseRecord.setRecordName(responseInfo.get(1));
                        responseRecord.setRecordType(DNSRecordType.valueOf(responseInfo.get(2)));

                        if (DEBUG) {
                            DEBUGGER.debug("responseRecord: {}", responseRecord);
                        }

                        responseRecords.add(responseRecord);

                        if (DEBUG) {
                            DEBUGGER.debug("responseRecords: {}", responseRecords);
                        }
                    }
                }

                response.setDnsRecords(responseRecords);
                response.setRequestStatus(CoreServicesStatus.SUCCESS);
            } else {
                response.setRequestStatus(CoreServicesStatus.FAILURE);
            }
        }
    } catch (UtilityException ux) {
        ERROR_RECORDER.error(ux.getMessage(), ux);

        throw new DNSServiceException(ux.getMessage(), ux);
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new DNSServiceException(sqx.getMessage(), sqx);
    } finally {
        // reset java dns timeout
        try {
            Security.setProperty("networkaddress.cache.ttl", currentTimeout);
        } catch (NullPointerException npx) {
        }
    }

    return response;
}

From source file:com.floragunn.searchguard.ssl.SSLTest.java

@Test
public void testCipherAndProtocols() throws Exception {

    Security.setProperty("jdk.tls.disabledAlgorithms", "");
    System.out.println("Disabled algos: " + Security.getProperty("jdk.tls.disabledAlgorithms"));
    System.out.println("allowOpenSSL: " + allowOpenSSL);

    Settings settings = Settings.settingsBuilder().put("searchguard.ssl.transport.enabled", false)
            .put(SSLConfigConstants.SEARCHGUARD_SSL_HTTP_KEYSTORE_ALIAS, "node-0")
            .put("searchguard.ssl.http.enabled", true)
            .put(SSLConfigConstants.SEARCHGUARD_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
            .put("searchguard.ssl.http.clientauth_mode", "REQUIRE")
            .put("searchguard.ssl.http.keystore_filepath",
                    getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
            .put("searchguard.ssl.http.truststore_filepath", getAbsoluteFilePathFromClassPath("truststore.jks"))
            //WEAK and insecure cipher, do NOT use this, its here for unittesting only!!!
            .put("searchguard.ssl.http.enabled_ciphers", "SSL_RSA_EXPORT_WITH_RC4_40_MD5")
            //WEAK and insecure protocol, do NOT use this, its here for unittesting only!!!
            .put("searchguard.ssl.http.enabled_protocols", "SSLv3").put("client.type", "node")
            .put("path.home", ".").build();

    try {/*from   w ww .  j  a  v  a  2s.  com*/
        String[] enabledCiphers = new SearchGuardKeyStore(settings).createHTTPSSLEngine()
                .getEnabledCipherSuites();
        String[] enabledProtocols = new SearchGuardKeyStore(settings).createHTTPSSLEngine()
                .getEnabledProtocols();

        if (allowOpenSSL) {
            Assert.assertEquals(2, enabledProtocols.length); //SSLv2Hello is always enabled when using openssl
            Assert.assertTrue("Check SSLv3",
                    "SSLv3".equals(enabledProtocols[0]) || "SSLv3".equals(enabledProtocols[1]));
            Assert.assertEquals(1, enabledCiphers.length);
            Assert.assertEquals("TLS_RSA_EXPORT_WITH_RC4_40_MD5", enabledCiphers[0]);
        } else {
            Assert.assertEquals(1, enabledProtocols.length);
            Assert.assertEquals("SSLv3", enabledProtocols[0]);
            Assert.assertEquals(1, enabledCiphers.length);
            Assert.assertEquals("SSL_RSA_EXPORT_WITH_RC4_40_MD5", enabledCiphers[0]);
        }

        settings = Settings.settingsBuilder().put("searchguard.ssl.transport.enabled", true)
                .put(SSLConfigConstants.SEARCHGUARD_SSL_HTTP_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
                .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_ENABLE_OPENSSL_IF_AVAILABLE, allowOpenSSL)
                .put("searchguard.ssl.transport.keystore_filepath",
                        getAbsoluteFilePathFromClassPath("node-0-keystore.jks"))
                .put("searchguard.ssl.transport.truststore_filepath",
                        getAbsoluteFilePathFromClassPath("truststore.jks"))
                //WEAK and insecure cipher, do NOT use this, its here for unittesting only!!!
                .put("searchguard.ssl.transport.enabled_ciphers", "SSL_RSA_EXPORT_WITH_RC4_40_MD5")
                //WEAK and insecure protocol, do NOT use this, its here for unittesting only!!!
                .put("searchguard.ssl.transport.enabled_protocols", "SSLv3").put("client.type", "node")
                .put("path.home", ".").build();

        enabledCiphers = new SearchGuardKeyStore(settings).createServerTransportSSLEngine()
                .getEnabledCipherSuites();
        enabledProtocols = new SearchGuardKeyStore(settings).createServerTransportSSLEngine()
                .getEnabledProtocols();

        if (allowOpenSSL) {
            Assert.assertEquals(2, enabledProtocols.length); //SSLv2Hello is always enabled when using openssl
            Assert.assertTrue("Check SSLv3",
                    "SSLv3".equals(enabledProtocols[0]) || "SSLv3".equals(enabledProtocols[1]));
            Assert.assertEquals(1, enabledCiphers.length);
            Assert.assertEquals("TLS_RSA_EXPORT_WITH_RC4_40_MD5", enabledCiphers[0]);
        } else {
            Assert.assertEquals(1, enabledProtocols.length);
            Assert.assertEquals("SSLv3", enabledProtocols[0]);
            Assert.assertEquals(1, enabledCiphers.length);
            Assert.assertEquals("SSL_RSA_EXPORT_WITH_RC4_40_MD5", enabledCiphers[0]);
        }
        enabledCiphers = new SearchGuardKeyStore(settings).createClientTransportSSLEngine(null, -1)
                .getEnabledCipherSuites();
        enabledProtocols = new SearchGuardKeyStore(settings).createClientTransportSSLEngine(null, -1)
                .getEnabledProtocols();

        if (allowOpenSSL) {
            Assert.assertEquals(2, enabledProtocols.length); //SSLv2Hello is always enabled when using openssl
            Assert.assertTrue("Check SSLv3",
                    "SSLv3".equals(enabledProtocols[0]) || "SSLv3".equals(enabledProtocols[1]));
            Assert.assertEquals(1, enabledCiphers.length);
            Assert.assertEquals("TLS_RSA_EXPORT_WITH_RC4_40_MD5", enabledCiphers[0]);
        } else {
            Assert.assertEquals(1, enabledProtocols.length);
            Assert.assertEquals("SSLv3", enabledProtocols[0]);
            Assert.assertEquals(1, enabledCiphers.length);
            Assert.assertEquals("SSL_RSA_EXPORT_WITH_RC4_40_MD5", enabledCiphers[0]);
        }
    } catch (ElasticsearchSecurityException e) {
        System.out.println("EXPECTED " + e.getClass().getSimpleName() + " for "
                + System.getProperty("java.specification.version") + ": " + e.toString());
        e.printStackTrace();
        Assert.assertTrue("Check if error contains 'no valid cipher suites' -> " + e.toString(),
                e.toString().contains("no valid cipher suites")
                        || e.toString().contains("failed to set cipher suite")
                        || e.toString().contains("Unable to configure permitted SSL ciphers")
                        || e.toString().contains("OPENSSL_internal:NO_CIPHER_MATCH"));
        Assert.assertTrue("Check if >= Java 8 and no openssl",
                allowOpenSSL ? true : Constants.JRE_IS_MINIMUM_JAVA8);
    }
}

From source file:catalina.startup.CatalinaService.java

/**
 * Start a new server instance.//  w  w  w . j  ava2 s . co m
 */
public void load() {

    // Create and execute our Digester
    Digester digester = createStartDigester();
    File file = configFile();
    try {
        digester.push(this);
        digester.parse(file);
    } catch (Exception e) {
        System.out.println("Catalina.start: " + e);
        e.printStackTrace(System.out);
        System.exit(1);
    }

    // Setting additional variables
    if (!useNaming) {
        System.setProperty("catalina.useNaming", "false");
    } else {
        System.setProperty("catalina.useNaming", "true");
        String value = "org.apache.naming";
        String oldValue = System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
        if (oldValue != null) {
            value = value + ":" + oldValue;
        }
        System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.naming.java.javaURLContextFactory");
    }

    // If a SecurityManager is being used, set properties for
    // checkPackageAccess() and checkPackageDefinition
    if (System.getSecurityManager() != null) {
        String access = Security.getProperty("package.access");
        if (access != null && access.length() > 0)
            access += ",";
        else
            access = "sun.,";
        Security.setProperty("package.access", access + "org.apache.catalina.,org.apache.jasper.");
        String definition = Security.getProperty("package.definition");
        if (definition != null && definition.length() > 0)
            definition += ",";
        else
            definition = "sun.,";
        Security.setProperty("package.definition",
                // FIX ME package "javax." was removed to prevent HotSpot
                // fatal internal errors
                definition + "java.,org.apache.catalina.,org.apache.jasper.");
    }

    // Start the new server
    if (server instanceof Lifecycle) {
        try {
            server.initialize();
        } catch (LifecycleException e) {
            System.out.println("Catalina.start: " + e);
            e.printStackTrace(System.out);
            if (e.getThrowable() != null) {
                System.out.println("----- Root Cause -----");
                e.getThrowable().printStackTrace(System.out);
            }
        }
    }

}

From source file:ch.swisscom.mid.verifier.MobileIdCmsVerifier.java

/**
 * Validates the specified certificate path incl. OCSP revocation check
 * //ww  w. j ava  2  s  . c  o  m
 * @param truststore
 * @return true if all certificate is valid
 * @throws Exception 
 */
private boolean isCertValid(KeyStore truststore) throws Exception {
    List<X509Certificate> certlist = new ArrayList<X509Certificate>();
    certlist.add(signerCert);

    PKIXParameters params = new PKIXParameters(truststore);

    // Activate certificate revocation checking
    params.setRevocationEnabled(true);

    // Activate OCSP
    Security.setProperty("ocsp.enable", "true");

    // Activate CRLDP
    System.setProperty("com.sun.security.enableCRLDP", "true");

    // Ensure that the ocsp.responderURL property is not set.
    if (Security.getProperty("ocsp.responderURL") != null) {
        throw new Exception("The ocsp.responderURL property must not be set");
    }

    CertPathValidator cpv = CertPathValidator.getInstance(CertPathValidator.getDefaultType());

    cpv.validate(CertificateFactory.getInstance("X.509").generateCertPath(certlist), params);

    return true; // No Exception, all fine..
}

From source file:catalina.startup.Catalina.java

/**
 * Start a new server instance.//from w ww . j av  a 2  s  .  c o m
 */
protected void start() {

    // Create and execute our Digester
    Digester digester = createStartDigester();
    File file = configFile();
    try {
        InputSource is = new InputSource("file://" + file.getAbsolutePath());
        FileInputStream fis = new FileInputStream(file);
        is.setByteStream(fis);
        digester.push(this);
        digester.parse(is);
        fis.close();
    } catch (Exception e) {
        System.out.println("Catalina.start: " + e);
        e.printStackTrace(System.out);
        System.exit(1);
    }

    // Setting additional variables
    if (!useNaming) {
        System.setProperty("catalina.useNaming", "false");
    } else {
        System.setProperty("catalina.useNaming", "true");
        String value = "org.apache.naming";
        String oldValue = System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
        if (oldValue != null) {
            value = value + ":" + oldValue;
        }
        System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
        value = System.getProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY);
        if (value == null) {
            System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.naming.java.javaURLContextFactory");
        }
    }

    // If a SecurityManager is being used, set properties for
    // checkPackageAccess() and checkPackageDefinition
    if (System.getSecurityManager() != null) {
        String access = Security.getProperty("package.access");
        if (access != null && access.length() > 0)
            access += ",";
        else
            access = "sun.,";
        Security.setProperty("package.access", access + "org.apache.catalina.,org.apache.jasper.");
        String definition = Security.getProperty("package.definition");
        if (definition != null && definition.length() > 0)
            definition += ",";
        else
            definition = "sun.,";
        Security.setProperty("package.definition",
                // FIX ME package "javax." was removed to prevent HotSpot
                // fatal internal errors
                definition + "java.,org.apache.catalina.,org.apache.jasper.");
    }

    // Replace System.out and System.err with a custom PrintStream
    SystemLogHandler log = new SystemLogHandler(System.out);
    System.setOut(log);
    System.setErr(log);

    Thread shutdownHook = new CatalinaShutdownHook();

    // Start the new server
    if (server instanceof Lifecycle) {
        try {
            server.initialize();
            ((Lifecycle) server).start();
            try {
                // Register shutdown hook
                Runtime.getRuntime().addShutdownHook(shutdownHook);
            } catch (Throwable t) {
                // This will fail on JDK 1.2. Ignoring, as Tomcat can run
                // fine without the shutdown hook.
            }
            // Wait for the server to be told to shut down
            server.await();
        } catch (LifecycleException e) {
            System.out.println("Catalina.start: " + e);
            e.printStackTrace(System.out);
            if (e.getThrowable() != null) {
                System.out.println("----- Root Cause -----");
                e.getThrowable().printStackTrace(System.out);
            }
        }
    }

    // Shut down the server
    if (server instanceof Lifecycle) {
        try {
            try {
                // Remove the ShutdownHook first so that server.stop()
                // doesn't get invoked twice
                Runtime.getRuntime().removeShutdownHook(shutdownHook);
            } catch (Throwable t) {
                // This will fail on JDK 1.2. Ignoring, as Tomcat can run
                // fine without the shutdown hook.
            }
            ((Lifecycle) server).stop();
        } catch (LifecycleException e) {
            System.out.println("Catalina.stop: " + e);
            e.printStackTrace(System.out);
            if (e.getThrowable() != null) {
                System.out.println("----- Root Cause -----");
                e.getThrowable().printStackTrace(System.out);
            }
        }
    }

}

From source file:com.cws.esolutions.core.utils.NetworkUtils.java

/**
 * Performs a DNS lookup of a given name and type against a provided server
 * (or if no server is provided, the default system resolver).
 *
 * If an error occurs during the lookup, a <code>UtilityException</code> is
 * thrown containing the error response text.
 * //  w ww  . j  av  a2  s  .c om
 * @param resolverHost - The target host to use for resolution. Can be null, if not provided the
 * the default system resolver is used.
 * @param recordName - The DNS hostname/IP address to lookup.
 * @param recordType - The type of record to look up.
 * @param searchList - A search list to utilize if a short name is provided.
 * @return An ArrayList as output from the request
 * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing
 */
public static final synchronized List<List<String>> executeDNSLookup(final String resolverHost,
        final String recordName, final String recordType, final String[] searchList) throws UtilityException {
    final String methodName = NetworkUtils.CNAME
            + "#executeDNSLookup(final String resolverHost, final String recordName, final String recordType, final String[] searchList) throws UtilityException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("String: {}", resolverHost);
        DEBUGGER.debug("String: {}", recordName);
        DEBUGGER.debug("String: {}", recordType);
        DEBUGGER.debug("String: {}", (Object) searchList);
    }

    Lookup lookup = null;
    String responseName = null;
    String responseType = null;
    Record[] recordList = null;
    String responseAddress = null;
    SimpleResolver resolver = null;
    List<String> lookupData = null;
    List<List<String>> response = null;

    final String currentTimeout = Security.getProperty("networkaddress.cache.ttl");

    if (DEBUG) {
        DEBUGGER.debug("currentTimeout: {}", currentTimeout);
    }

    try {
        // no authorization required for service lookup
        Name name = Name.fromString(recordName);
        lookup = new Lookup(name, Type.value(recordType));

        if (DEBUG) {
            DEBUGGER.debug("Name: {}", name);
            DEBUGGER.debug("Lookup: {}", lookup);
        }

        if (StringUtils.isNotEmpty(resolverHost)) {
            resolver = new SimpleResolver(resolverHost);

            if (DEBUG) {
                DEBUGGER.debug("SimpleResolver: {}", resolver);
            }
        } else {
            resolver = new SimpleResolver();

            if (DEBUG) {
                DEBUGGER.debug("SimpleResolver: {}", resolver);
            }
        }

        lookup.setResolver(resolver);
        lookup.setCache(null);

        if (searchList != null) {
            lookup.setSearchPath(searchList);
        }

        if (DEBUG) {
            DEBUGGER.debug("Lookup: {}", lookup);
        }

        recordList = lookup.run();

        if (DEBUG) {
            if (recordList != null) {
                for (Record dRecord : recordList) {
                    DEBUGGER.debug("Record: {}", dRecord);
                }
            }
        }

        if (lookup.getResult() != Lookup.SUCCESSFUL) {
            throw new UtilityException("An error occurred during the lookup. The response obtained is: "
                    + lookup.getErrorString());
        }

        response = new ArrayList<List<String>>();

        if ((recordList == null) || (recordList.length == 0)) {
            throw new UtilityException("No results were found for the provided information.");
        }

        switch (recordList.length) {
        case 1:
            Record sRecord = recordList[0];

            if (DEBUG) {
                DEBUGGER.debug("Record: {}", sRecord);
            }

            responseAddress = sRecord.rdataToString();
            responseName = sRecord.getName().toString();
            responseType = Type.string(sRecord.getType());

            lookupData = new ArrayList<String>(Arrays.asList(responseAddress, responseName, responseType));
            if (DEBUG) {
                DEBUGGER.debug("responseAddress: {}", responseAddress);
                DEBUGGER.debug("responseName: {}", responseName);
                DEBUGGER.debug("responseType: {}", responseType);
            }

            response.add(lookupData);

            break;
        default:
            for (Record mRecord : recordList) {
                if (DEBUG) {
                    DEBUGGER.debug("Record: {}", mRecord);
                }

                responseAddress = mRecord.rdataToString();
                responseName = mRecord.getName().toString();
                responseType = Type.string(mRecord.getType());

                lookupData = new ArrayList<String>(Arrays.asList(responseAddress, responseName, responseType));
                if (DEBUG) {
                    DEBUGGER.debug("responseAddress: {}", responseAddress);
                    DEBUGGER.debug("responseName: {}", responseName);
                    DEBUGGER.debug("responseType: {}", responseType);
                }

                response.add(lookupData);

                if (DEBUG) {
                    DEBUGGER.debug("response: {}", response);
                }
            }

            break;
        }

        if (DEBUG) {
            DEBUGGER.debug("response: {}", response);
        }
    } catch (TextParseException tpx) {
        ERROR_RECORDER.error(tpx.getMessage(), tpx);

        throw new UtilityException(tpx.getMessage(), tpx);
    } catch (UnknownHostException uhx) {
        ERROR_RECORDER.error(uhx.getMessage(), uhx);

        throw new UtilityException(uhx.getMessage(), uhx);
    } finally {
        // reset java dns timeout
        try {
            Security.setProperty("networkaddress.cache.ttl", currentTimeout);
        } catch (NullPointerException npx) {
        }
    }

    return response;
}

From source file:org.acegisecurity.providers.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.
 *
 *//*ww w  .  j  av  a 2s .c o  m*/
private void configureJaasUsingLoop() throws IOException {
    String loginConfigUrl = loginConfig.getURL().toString();
    boolean alreadySet = false;

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

    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.apache.catalina.security.SecurityConfig.java

/**
 * Set the proper security property//  w w w .  j  a va  2  s.  c  o m
 * @param properties the package.* property.
 */
private final void setSecurityProperty(String properties, String packageList) {
    if (System.getSecurityManager() != null) {
        String definition = Security.getProperty(properties);
        if (definition != null && definition.length() > 0) {
            definition += ",";
        }

        Security.setProperty(properties,
                // FIX ME package "javax." was removed to prevent HotSpot
                // fatal internal errors
                definition + packageList);
    }
}

From source file:org.mule.transport.ldap.util.DSManager.java

public static IoFilterChainBuilder init(final KeyStore ks) throws NamingException {
    SSLContext sslCtx;/*  w ww . j a  v a 2s. c  o m*/
    try {
        // Set up key manager factory to use our key store
        String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
        if (algorithm == null) {
            algorithm = "SunX509";
        }
        final KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(ks, "changeit".toCharArray());

        // Initialize the SSLContext to work with our key managers.
        sslCtx = SSLContext.getInstance("TLS");
        sslCtx.init(kmf.getKeyManagers(), new TrustManager[] { new ServerX509TrustManager() },
                new SecureRandom());

        logger.debug("ssl set");
    } catch (final Exception e) {
        throw (NamingException) new NamingException("Failed to create a SSL context.").initCause(e);
    }

    final DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
    chain.addLast("sslFilter", new SSLFilter(sslCtx));
    return chain;
}

From source file:org.opendaylight.aaa.cert.impl.CertificateManagerService.java

@Override
public SSLContext getServerContext() {
    String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
    if (algorithm == null) {
        algorithm = "SunX509";
    }/* www. j  a  va  2  s .c o m*/
    SSLContext serverContext = null;
    try {
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(aaaCertProvider.getODLKeyStore(),
                aaaCertProvider.getOdlKeyStoreInfo().getStorePassword().toCharArray());
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
        tmf.init(aaaCertProvider.getTrustKeyStore());

        serverContext = SSLContext.getInstance(KeyStoreConstant.TLS_PROTOCOL);
        serverContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    } catch (final NoSuchAlgorithmException | UnrecoverableKeyException | KeyStoreException
            | KeyManagementException e) {
        LOG.error("Error while creating SSLContext ", e);
    }
    return serverContext;
}