
de.adorsys.psd2.aspsp.profile.config.WebConfig Maven / Gradle / Ivy
/*
* Copyright 2018-2019 adorsys GmbH & Co KG
*
* 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 de.adorsys.psd2.aspsp.profile.config;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import de.adorsys.psd2.aspsp.profile.converter.YamlJackson2HttpMessageConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
private final CorsConfigProperties corsConfigProperties;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Override
public void extendMessageConverters(List> converters) {
ObjectMapper yamlMapper = new YAMLMapper()
.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
converters.add(new YamlJackson2HttpMessageConverter(yamlMapper));
}
@Bean
@SuppressWarnings("common-java:DuplicatedBlocks")
public FilterRegistrationBean corsFilterRegistrationBean() {
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues(); //NOSONAR
config.setAllowCredentials(corsConfigProperties.getAllowCredentials());
config.setAllowedOrigins(corsConfigProperties.getAllowedOrigins());
config.setAllowedHeaders(corsConfigProperties.getAllowedHeaders());
config.setAllowedMethods(corsConfigProperties.getAllowedMethods());
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new FilterRegistrationBean<>(new CorsFilter(source));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy