1 package org.kuali.common.util.properties.spring;
2
3 import java.util.Properties;
4
5 import org.kuali.common.util.PropertyUtils;
6 import org.kuali.common.util.project.model.Project;
7 import org.kuali.common.util.project.spring.AutowiredProjectConfig;
8 import org.kuali.common.util.properties.DefaultPropertiesService;
9 import org.kuali.common.util.properties.PropertiesService;
10 import org.kuali.common.util.property.ImmutableProperties;
11 import org.kuali.common.util.property.processor.DecryptingProcessor;
12 import org.kuali.common.util.property.processor.OverridingProcessor;
13 import org.kuali.common.util.property.processor.ProcessorsProcessor;
14 import org.kuali.common.util.property.processor.PropertyProcessor;
15 import org.kuali.common.util.property.processor.ResolvingProcessor;
16 import org.kuali.common.util.property.processor.TrimmingProcessor;
17 import org.kuali.common.util.spring.env.EnvironmentService;
18 import org.kuali.common.util.spring.service.SpringServiceConfig;
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.context.annotation.Bean;
21 import org.springframework.context.annotation.Configuration;
22 import org.springframework.context.annotation.Import;
23
24 @Configuration
25 @Import({ SpringServiceConfig.class, AutowiredProjectConfig.class })
26 public class DefaultPropertiesServiceConfig implements PropertiesServiceConfig {
27
28 private static final String REMOVE_SYSTEM_PROPERTY_PASSWORD_KEY = "properties.enc.password.remove";
29
30 @Autowired
31 Project project;
32
33 @Autowired
34 EnvironmentService env;
35
36 @Override
37 @Bean
38 public PropertiesService propertiesService() {
39
40
41 Properties global = PropertyUtils.getGlobalProperties();
42
43
44 Properties overrides = new ImmutableProperties(PropertyUtils.combine(project.getProperties(), global));
45
46
47 String passwordKey = DecryptingProcessor.DEFAULT_PASSWORD_KEY;
48
49
50 PropertyProcessor processor = getPostProcessor(overrides, passwordKey);
51
52
53 PropertiesService service = new DefaultPropertiesService(overrides, processor);
54
55
56 if (env.getBoolean(REMOVE_SYSTEM_PROPERTY_PASSWORD_KEY, true)) {
57 PropertyUtils.removeSystemProperty(passwordKey);
58 }
59
60
61 return service;
62 }
63
64 protected PropertyProcessor getPostProcessor(Properties overrides, String passwordKey) {
65 PropertyProcessor override = new OverridingProcessor(overrides);
66 PropertyProcessor decrypt = new DecryptingProcessor(passwordKey);
67 PropertyProcessor resolve = new ResolvingProcessor();
68 PropertyProcessor trim = new TrimmingProcessor(passwordKey);
69 return new ProcessorsProcessor(override, decrypt, resolve, trim);
70 }
71
72 }