-
-
Save drissamri/8def1ce9322caab47e8e to your computer and use it in GitHub Desktop.
@Bean | |
public EmbeddedServletContainerFactory servletContainer() { | |
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() { | |
@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(initiateHttpConnector()); | |
return tomcat; | |
} | |
private Connector initiateHttpConnector() { | |
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); | |
connector.setScheme("http"); | |
connector.setPort(8080); | |
connector.setSecure(false); | |
connector.setRedirectPort(8443); | |
return connector; | |
} |
Hi All
Anyone here looking for the the imports, chances are that you are using springboot 2 If so please modify you code as follows:
@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(redirectConnector());
return tomcat;
}
Hi All
Anyone here looking for the the imports, chances are that you are using springboot 2 If so please modify you code as follows:
@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(redirectConnector());
return tomcat;
}
Thanks! That works fine.
Can you share all your imports please ?