在 Tomcat 中设置 JDBCRealm
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在 Tomcat 中设置 JDBCRealm,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3674字,纯文字阅读大概需要6分钟。
内容图文
![在 Tomcat 中设置 JDBCRealm](/upload/InfoBanner/zyjiaocheng/448/4cb2ea8c07ea4fe584050990ba0bc2f5.jpg)
<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
标签:
本文系统来源:http://www.cnblogs.com/huey/p/4515340.html
内容总结
以上是互联网集市为您收集整理的在 Tomcat 中设置 JDBCRealm全部内容,希望文章能够帮你解决在 Tomcat 中设置 JDBCRealm所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。