bmuschko / gradle-tomcat-plugin

Gradle plugin supporting deployment of your web application to an embedded Tomcat web container
Apache License 2.0
530 stars 125 forks source link

Authentication against JDBCRealm? #183

Open alamakih opened 6 years ago

alamakih commented 6 years ago

I have a webapp that does form based authentication against JDBCRealm, which is normally configured in server.xml. Is there some way to get the authentication working in tomcat-plugin?

bmuschko commented 6 years ago

I am not fully sure if it works for JDBCRealm as well but have a look at this example. You can define users with roles.

alamakih commented 6 years ago

Figured it out. Realm configuration can be done in [webapp]/META-INF/context.xml, so no need for server.xml. Now if I'd just get webapp dir working from "foo/WebContent" instead of "src/main/webapp".

bmuschko commented 6 years ago

The configuration of foo/WebContent is specific to the war plugin so you'll need to check its documentation.

nth347 commented 3 years ago

Hello, project's maintainer! Thank you for your great work. I am setting up authentication using Basic authentication, servlet, and the Gradle Tomcat Plugin. But it does not work. I defined user roles in web.xml, and here is my tomcat section in build.gradle:

tomcat {
    httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol'
    ajpProtocol  = 'org.apache.coyote.ajp.AjpNio2Protocol'

    contextPath = '/'

    users {
        user {
            username = 'user1'
            password = '123456'
            roles = ['admin']
        }

        user {
            username = 'user2'
            password = 'abcdef'
            roles = ['user']
        }
    }
}

When I entering the correct credential in the pop-up asking for login and password, the site still doesn't let me log in, the pop-up will raise again. Please help me get it to work correctly. Thank you