Realm Configuration How-To
时间: 2024-05-24 17:08:42 浏览: 152
Realm Configuration是一种配置方式,用于定义Tomcat如何进行认证和授权。下面是一些Realm Configuration的配置方法[^1][^2]:
1.通过在Tomcat配置文件server.xml中为Realm元素设置属性来配置。例如:
```xml
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.apache.derby.jdbc.ClientDriver"
connectionURL="jdbc:derby://localhost:1527/myDB"
connectionName="app"
connectionPassword="app"
userTable="USERS" userNameCol="USERNAME" userCredCol="PASSWORD"
userRoleTable="USER_ROLES" roleNameCol="ROLENAME" />
```
2.通过在Tomcat的web.xml文件中声明Realm来配置。例如:
```xml
<security-constraint>
<web-resource-collection>
<web-resource-name>Apache Tomcat Examples</web-resource-name>
<url-pattern>/examples/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>tomcat</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Tomcat Examples</realm-name>
</login-config>
<security-role>
<description>
The role that is required to access the Tomcat examples web application.
</description>
<role-name>tomcat</role-name>
</security-role>
```
3.通过在context.xml文件中为Context元素设置Realm属性来配置。例如:
```xml
<Context path="/myapp" docBase="/usr/local/tomcat/myapp">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Context>
```
阅读全文