use of org.springframework.core.env.EnumerablePropertySource in project cas by apereo.
the class ShibbolethAttributeResolverConfiguration method attributeRepository.
@Bean
public IPersonAttributeDao attributeRepository() {
try {
final PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
final Map<String, Object> result = new HashMap<>();
environment.getPropertySources().forEach(s -> {
if (s instanceof EnumerablePropertySource<?>) {
final EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) s;
Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
}
});
final Properties p = new Properties();
p.putAll(result);
cfg.setProperties(p);
registerBeanIntoApplicationContext(cfg, "shibboleth.PropertySourcesPlaceholderConfigurer");
final ApplicationContext tempApplicationContext = SpringSupport.newContext(getClass().getName(), casProperties.getShibAttributeResolver().getResources(), Collections.singletonList(cfg), Collections.emptyList(), Collections.emptyList(), this.applicationContext);
final Collection<DataConnector> values = BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, DataConnector.class).values();
final Collection<DataConnector> connectors = new HashSet<>(values);
final AttributeResolverImpl impl = new AttributeResolverImpl();
impl.setId(getClass().getSimpleName());
impl.setApplicationContext(tempApplicationContext);
impl.setAttributeDefinitions(BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, AttributeDefinition.class).values());
impl.setDataConnectors(connectors);
if (!impl.isInitialized()) {
impl.initialize();
}
return new ShibbolethPersonAttributeDao(impl);
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return Beans.newStubAttributeRepository(casProperties.getAuthn().getAttributeRepository());
}
use of org.springframework.core.env.EnumerablePropertySource in project hub-detect by blackducksoftware.
the class DetectConfiguration method init.
public void init() throws DetectUserFriendlyException, IOException, IllegalArgumentException, IllegalAccessException {
final String systemUserHome = System.getProperty("user.home");
if (resolveTildeInPaths) {
tildeInPathResolver.resolveTildeInAllPathFields(systemUserHome, this);
}
if (StringUtils.isBlank(sourcePath)) {
usingDefaultSourcePath = true;
sourcePath = System.getProperty("user.dir");
}
sourceDirectory = new File(sourcePath);
if (!sourceDirectory.exists() || !sourceDirectory.isDirectory()) {
throw new DetectUserFriendlyException("The source path ${sourcePath} either doesn't exist, isn't a directory, or doesn't have appropriate permissions.", ExitCodeType.FAILURE_GENERAL_ERROR);
}
// make sure the path is absolute
sourcePath = sourceDirectory.getCanonicalPath();
usingDefaultOutputPath = StringUtils.isBlank(outputDirectoryPath);
outputDirectoryPath = createDirectoryPath(outputDirectoryPath, systemUserHome, "blackduck");
bdioOutputDirectoryPath = createDirectoryPath(bdioOutputDirectoryPath, outputDirectoryPath, "bdio");
scanOutputDirectoryPath = createDirectoryPath(scanOutputDirectoryPath, outputDirectoryPath, "scan");
ensureDirectoryExists(outputDirectoryPath, "The system property 'user.home' will be used by default, but the output directory must exist.");
ensureDirectoryExists(bdioOutputDirectoryPath, "By default, the directory 'bdio' will be created in the outputDirectory, but the directory must exist.");
ensureDirectoryExists(scanOutputDirectoryPath, "By default, the directory 'scan' will be created in the outputDirectory, but the directory must exist.");
outputDirectory = new File(outputDirectoryPath);
nugetInspectorPackageName = nugetInspectorPackageName.trim();
nugetInspectorPackageVersion = nugetInspectorPackageVersion.trim();
final MutablePropertySources mutablePropertySources = configurableEnvironment.getPropertySources();
for (final PropertySource<?> propertySource : mutablePropertySources) {
if (propertySource instanceof EnumerablePropertySource) {
final EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
for (final String propertyName : enumerablePropertySource.getPropertyNames()) {
if (StringUtils.isNotBlank(propertyName) && propertyName.startsWith(DETECT_PROPERTY_PREFIX)) {
allDetectPropertyKeys.add(propertyName);
}
}
}
}
if (hubSignatureScannerParallelProcessors == -1) {
hubSignatureScannerParallelProcessors = Runtime.getRuntime().availableProcessors();
}
bomToolFilter = new ExcludedIncludedFilter(getExcludedBomToolTypes(), getIncludedBomToolTypes());
if (dockerBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(dockerBomTool.getBomToolType().toString())) {
configureForDocker();
}
if (hubSignatureScannerRelativePathsToExclude != null && hubSignatureScannerRelativePathsToExclude.length > 0) {
for (final String path : hubSignatureScannerRelativePathsToExclude) {
excludedScanPaths.add(new File(sourceDirectory, path).getCanonicalPath());
}
}
if (StringUtils.isNotBlank(hubSignatureScannerHostUrl) && StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
throw new DetectUserFriendlyException("You have provided both a hub signature scanner url AND a local hub signature scanner path. Only one of these properties can be set at a time. If both are used together, the *correct* source of the signature scanner can not be determined.", ExitCodeType.FAILURE_GENERAL_ERROR);
}
if (StringUtils.isNotBlank(hubSignatureScannerHostUrl)) {
logger.info("A hub signature scanner url was provided, which requires hub offline mode. Setting hub offline mode to true.");
hubOfflineMode = true;
}
if (StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
logger.info("A local hub signature scanner path was provided, which requires hub offline mode. Setting hub offline mode to true.");
hubOfflineMode = true;
}
if (gradleBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(gradleBomTool.getBomToolType().toString())) {
gradleInspectorVersion = gradleBomTool.getInspectorVersion();
}
if (nugetBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(nugetBomTool.getBomToolType().toString())) {
nugetInspectorPackageVersion = nugetBomTool.getInspectorVersion();
}
if (dockerBomTool.isBomToolApplicable() && bomToolFilter.shouldInclude(dockerBomTool.getBomToolType().toString())) {
dockerInspectorVersion = dockerBomTool.getInspectorVersion();
}
configureForPhoneHome();
}
use of org.springframework.core.env.EnumerablePropertySource in project pinpoint by naver.
the class ExperimentalConfig method readExperimentalProperties.
private Map<String, Object> readExperimentalProperties(Environment environment) {
MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources();
Map<String, Object> collect = propertySources.stream().filter(ps -> ps instanceof EnumerablePropertySource).map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).filter(propName -> propName.startsWith(PREFIX)).collect(Collectors.toMap(Function.identity(), toValue(environment)));
return collect;
}
use of org.springframework.core.env.EnumerablePropertySource in project spring-boot by spring-projects.
the class YamlPropertySourceLoaderTests method orderedItems.
@Test
void orderedItems() throws Exception {
StringBuilder yaml = new StringBuilder();
List<String> expected = new ArrayList<>();
for (char c = 'a'; c <= 'z'; c++) {
yaml.append(c).append(": value").append(c).append("\n");
expected.add(String.valueOf(c));
}
ByteArrayResource resource = new ByteArrayResource(yaml.toString().getBytes());
EnumerablePropertySource<?> source = (EnumerablePropertySource<?>) this.loader.load("resource", resource).get(0);
assertThat(source).isNotNull();
assertThat(source.getPropertyNames()).isEqualTo(StringUtils.toStringArray(expected));
}
use of org.springframework.core.env.EnumerablePropertySource in project canal by alibaba.
the class CanalAdapterLoader method loadAdapter.
private void loadAdapter(OuterAdapterConfig config, List<OuterAdapter> canalOutConnectors) {
try {
OuterAdapter adapter;
adapter = loader.getExtension(config.getName(), StringUtils.trimToEmpty(config.getKey()));
ClassLoader cl = Thread.currentThread().getContextClassLoader();
// 替换ClassLoader
Thread.currentThread().setContextClassLoader(adapter.getClass().getClassLoader());
Environment env = (Environment) SpringContext.getBean(Environment.class);
Properties evnProperties = null;
if (env instanceof StandardEnvironment) {
evnProperties = new Properties();
for (PropertySource<?> propertySource : ((StandardEnvironment) env).getPropertySources()) {
if (propertySource instanceof EnumerablePropertySource) {
String[] names = ((EnumerablePropertySource<?>) propertySource).getPropertyNames();
for (String name : names) {
Object val = env.getProperty(name);
if (val != null) {
evnProperties.put(name, val);
}
}
}
}
}
adapter.init(config, evnProperties);
Thread.currentThread().setContextClassLoader(cl);
canalOutConnectors.add(adapter);
logger.info("Load canal adapter: {} succeed", config.getName());
} catch (Exception e) {
logger.error("Load canal adapter: {} failed", config.getName(), e);
}
}
Aggregations