The security domain is a built-in function of Tomcat. apache. catalina. the realm interface declares that a group of usernames, passwords, and associated roles are integrated into the Tomcat method. Tomcat 5 provides four classes to implement this interface, they represent four security domain types.
The following describes the configurations and application methods.
Running Environment: Windows2000, tomcat5.0.28, jdk1.5, jdbc3.0, sqlserver2000,
Test Directory: % Tomcat %/webapps/area directory.
1. Memory domain: Class Name, memoryrealm; in the initialization phase, read the security authentication information from the XML file and put them in the memory as a group of objects.
There are three methods for accessing resources: basic, digest, and form. Using basic authentication is considered insecure because it does not have robust encryption methods, unless the client and server Use https or other password and password methods (for example, in a virtual private network ).
The configuration file % Tomcat %/CONF/Catalina/localhost/area. XML is:
<? XML version = '1. 0' encoding = 'utf-8'?>
<Context docbase = "D:/jakarta-tomcat-5.0.28/webapps/area" Path = "/area" reloadable = "true"
Workdir = "work/Catalina/localhost/area">
<Realm classname = "org. Apache. Catalina. realm. memoryrealm"/>
</Context>
The WEB-INF/Web. XML for the Web application is:
<? XML version = "1.0" encoding = "gb2312"?>
<! Doctype web-app
Public "-// Sun Microsystems, Inc. // DTD web application 2.3 // en" "http://java.sun.com/dtd/web-app_2_3.dtd">
<Web-app>
<Security-constraint>
<Display-Name> sessiontest secruity constraint </display-Name>
<Web-resource-collection>
<Web-resource-Name> Protected Area </Web-resource-Name>
<URL-pattern>/test/* </url-pattern>
</Web-resource-collection>
<Auth-constraint>
<Role-Name> cool </role-Name>
</Auth-constraint>
</Security-constraint>
<! -- Basic verification -->
<Login-config>
<Auth-method> basic </auth-method>
<Realm-Name> sessiontest realm </realm-Name>
</Login-config>
<! -- Digest-based verification -->
<! -- <Login-config>
<Auth-method> digest </auth-method>
<Realm-Name> sessiontest realm </realm-Name>
</Login-config>
-->
<! -- The following is form-based verification -->
<! -- <Login-config>
<Auth-method> form </auth-method>
<Realm-Name> sessiontest realm </realm-Name>
<Form-login-config>
<Form-login-page>/usercheck. jsp </form-login-page>
<Form-error-page>/error. jsp </form-error-page>
</Form-login-config>
</Login-config>
If form verification is used, usercheck. jsp, the main parameter (do not change it) is set as follows:
<Form method = "Post" Action = "j_security_check">
<Input type = "text" name = "j_username"> <br>
<Br>
<Input type = "password" name = "j_password"> <br>
<Br>
<Input type = "Submit" value = "login">
<Input type = "reset" value = "reset">
</Form>
-->
<Security-role>
<Description> session jdbctest </description>
<Role-Name> cool </role-Name>
</Security-role>
</Web-app>
<URL-pattern>/test/* </url-pattern> indicates that the protected resource is all resources under http: // localhost: 8080/area/test. The role cool is added to the tomcat-users.xml in % Tomcat % conf:
<Role rolename = "cool"/>
<User Username = "zxj1" Password = "zxj2" roles = "cool"/>
2. JDBC domain: Class Name, jdbcrealm, driven by JDBC Program Access Security Authentication in the database.
3. Data Source Domain: Class Name, datasourcerealm. Access the security authentication information in the database through the JNDI data source.
4. JNDI domain: the class name, jndirealm, uses jndiproveider to access the security authentication information stored in the LDAP-based Directory Server.
The time is limited. You need to modify it later.