All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.trustable.ca3s.core.PropertiesLogger Maven / Gradle / Ivy

Go to download

ca3s offers a unified view and administrative interface for your certificate landscape. It's a CA system with a flexible RA part based on BPM. backed by a CMP-connected CA or an ADCS. Offers automatic certificate distribution interfaces (like ACME and SCEP) for CAs that don't offer such interfaces. Brushed-up codebase of the sourceforge's ca3s-project ([https://sourceforge.net/projects/ca3s/]

There is a newer version: 1.1.19
Show newest version
package de.trustable.ca3s.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class PropertiesLogger implements ApplicationListener {
    private static final Logger log = LoggerFactory.getLogger(PropertiesLogger.class);

    private ConfigurableEnvironment environment;
    private boolean isFirstRun = true;

    @Override
    public void onApplicationEvent(ApplicationPreparedEvent event) {
        if (isFirstRun) {
            environment = event.getApplicationContext().getEnvironment();
            printProperties();
        }
        isFirstRun = false;
    }

    public void printProperties() {
        if(log.isDebugEnabled()) {
            for (EnumerablePropertySource propertySource : findPropertiesPropertySources()) {
                log.debug("******* " + propertySource.getName() + " *******");
                String[] propertyNames = propertySource.getPropertyNames();
                Arrays.sort(propertyNames);
                for (String propertyName : propertyNames) {
                    String resolvedProperty = environment.getProperty(propertyName);
                    String sourceProperty = propertySource.getProperty(propertyName).toString();
                    if (resolvedProperty.equals(sourceProperty)) {
                        log.debug("{}={}", propertyName, resolvedProperty);
                    } else {
                        log.debug("{}={} OVERRIDDEN to {}", propertyName, sourceProperty, resolvedProperty);
                    }
                }
            }
        }
    }

    private List findPropertiesPropertySources() {
        List propertiesPropertySources = new LinkedList<>();
        for (PropertySource propertySource : environment.getPropertySources()) {
            if (propertySource instanceof EnumerablePropertySource) {
                propertiesPropertySources.add((EnumerablePropertySource) propertySource);
            }
        }
        return propertiesPropertySources;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy