首页 > 解决方案 > 没有 web.xml 的 JAX-RS 的 HTTP 基本身份验证

问题描述

我正在 JBoss EAP 7.1 上运行的 EAR 中的 EJB-JAR 中实现 REST 服务。

该服务的不安全版本运行良好,但即使添加基本的 HTTP 身份验证也是一个挑战,因为在 EJB-JAR 中我发现无法指定任何所需的 web.xml 条目,例如<auth-method>BASIC</auth-method>

所以我的问题是:

如何配置 JAX-RS 以在 EJB-JAR 中使用 HTTP 身份验证?

附加信息:

标签: jax-rswildflybasic-authenticationjboss-eap-7

解决方案


解决方案是使用 Undertow 的主动身份验证功能,默认情况下实际上是打开的。在请求中指定 HTTP-BASIC-Authentication 标头,使 Undertow 即使通过我的 REST 服务也尝试登录用户,因为缺少web.xml不需要任何类型的身份验证。

我的完整配置(使用来自的管理JBoss 用户mgmt-users.properties):

# Define my security domain
/subsystem=security/security-domain=MY-SECURITY-DOMAIN:add(cache-type=default)

# Link Untertow to Elytron for authentication
/subsystem=undertow/application-security-domain=MY-SECURITY-DOMAIN:add(   \
           http-authentication-factory="management-http-authentication"   \
)

# Add BASIC-HTTP-Authentication support to Elytron
/subsystem=elytron/http-authentication-factory=management-http-authentication:list-add( \
           name=mechanism-configurations,                                               \
           value={mechanism-name="BASIC",                                               \
               mechanism-realm-configurations=[{realm-name="ManagementRealm"}]          \
           }                                                                            \
)

# Not sure, why is this required...
/subsystem=ejb3/application-security-domain=MY-SECURITY-DOMAIN:add(  \
           security-domain="ManagementDomain")

推荐阅读