Redirecting HTTP requests to HTTPS in Spring Boot - (Wildfly server)

Asked

Viewed 115 times

2

I want to deploy a Spring Boot app in Wildfly that features HTTP request forwarding to HTTPS.

Here is the application.properties:

server.port=8443
server.ssl.key-alias=https-example
server.ssl.key-password=password
server.ssl.key-store=classpath:https-example.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS

The Serverconfig class where request forwarding is configured:

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.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;

public class ServerConfig {
    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(getHttpConnector());
        return tomcat;
    }

    private Connector getHttpConnector() {
        Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8443);
        return connector;
    }
}

After having built the app as War, when I try to deploy I have the following error:

{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"demo.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
    Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
    Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.example.demo.congif.ServerConfig] from ClassLoader [ModuleClassLoader for Module \"deployment.demo.war\" from Service Module Loader]
    Caused by: java.lang.NoClassDefFoundError: org/apache/catalina/connector/Connector
    Caused by: java.lang.ClassNotFoundException: org.apache.catalina.connector.Connector from [Module \"deployment.demo.war\" from Service Module Loader]"}}`

I have a Classnotfoundexception because I am deploying to a server other than wildfly. How to resolve this error?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.