UserDatabaseRealm

%TOMCAT_HOME%\conf\server.xml

Basic

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" debug="0" resourceName="UserDatabase"/>

Digest

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" debug="0" resourceName="UserDatabase" digest="MD5"/>

%TOMCAT_HOME%\conf\tomcat-users.xml

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="admin" password="" roles="admin,manager"/>
  <user username="jasonb" password="9a3729201fdd376c76ded01f986481b1" roles="member"/>
</tomcat-users>

Memory Realm

%TOMCAT_HOME%\conf\server.xml

Basic

<Realm className="org.apache.catalina.realm.MemoryRealm"/>

JDBC Realm

%TOMCAT_HOME%\conf\server.xml

Basic

<Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99" driverName="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/authority" connectionName="root" connectionPassword="" userTable="users" userNameCol="user_name" userCredCol="user_pass" userRoleTable="user_roles" roleNameCol="role_name" />
create table users (
  user_name varchar(15) not null primary key,
  user_pass varchar(15) not null
);

create table roles (
  role_name varchar(15) not null primary key
);

create table user_roles (
  user_name varchar(15) not null,
  role_name varchar(15) not null,
  primary key( user_name, role_name )
);

Application

%TOMCAT_HOME%\webapps\WebCruise\WEB-INF\web.xml

Basic

<security-constraint>
  <web-resource-collection>
    <web-resource-name>MARCOM</web-resource-name>
    <url-pattern>/marcom/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <!-- %TOMCAT_HOME%/conf/tomcat-users.xml -->
    <role-name>home</role-name>
    <role-name>admin</role-name>
  </auth-constraint>
</security-constraint>
<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>MARCOM</realm-name>
</login-config>

Digest

<security-constraint>
  <web-resource-collection>
    <web-resource-name>MARCOM</web-resource-name>
    <url-pattern>/marcom/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <!-- %TOMCAT_HOME%/conf/tomcat-users.xml -->
    <role-name>home</role-name>
    <role-name>admin</role-name>
  </auth-constraint>
</security-constraint>
<login-config>
  <auth-method>DIGEST</auth-method>
  <realm-name>MARCOM</realm-name>
</login-config>