星期二, 一月 25, 2005

JBOSS JAAS 403错误解决问题.

问题描述:
当使用JAAS Login成功后,访问任何页面出现:
HTTP Status 403 - Access to the requested resource has been denied
错误

分析:
当使用JAAS login的时候.在login jsp里包括如下Form:

用户名

密码:




在conf/login-config.xml包含如下:
<application-policy name = "Demo">
<authentication>
<login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
flag = "required">
<module-option name = "dsJndiName">java:/MySqlDS</module-option>
<module-option name = "principalsQuery">
Select userpassword from sys_L_UserLogin where userid = ?
</module-option>
<module-option name = "rolesQuery">
Select roleid,roleid as Role from sys_L_UserRole where userid =?
</module-option>

</login-module>
</authentication>
</application-policy>

在web.xml包含如下:
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>

<url-pattern>*.jsp</url-pattern>

<url-pattern>/Demo/*.jsp</url-pattern>
<url-pattern>*.*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>

</web-resource-collection>

<auth-constraint>
<role-name>*</role-name>
</auth-constraint>

<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>

</security-constraint>
<login-config>
<auth-method>FORM</auth-method>

<realm-name>Demo</realm-name>

<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error_error.jsp</form-error-page>
</form-login-config>

</login-config>
注意红色部分.
出现403 错误:
jboss-web.xml 包含:
<同jboss-web.xml中的 <security-domain>java:/jaas/Demo</security-domain>相同>