【发布时间】:2022-12-23 02:46:47
【问题描述】:
我有一个设置,使得用 @RolesAllowed 注释的端点需要身份验证和授权。但是,那些没有任何特定注释的端点甚至不需要身份验证。我如何配置服务器,使所有 URL 默认都受到保护,至少需要一个登录用户?
【问题讨论】:
标签: jakarta-ee jwt open-liberty microprofile
我有一个设置,使得用 @RolesAllowed 注释的端点需要身份验证和授权。但是,那些没有任何特定注释的端点甚至不需要身份验证。我如何配置服务器,使所有 URL 默认都受到保护,至少需要一个登录用户?
【问题讨论】:
标签: jakarta-ee jwt open-liberty microprofile
更新-这些目前都不适用于带有 JWT 的 JAX-RS
*目前将其保留为“已测试 - 不工作”以供参考。 *
最简单的方法是在您的web.xml 中提供security-constraints。像这样(您可以将登录更改为 FORM)。这也可以通过注释来完成,但这种方式更直接:
<security-constraint>
<web-resource-collection>
<web-resource-name>all-resources</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>auth-user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<role-name>auth-user</role-name>
</security-role>
然后在server.xml提供角色绑定(类似的可以通过ibm-web-bnd.xml文件完成):
<application-bnd>
<security-role name="admin">
<group name="admins" />
</security-role>
<security-role name="auth-user">
<special-subject type="ALL_AUTHENTICATED_USERS" />
</security-role>
</application-bnd>
【讨论】:
web.xml 文件(我不熟悉它)。
appSecurity 和 mpJwt 等。
@RolesAllowed 工作的方式。但是,所有没有 @RolesAllowed 的端点(在您链接的指南中没有)不需要身份验证(它们应该需要身份验证,而不是授权)。