gradle-tomcat-plugin icon indicating copy to clipboard operation
gradle-tomcat-plugin copied to clipboard

Issues getting users working

Open aleclerc opened this issue 10 years ago • 1 comments

Trying to get users running on a simple Tomcat 6.0.43 application.

I made a really basic application to try and test the user stuff build.gradle:

plugins {
    id "com.bmuschko.tomcat" version "2.1"
}
repositories {
    jcenter()
}
war{
    webXml = file('src/web.xml')
}
dependencies {
    def tomcatVersion = '6.0.43'
    tomcat "org.apache.tomcat:catalina:${tomcatVersion}",
    "org.apache.tomcat:coyote:${tomcatVersion}",
    "org.apache.tomcat:jasper:${tomcatVersion}"
}
tomcat {
    users {
        user {
            username = 'user1'
            password = '123456'
            roles = ['developers', 'admin', 'AuthenticatedUser']
        }
    }
}

web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <security-constraint>
        <display-name>Entire Application</display-name>
        <web-resource-collection>
            <web-resource-name>Entire Application</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
             <role-name>AuthenticatedUser</role-name>
        </auth-constraint>
    </security-constraint>
    <security-role>
        <role-name>AuthenticatedUser</role-name>
    </security-role>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
</web-app>

Everytime I hit a url, I get the basic auth popup, as expected. When I try to enter a user this shows up in my gradle output:

The Server is running at http://localhost:8080/RunSimpleWebApp
Unexpected error
javax.security.auth.login.LoginException: No LoginModules configured for localEngine
        at javax.security.auth.login.LoginContext.init(LoginContext.java:282)
        at javax.security.auth.login.LoginContext.<init>(LoginContext.java:427)
        at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:393)
        at org.apache.catalina.realm.JAASRealm.authenticate(JAASRealm.java:334)
        at org.apache.catalina.authenticator.BasicAuthenticator.authenticate(BasicAuthenticator.java:181)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:853)

From what I can see in the plugin code, it should be setting the Realm of my webapp to use org.apache.catalina.realm.UserDatabaseRealm Fairly notice tomcat user here, so bare with me if this is something obvious

aleclerc avatar Apr 10 '15 19:04 aleclerc

Not quite sure why it isn't working. This might be an issue with the default web.xml setup which is missing some configuration. My guess is that you can fix it by providing a proper web.xml via the property webDefaultXml.

bmuschko avatar Apr 12 '15 14:04 bmuschko