时间:2021-07-01 10:21:17 帮助过:2人阅读
<Reaml /> 元素属性说明:
属性 | 说明 |
className | Tomcat 的 JDBCRealm 实现类 |
driverName | JDBC 驱动类 |
connectionURL | 数据库连接地址 |
connectionName | 数据库登录用户 |
connectionPassword | 数据库登录密码 |
userTable | 用户表的表名 |
userNameCol | 用户表中用户列的列名 |
userCredCol | 用户表中密码列的列名 |
userRoleTable | 角色表的表名 |
roleNameCol | 角色表中的角色列 |
注:<Realm/> 元素可以放在 <Engine/> 元素中,这时该 Realm 会被所有应用共享。 放在 <Host/> 元素中,会被该 Host 下的应用程序共享。放在 <Context/> 元素中,则只有对应的应用程序能被访问。
CREATE TABLE `users` ( `username` varchar(32) NOT NULL, `userpass` varchar(32) NOT NULL, PRIMARY KEY (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `roles` ( `username` varchar(32) NOT NULL, `userrole` varchar(32) NOT NULL, PRIMARY KEY (`username`,`userrole`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `tomcat`.`users` (`username`, `userpass`) VALUES (‘admin‘, ‘admin‘); INSERT INTO `tomcat`.`users` (`username`, `userpass`) VALUES (‘huey‘, ‘huey‘); INSERT INTO `tomcat`.`users` (`username`, `userpass`) VALUES (‘suer‘, ‘suer‘); INSERT INTO `tomcat`.`roles` (`username`, `role`) VALUES (‘admin‘, ‘admin‘); INSERT INTO `tomcat`.`roles` (`username`, `role`) VALUES (‘admin‘, ‘common‘); INSERT INTO `tomcat`.`roles` (`username`, `role`) VALUES (‘huey‘, ‘common‘); INSERT INTO `tomcat`.`roles` (`username`, `role`) VALUES (‘suer‘, ‘common‘); INSERT INTO `tomcat`.`roles` (`username`, `role`) VALUES (‘suer‘, ‘vip‘);
<security-role> <role-name>admin</role-name> </security-role> <security-role> <role-name>common</role-name> </security-role> <security-role> <role-name>vip</role-name> </security-role>
<security-constraint> <web-resource-collection> <web-resource-name>Public resources</web-resource-name> <url-pattern>/home/*</url-pattern> <http-method>HEAD</http-method> <http-method>GET</http-method> </web-resource-collection> <auth-constraint> <role-name>common</role-name> </auth-constraint> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>Secret resources</web-resource-name> <url-pattern>/blog/*</url-pattern> <url-pattern>/photo/*</url-pattern> <http-method>HEAD</http-method> <http-method>GET</http-method> <http-method>POST</http-method> <http-method>PUT</http-method> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> <role-name>vip</role-name> </auth-constraint> </security-constraint>
<login-config> <auth-method>BASIC</auth-method> <realm-name>hueyhome</realm-name> </login-config>
C:\Users\huey>curl -I -u "suer:suer" http://localhost:8080/helloweb/blog/index.html
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 08:00:00 CST
Accept-Ranges: bytes
ETag: W/"261-1431758220107"
Last-Modified: Sat, 16 May 2015 06:37:00 GMT
Content-Type: text/html
Content-Length: 261
Date: Tue, 19 May 2015 11:44:20 GMT
在 Tomcat 中设置 JDBCRealm
标签: