View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.properties.spring;
17  
18  import java.util.Properties;
19  
20  import org.kuali.common.util.PropertyUtils;
21  import org.kuali.common.util.enc.EncContext;
22  import org.kuali.common.util.project.model.Project;
23  import org.kuali.common.util.project.spring.AutowiredProjectConfig;
24  import org.kuali.common.util.properties.DefaultPropertiesService;
25  import org.kuali.common.util.properties.PropertiesService;
26  import org.kuali.common.util.property.ImmutableProperties;
27  import org.kuali.common.util.property.processor.JasyptDecryptingProcessor;
28  import org.kuali.common.util.property.processor.OverridingProcessor;
29  import org.kuali.common.util.property.processor.ProcessorsProcessor;
30  import org.kuali.common.util.property.processor.PropertyProcessor;
31  import org.kuali.common.util.property.processor.ResolvingProcessor;
32  import org.kuali.common.util.spring.env.BasicEnvironmentService;
33  import org.kuali.common.util.spring.env.EnvironmentService;
34  import org.kuali.common.util.spring.service.SpringServiceConfig;
35  import org.springframework.beans.factory.annotation.Autowired;
36  import org.springframework.context.annotation.Bean;
37  import org.springframework.context.annotation.Configuration;
38  import org.springframework.context.annotation.Import;
39  
40  /**
41   * @deprecated
42   */
43  @Deprecated
44  @Configuration
45  @Import({ SpringServiceConfig.class, AutowiredProjectConfig.class })
46  public class DefaultPropertiesServiceConfig implements PropertiesServiceConfig {
47  
48  	@Autowired
49  	Project project;
50  
51  	@Autowired
52  	EnvironmentService env;
53  
54  	@Override
55  	@Bean
56  	public PropertiesService propertiesService() {
57  		Properties overrides = getOverrides(project);
58  		PropertyProcessor processor = getPostProcessor(overrides);
59  		return new DefaultPropertiesService(overrides, processor);
60  	}
61  
62  	private Properties getOverrides(Project project) {
63  		// Get a reference to system + environment properties
64  		Properties global = PropertyUtils.getGlobalProperties();
65  
66  		// Setup a properties object where system properties "win" over project properties
67  		return ImmutableProperties.copyOf(PropertyUtils.combine(project.getProperties(), global));
68  	}
69  
70  	private PropertyProcessor getPostProcessor(Properties overrides) {
71  		EnvironmentService env = new BasicEnvironmentService(overrides);
72  		EncContext context = EncContext.builder(env).removeSystemProperties(false).build();
73  		PropertyProcessor override = new OverridingProcessor(overrides);
74  		PropertyProcessor decrypt = new JasyptDecryptingProcessor(context.getTextEncryptor());
75  		PropertyProcessor resolver = new ResolvingProcessor();
76  		return new ProcessorsProcessor(override, decrypt, resolver);
77  	}
78  
79  }