您的位置:首页 > 运维架构 > Tomcat

tomcat启用 BASIC authentication,使用数据库身份认证,口令MD5加密

2016-10-18 15:56 337 查看
准备数据库:

表名

users

列名 值

username user11

password 698d51a19d8a121ce581499d7b701668

是口令111的MD5 32位 http://md5jiami.51240.com/

表名

users-roles

列名 值

username user11

rolename roles22

===================================================================================

修改apache的配置文件,启用JDBC数据库Realm,支持MD5 digest加密口令

D:\apache-tomcat-7.0.62\conf\context.xml

<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://xxxxxx:3306/spiis"
connectionName="root" connectionPassword="1q2w3e4r"
userTable="users" userNameCol="usercode"
userCredCol="password"
userRoleTable="users-roles"
digest="MD5"
roleNameCol="rolename"/>


修改apache的例子应用examples,使用 BASIC身份认证,角色roles22的用户可以访问/jsp/security/protected/* 资源

web.xml 修改为BASIC,role改一个为roles22

<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>tomcat</role-name>
<role-name>roles22</role-name>
</auth-constraint>
</security-constraint>

<!-- Default login configuration uses form-based authentication -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Example Form-Based Authentication Area</realm-name>
</login-config>

<!-- Security roles referenced by this web application -->
<security-role>
<role-name>roles22</role-name>
</security-role>
<security-role>
<role-name>tomcat</role-name>
</security-role>


copy mysql-connector-java-5.1.34-bin.jar to

D:\apache-tomcat-7.0.62-authentication-mysql\lib

浏览器访问URL,输入用户名口令user11/111进行身份认证

http://localhost:8088/examples/jsp/security/protected/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: