我正在做一个项目,我想在特定的url上应用身份验证。Jboss版本: Jboss 6.1.0
在我的应用程序http://localhost:8080/myApp/monitoring中有一个url,当用户点击这个URL时,它会询问用户id和密码。
以下是我所做的步骤
在WEB.XML中添加以下内容
<security-constraint>
<web-resource-collection>
<web-resource-name>All Access</web-resource-name>
<url-pattern>/monitoring</url-pattern>
<http-method>DELETE</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>ApplicationRealm</realm-name>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>jboss-web.xml
<jboss-web>
<security-domain>java:/jaas/other</security-domain>
</jboss-web>然后使用add-user.bat文件添加用户。但是当我点击url时,http://localhost:8080/myApp/monitoring服务器将返回错误代码302,并且url将重定向到https://localhost/myApp/monitoring。
有人能帮忙吗。提前谢谢。
发布于 2015-12-01 07:56:28
您在security-constraint中错误配置了web.xml元素。
尝试使用以下值:
<security-constraint>
<web-resource-collection>
<web-resource-name>All Access</web-resource-name>
<url-pattern>/monitoring</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>和现在的一些细节:
web-resource-collection中给它们命名(否则只有命名的方法受到保护)https (值不等于NONE),那么实际上的请求使用http (SSL/TLS)代替http。auth-constraint (提供授予访问权限的角色列表)https://stackoverflow.com/questions/33985004
复制相似问题