001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util.properties.spring; 017 018import java.util.Properties; 019 020import org.kuali.common.util.PropertyUtils; 021import org.kuali.common.util.enc.EncContext; 022import org.kuali.common.util.project.model.Project; 023import org.kuali.common.util.project.spring.AutowiredProjectConfig; 024import org.kuali.common.util.properties.DefaultPropertiesService; 025import org.kuali.common.util.properties.PropertiesService; 026import org.kuali.common.util.property.ImmutableProperties; 027import org.kuali.common.util.property.processor.JasyptDecryptingProcessor; 028import org.kuali.common.util.property.processor.OverridingProcessor; 029import org.kuali.common.util.property.processor.ProcessorsProcessor; 030import org.kuali.common.util.property.processor.PropertyProcessor; 031import org.kuali.common.util.property.processor.ResolvingProcessor; 032import org.kuali.common.util.spring.env.BasicEnvironmentService; 033import org.kuali.common.util.spring.env.EnvironmentService; 034import org.kuali.common.util.spring.service.SpringServiceConfig; 035import org.springframework.beans.factory.annotation.Autowired; 036import org.springframework.context.annotation.Bean; 037import org.springframework.context.annotation.Configuration; 038import org.springframework.context.annotation.Import; 039 040/** 041 * @deprecated 042 */ 043@Deprecated 044@Configuration 045@Import({ SpringServiceConfig.class, AutowiredProjectConfig.class }) 046public class DefaultPropertiesServiceConfig implements PropertiesServiceConfig { 047 048 @Autowired 049 Project project; 050 051 @Autowired 052 EnvironmentService env; 053 054 @Override 055 @Bean 056 public PropertiesService propertiesService() { 057 Properties overrides = getOverrides(project); 058 PropertyProcessor processor = getPostProcessor(overrides); 059 return new DefaultPropertiesService(overrides, processor); 060 } 061 062 private Properties getOverrides(Project project) { 063 // Get a reference to system + environment properties 064 Properties global = PropertyUtils.getGlobalProperties(); 065 066 // Setup a properties object where system properties "win" over project properties 067 return ImmutableProperties.copyOf(PropertyUtils.combine(project.getProperties(), global)); 068 } 069 070 private PropertyProcessor getPostProcessor(Properties overrides) { 071 EnvironmentService env = new BasicEnvironmentService(overrides); 072 EncContext context = EncContext.builder(env).removeSystemProperties(false).build(); 073 PropertyProcessor override = new OverridingProcessor(overrides); 074 PropertyProcessor decrypt = new JasyptDecryptingProcessor(context.getTextEncryptor()); 075 PropertyProcessor resolver = new ResolvingProcessor(); 076 return new ProcessorsProcessor(override, decrypt, resolver); 077 } 078 079}