如何在 Jboss eap 6.1.0 中的特定 URL 上设置身份验证
How to set authentication on a specific URL in Jboss eap 6.1.0
我正在做一个项目,我想在其中对特定 url 应用身份验证。
Jboss版本:Jbosseap 6.1.0
我的申请中有一个URL
http://localhost:8080/myApp/monitoring
我想当用户点击这个 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
任何人都可以帮助解决这个问题。提前致谢。
您错误配置了 web.xml
中的 security-constraint
元素。
尝试使用以下值:
<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>
现在一些细节:
- 如果你想保护所有访问给定 URL 的 HTTP 方法,那么不要在
web-resource-collection
中命名它们(否则只有命名的方法受到保护)
- 如果您指定
transport-guarantee
(值不等于 NONE
),那么您实际上请求使用 https
(SSL/TLS) 而不是 http
- 如果您不想向所有人授予访问权限,您必须提供
auth-constraint
(以及您授予访问权限的角色列表)
我正在做一个项目,我想在其中对特定 url 应用身份验证。 Jboss版本:Jbosseap 6.1.0
我的申请中有一个URL http://localhost:8080/myApp/monitoring 我想当用户点击这个 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
任何人都可以帮助解决这个问题。提前致谢。
您错误配置了 web.xml
中的 security-constraint
元素。
尝试使用以下值:
<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>
现在一些细节:
- 如果你想保护所有访问给定 URL 的 HTTP 方法,那么不要在
web-resource-collection
中命名它们(否则只有命名的方法受到保护) - 如果您指定
transport-guarantee
(值不等于NONE
),那么您实际上请求使用https
(SSL/TLS) 而不是http
- 如果您不想向所有人授予访问权限,您必须提供
auth-constraint
(以及您授予访问权限的角色列表)