在web.xml设置的role-name怎么和数据库里面的值对应
发布网友
发布时间:2022-05-05 01:58
我来回答
共1个回答
热心网友
时间:2022-06-28 10:55
在resin下正常使用。如果其它的服务器不好用可以做相应的更改
<web-app>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!--直接把用户和角色配置在xml里
<authenticator>
<class-name>com.caucho.http.security.XmlAuthenticator</class-name>
<init-param user='Harry Potter:quidditch:user,gryffindor'/>
<init-param user='Draco Malfoy:pureblood:user,slytherin'/>
<init-param user='Fish:pwd:admin_user'/>
</authenticator>
-->
<!-- 从数据库里取用户和角色 -->
<authenticator id='com.caucho.http.security.JdbcAuthenticator'>
<pool-name>cncworkdb</pool-name>
<password-query>
SELECT password FROM userInfo WHERE userName=?
</password-query>
<cookie-auth-query>
SELECT cookie FROM userInfo WHERE userName=?
</cookie-auth-query>
<cookie-auth-update>
UPDATE userInfo SET cookie=? WHERE userName=?
</cookie-auth-update>
<role-query>
SELECT userRole FROM userInfo WHERE userName=?
</role-query>
</authenticator>
<!-- 设置被保护的资源 -->
<security-constraint>
<web-resource-collection>
<url-pattern>/FishTest/*.jsp</url-pattern>
<url-pattern>/FishTest/*.htm</url-pattern>
<url-pattern>/FishTest/*.html</url-pattern>
</web-resource-collection>
<auth-constraint role-name='admin'/>
</security-constraint>
<!-- 设置登录页面及登录失败页面 -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>default</realm-name>
<form-login-config>
<form-login-page>/FishTest/Login.jsp</form-login-page>
<form-error-page>/FishTest/LoginError.html</form-error-page>
<internal-forward>false</internal-forward>
<form-uri-priority>true</form-uri-priority>
</form-login-config>
</login-config>
</web-app>