tomcat7spring-bootembedded-tomcat-7

How to set custom realm in embedded tomcat server? I am using Spring Boot.


How to set custom realm for the embedded tomcat? i am using SpringBoot however dont see a way to add custom realm via Embeddedservletcontainercustomizer.


Solution

  • Looks like you should define this bean:

    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
        TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
        factory.addContextCustomizers(new TomcatContextCustomizer() {
            @Override
            public void customize(Context context) {
                context.setRealm(new CombinedRealm());
            }
        });
        return factory;
    }
    

    And provide the desired Realm implementation.