How to set custom realm for the embedded tomcat? i am using SpringBoot however dont see a way to add custom realm via Embeddedservletcontainercustomizer.
Asked
Active
Viewed 2,312 times
1 Answers
5
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.

Artem Bilan
- 113,505
- 11
- 91
- 118
-
thanks very much for this, this resolved the issue, I see valve getting initialized in the logs. however my requests are bypassing the valve completely. any idea why would not go through the valve first ? do we need to do additional config from web.xml related to
/ – user3399267 Jun 26 '14 at 15:04? -
True. You can do it via `ServletContextInitializer` bean and provide `ServletContext.declareRoles`. I think... – Artem Bilan Jun 26 '14 at 15:44
-
How about adding in the customize() method above? SecurityConstraint sc = new SecurityConstraint(); //add config here context.addConstraint( sc); context.addSecurityRole("all_auth_users"); – user3399267 Jun 26 '14 at 16:26
-
Still not hitting the Valve, Ideally it should redirect the request to our centralized web authentication form, and once authenticated it would process the request. However looks like request directly hits dispatcher servlet and then controller even though I see in the logs 2014-06-26 14:47:51.528 INFO 4048 --- [ost-startStop-1] : GSAuthNAuthenticator (gsauthn-j version 4.1.1) started successfully. Any other thoughts ? – user3399267 Jun 26 '14 at 18:51