1
votes

I'm new to tomcat development. I've tried configuration for form-based authentication on tomcat server. But errors appear in log file logs/catalina.out. I'm not sure whether there is any error in conf/server.xml or application/WEB-INF/web.xml.
tomcat/logs/catalina.out outputs:

WARNING [main] org.apache.tomcat.util.digester.SetPropertiesRule.begin [SetPropertiesRule]{Server/Service/Engine/Realm} Setting property 'digest' to 'MD5' did not find a matching property.
WARNING [main] org.apache.tomcat.util.digester.Digester.endElement No rules found matching 'Server/Service/Engine/Resource'.

In tomcat/conf/server.xml

<Realm className="org.apache.catalina.realm.DataSourceRealm"
    localDataSource="true"
    digest="MD5"
    dataSourceName="jdbc/test"
    userTable="users"
    userNameCol="user_name"
    userCredCol="user_pass"
    userRoleTable="user_roles"
    roleNameCol="role_name"/>

<Resource name="jdbc/test"
    type="javax.sql.DataSource"
    factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/test"
    username="he"
    password="***"
    maxActive="8"
    maxIdle="4"
    maxWait="10000"
    auth="Container"/>

In application/WEB-INF/web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>UpdateRe</web-resource-name>
        <url-pattern>/images/*</url-pattern> 
    </web-resource-collection>
    <auth-constraint>
        <role-name>Admin</role-name>
        <role-name>Member</role-name>
    </auth-constraint>
</security-constraint>

<security-role>
    <role-name>Admin</role-name>
    <role-name>Member</role-name>
    <role-name>Guest</role-name>
</security-role>    

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/loginError.html</form-error-page>
    </form-login-config>  
</login-config>
1

1 Answers

1
votes

This is most likely you have Tomcat8.5 where digest attribute is removed. You need to use CredentialHandler sub element. This answer has an example how to support both Tomcat7 and Tomcat8 server in a same myapp.war file.

Most of the documentation online about the org.apache.catalina.realm.DataSourceRealm point to previous configuration.