Search in sources :

Example 1 with SslConfiguration

use of org.apache.logging.log4j.core.net.ssl.SslConfiguration in project logging-log4j2 by apache.

the class ConfigurationSource method getConfigurationSource.

private static ConfigurationSource getConfigurationSource(final URL url) {
    try {
        final URLConnection urlConnection = url.openConnection();
        final AuthorizationProvider provider = ConfigurationFactory.authorizationProvider(PropertiesUtil.getProperties());
        provider.addAuthorization(urlConnection);
        if (url.getProtocol().equals(HTTPS)) {
            final SslConfiguration sslConfiguration = SslConfigurationFactory.getSslConfiguration();
            if (sslConfiguration != null) {
                ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
                if (!sslConfiguration.isVerifyHostName()) {
                    ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
                }
            }
        }
        final File file = FileUtils.fileFromUri(url.toURI());
        try {
            if (file != null) {
                return new ConfigurationSource(urlConnection.getInputStream(), FileUtils.fileFromUri(url.toURI()));
            } else {
                return new ConfigurationSource(urlConnection.getInputStream(), url, urlConnection.getLastModified());
            }
        } catch (final FileNotFoundException ex) {
            ConfigurationFactory.LOGGER.info("Unable to locate file {}, ignoring.", url.toString());
            return null;
        }
    } catch (final IOException | URISyntaxException ex) {
        ConfigurationFactory.LOGGER.warn("Error accessing {} due to {}, ignoring.", url.toString(), ex.getMessage());
        return null;
    }
}
Also used : SslConfiguration(org.apache.logging.log4j.core.net.ssl.SslConfiguration) AuthorizationProvider(org.apache.logging.log4j.core.util.AuthorizationProvider) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 2 with SslConfiguration

use of org.apache.logging.log4j.core.net.ssl.SslConfiguration in project logging-log4j2 by apache.

the class Log4j2CloudConfigLoggingSystem method getConfigurationSource.

private ConfigurationSource getConfigurationSource(URL url) throws IOException, URISyntaxException {
    URLConnection urlConnection = url.openConnection();
    AuthorizationProvider provider = ConfigurationFactory.authorizationProvider(PropertiesUtil.getProperties());
    provider.addAuthorization(urlConnection);
    if (url.getProtocol().equals(HTTPS)) {
        SslConfiguration sslConfiguration = SslConfigurationFactory.getSslConfiguration();
        if (sslConfiguration != null) {
            ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
            if (!sslConfiguration.isVerifyHostName()) {
                ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
            }
        }
    }
    File file = FileUtils.fileFromUri(url.toURI());
    try {
        if (file != null) {
            return new ConfigurationSource(urlConnection.getInputStream(), FileUtils.fileFromUri(url.toURI()));
        } else {
            return new ConfigurationSource(urlConnection.getInputStream(), url, urlConnection.getLastModified());
        }
    } catch (FileNotFoundException ex) {
        LOGGER.info("Unable to locate file {}, ignoring.", url.toString());
        return null;
    }
}
Also used : ConfigurationSource(org.apache.logging.log4j.core.config.ConfigurationSource) SslConfiguration(org.apache.logging.log4j.core.net.ssl.SslConfiguration) BasicAuthorizationProvider(org.apache.logging.log4j.core.util.BasicAuthorizationProvider) AuthorizationProvider(org.apache.logging.log4j.core.util.AuthorizationProvider) FileNotFoundException(java.io.FileNotFoundException) LogFile(org.springframework.boot.logging.LogFile) File(java.io.File) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 3 with SslConfiguration

use of org.apache.logging.log4j.core.net.ssl.SslConfiguration in project logging-log4j2 by apache.

the class TlsSyslogAppenderTest method createAppender.

private SyslogAppender createAppender() {
    String format;
    if (messageFormat == TlsSyslogMessageFormat.LEGACY_BSD) {
        format = "LEGACY_BSD";
    } else {
        format = "RFC5424";
    }
    final SslConfiguration sslConfiguration1 = sslConfiguration;
    final boolean newLine = includeNewLine;
    final String format1 = format;
    // @formatter:off
    return SyslogAppender.newSyslogAppenderBuilder().setHost("localhost").setPort(PORTNUM).setProtocol(EnglishEnums.valueOf(Protocol.class, "SSL")).setSslConfiguration(sslConfiguration1).setConnectTimeoutMillis(0).setReconnectDelayMillis(-1).setImmediateFail(true).setName("TestApp").setImmediateFlush(true).setIgnoreExceptions(false).setFilter(null).setConfiguration(null).setAdvertise(false).setFacility(Facility.LOCAL0).setId("Audit").setEnterpriseNumber(18060).setIncludeMdc(true).setMdcId("RequestContext").setMdcPrefix(null).setEventPrefix(null).setNewLine(newLine).setAppName("TestApp").setMsgId("Test").setExcludes(null).setIncludeMdc(true).setRequired(null).setFormat(format1).setCharsetName(null).setExceptionPattern(null).setLoggerFields(null).build();
// @formatter:on
}
Also used : SslConfiguration(org.apache.logging.log4j.core.net.ssl.SslConfiguration) Protocol(org.apache.logging.log4j.core.net.Protocol)

Aggregations

SslConfiguration (org.apache.logging.log4j.core.net.ssl.SslConfiguration)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 URLConnection (java.net.URLConnection)2 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)2 AuthorizationProvider (org.apache.logging.log4j.core.util.AuthorizationProvider)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ConfigurationSource (org.apache.logging.log4j.core.config.ConfigurationSource)1 Protocol (org.apache.logging.log4j.core.net.Protocol)1 BasicAuthorizationProvider (org.apache.logging.log4j.core.util.BasicAuthorizationProvider)1 LogFile (org.springframework.boot.logging.LogFile)1