Skip to content
Snippets Groups Projects
Commit a0610580 authored by Lukas Malte Monnerjahn's avatar Lukas Malte Monnerjahn
Browse files

remove obsolete webservice config

parent c5c3f8ce
Branches OZG-7303
No related tags found
No related merge requests found
/*
* @formatter:off
*
* Copyright 2021-2022 Koordinierungsstelle für IT-Standards (KoSIT)
*
* Licensed under the European Public License, Version 1.2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/EUPL-1.2
*
* 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.
* @formatter:on
*/
package de.ozgcloud.xta.test.app.config;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
@Configuration
public class WebServiceConfig {
@Value("${server.port}")
@Getter
private int serverPort;
@Value("${app.server.http-port}")
@Getter
private int serverHttpPort;
@Value("${app.server.redirect-to-https:false}")
private boolean redirectToHttps;
@Bean
public ServletWebServerFactory servletContainer() {
if (redirectToHttps) {
return servletContainerRedirectToHttps();
}
return servletContainerStandardHttp();
}
public ServletWebServerFactory servletContainerStandardHttp() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addAdditionalTomcatConnectors(createStandardConnector());
return tomcat;
}
private Connector createStandardConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setPort(serverHttpPort);
return connector;
}
private ServletWebServerFactory servletContainerRedirectToHttps() {
// redirect Http to Https
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(final Context context) {
var securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
var collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(getHttpConnector());
return tomcat;
}
private Connector getHttpConnector() {
var connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(serverHttpPort);
connector.setSecure(false);
connector.setRedirectPort(serverPort);
return connector;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment