gretty
gretty copied to clipboard
Tomcat runner ignores config file based realm configuration
Using tomcat as my container, if I specify a custom realm in tomcat.xml
two things can happen:
- If i provide the
tomcat-users.xml
file, Gretty picks this up and configures automatically a fixed realm, losing my custom configuration. - If I don't provide the file, Gretty ignores my custom configuration.
The workaround I found is leaving the tomcat-users.xml
present, and provide a realm configuration in webapp context.xml file.
I think the error comes from this code in TomcatServerConfigurer.groovy:
def realmConfigFile = webapp.realmConfigFile ?: params.realmConfigFile
if (realmConfigFile && new File(realmConfigFile).exists()) {
log.info '{} -> realm config {}', webapp.contextPath, realmConfigFile
def realm = new MemoryRealm()
realm.setPathname(realmConfigFile)
context.setRealm(realm)
} else
context.addLifecycleListener(new FixContextListener())
context.configFile = tomcat.getWebappConfigFile(webapp.resourceBase, webapp.contextPath)
if (!context.configFile && webapp.contextConfigFile)
context.configFile = new File(webapp.contextConfigFile).toURI().toURL()
if (context.configFile)
log.info 'Configuring {} with {}', webapp.contextPath, context.configFile
I believe that context.addLifecycleListener(new FixContextListener())
makes Tomcat ignore further configuration
I have the same problem if I use a DataSourceRealm in my context.xml. I must set an empty file to make it works.
Here my gretty configuration:
gretty {
servletContainer = 'tomcat8'
enableNaming = true
contextPath = 'app'
realmConfigFile = 'empty.xml'
dependencies {
// https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-dbcp
gretty 'org.apache.tomcat:tomcat-dbcp:' + tomcat8Version
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4
gretty 'com.microsoft.sqlserver:sqljdbc4:4.0'
// https://mvnrepository.com/artifact/org.clojars.prepor/vertica-jdbc
gretty 'org.clojars.prepor:vertica-jdbc:7.0.1-0'
// https://mvnrepository.com/artifact/org.hsqldb/hsqldb
gretty 'org.hsqldb:hsqldb:2.4.0'
// https://mvnrepository.com/artifact/com.oracle/ojdbc6
gretty 'com.oracle:ojdbc6:12.1.0.1-atlassian-hosted'
}
scanner = 'jdk'
httpPort = 8180
servicePort = 9910
statusPort = 9911
fastReload = true
recompileOnSourceChange = false
reloadOnClassChange = false
reloadOnConfigChange = false
reloadOnLibChange = fals
managedClassReload = false
scanInterval = 1
logDir = 'logs'
logFileName = 'output'
loggingLevel = 'INFO'
}