2

I am aware of this question: embedded tomcat spring boot
however this leaves much to be desired as far as a solution is concerned, Currently I have the following code which works to enable SSL:

TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers( (connector) -> {
     connector.setPort(8443);
     connector.setSecure(true);
     connector.setScheme("https");

     Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
     protocol.setSSLEnabled(true);
     protocol.setKeystoreFile(keystore);
     protocol.setKeystorePass(password);
     protocol.setKeystoreType("jks");
     protocol.setKeyAlias(alias);
}
)

My question is this, if I have a Realm that looks like this in XML:

<Realm classname="foo.bar.baz | bing.bang.bong"
        var1 = "xyz"
        var2 = "123"
/>

How do I recreate that with embedded tomcat?

Community
  • 1
  • 1
test name
  • 21
  • 3

1 Answers1

1

Try using the ContextCustomizer instead of the ConnectorCustomizer

tomcat.addContextCustomizers( (context) -> { 
    context.setRealm(...);
}
)
jst
  • 1,697
  • 1
  • 12
  • 13
  • sure, but how do I actually build the realm? – test name Jun 12 '15 at 16:28
  • Well not sure based on your question above what implementation of a realm you are using. But for instance look at the API for org.apache.catalina.realm.DataSourceRealm and you will see it has a constructor and setters for the attributes you would normally configure in the XML. – jst Jun 13 '15 at 14:43