com.wavemaker.runtime.security.DefaultBootStrapPropertySourceInitializer Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2022-2023 WaveMaker, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.wavemaker.runtime.security;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import com.wavemaker.commons.util.DefaultYamlProcessor;
//TODO this class right now handles securityService.properties. Ideally there should be common framework to handle bootstrap properties
public class DefaultBootStrapPropertySourceInitializer implements ApplicationContextInitializer {
private static final Logger logger = LoggerFactory.getLogger(DefaultBootStrapPropertySourceInitializer.class);
@Override
public void initialize(ConfigurableWebApplicationContext applicationContext) {
Resource securityServiceResource = applicationContext.getResource("classpath:conf/securityService.yaml");
if (securityServiceResource.exists()) {
DefaultYamlProcessor defaultYamlProcessor = new DefaultYamlProcessor();
defaultYamlProcessor.setResources(securityServiceResource);
Properties properties = defaultYamlProcessor.getProperties();
applicationContext.getEnvironment().getPropertySources().addLast(new PropertySource<>("securityServicePropertySource") {
@Override
public Object getProperty(String name) {
if (name != null && name.startsWith("security.")) {
DefaultBootStrapPropertySourceInitializer.logger.info("Fetching security services property {}", name);
return properties.get(name);
}
return null;
}
});
}
}
}