15.2. HawtIO 中的通用 OpenID Connect 身份验证
HawtIO 4 可以与现有 OpenID Connect 供应商(如 Keycloak、Microsoft Entra ID、Auth0, …)一起使用,并使用这些库来填充任务:
- Apache HTTP 客户端 4 将来自 HawtIO 服务器的 HTTP 通信实施到 OpenID Connect 供应商(例如,检索有关令牌签名验证的公钥的信息)。
- Nimbus JOSE + JWT 库,以操作和验证 OpenID Connect / OAuth2 访问令牌。
这些库包含在 HawtIO Server WAR 中,这意味着不需要安装/部署任何其他库(就像 Keycloak 特定的配置一样)。为了配置带有外部 OpenID Connect 提供商的 HawtIO,我们需要提供一个配置文件,并将 HawtIO 指向其位置。
指定 OIDC (OpenID Connect)配置的位置为 -Dhawtio.oidcConfig
,但没有指定,则会检查默认位置。默认值为:
-
对于 Karaf runtime,
${karaf.base}/etc/hawtio-oidc.properties
-
对于 Jetty runtime,
${jetty.home}/etc/hawtio-oidc.properties
-
对于 Tomcat 运行时,
${catalina.home}/conf/hawtio-oidc.properties
-
对于 JBoss/EAP/Wildfly 运行时,
${jboss.server.config.dir}/hawtio-oidc.properties
-
对于 Apache Artemis 运行时,
${artemis.instance.etc}/hawtio-oidc.properties
-
回退到
classpath:hawtio-oidc.properties
(用于嵌入式 HawtIO 用法)
与 Keycloak 特定的配置不同,只有一个 2.2.properties 文件来配置 OpenID Connect 配置的所有方面。
以下是模板:
OpenID Connect configuration requred at client side URL of OpenID Connect Provider - the URL after which ".well-known/openid-configuration" can be appended for discovery purposes OpenID client identifier response mode according to https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html scope to request when performing OpenID authentication. MUST include "openid" and required permissions redirect URI after OpenID authentication - must also be configured at provider side challenge method according to https://datatracker.ietf.org/doc/html/rfc7636 prompt hint according to https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest additional configuration for the server side if true, .well-known/openid-configuration will be fetched at server side. This is required for proper JWT access token validation time in minutes to cache public keys from jwks_uri a path for an array of roles found in JWT payload. Property placeholders can be used for parameterized parts of the path (like for Keycloak) - but only for properties from this particular file example for properly configured Entra ID token example for Keycloak with use-resource-role-mappings=true example for Keycloak with use-resource-role-mappings=false properties for role mapping. Each property with "roleMapping." prefix is used to map an original role from JWT token (found at ${oidc.rolesPath}) to a role used by the application timeout for connection establishment (milliseconds) timeout for reading from established connection (milliseconds) HTTP proxy to use when connecting to OpenID Connect provider TLS configuration (system properties can be used, e.g., "${catalina.home}/conf/hawtio.jks")
# OpenID Connect configuration requred at client side
# URL of OpenID Connect Provider - the URL after which ".well-known/openid-configuration" can be appended for
# discovery purposes
provider = http://localhost:18080/realms/hawtio-demo
# OpenID client identifier
client_id = hawtio-client
# response mode according to https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html
response_mode = fragment
# scope to request when performing OpenID authentication. MUST include "openid" and required permissions
scope = openid email profile
# redirect URI after OpenID authentication - must also be configured at provider side
redirect_uri = http://localhost:8080/hawtio
# challenge method according to https://datatracker.ietf.org/doc/html/rfc7636
code_challenge_method = S256
# prompt hint according to https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
prompt = login
# additional configuration for the server side
# if true, .well-known/openid-configuration will be fetched at server side. This is required
# for proper JWT access token validation
oidc.cacheConfig = true
# time in minutes to cache public keys from jwks_uri
jwks.cacheTime = 60
# a path for an array of roles found in JWT payload. Property placeholders can be used for parameterized parts
# of the path (like for Keycloak) - but only for properties from this particular file
# example for properly configured Entra ID token
#oidc.rolesPath = roles
# example for Keycloak with use-resource-role-mappings=true
#oidc.rolesPath = resource_access.${client_id}.roles
# example for Keycloak with use-resource-role-mappings=false
oidc.rolesPath = realm_access.roles
# properties for role mapping. Each property with "roleMapping." prefix is used to map an original role
# from JWT token (found at ${oidc.rolesPath}) to a role used by the application
roleMapping.admin = admin
roleMapping.user = user
roleMapping.viewer = viewer
roleMapping.manager = manager
# timeout for connection establishment (milliseconds)
http.connectionTimeout = 5000
# timeout for reading from established connection (milliseconds)
http.readTimeout = 10000
# HTTP proxy to use when connecting to OpenID Connect provider
#http.proxyURL = http://127.0.0.1:3128
# TLS configuration (system properties can be used, e.g., "${catalina.home}/conf/hawtio.jks")
#ssl.protocol = TLSv1.3
#ssl.truststore = src/test/resources/hawtio.jks
#ssl.truststorePassword = hawtio
#ssl.keystore = src/test/resources/hawtio.jks
#ssl.keystorePassword = hawtio
#ssl.keyAlias = openid connect test provider
#ssl.keyPassword = hawtio
此文件配置 HawtIO+OpenID Connect 的一些方面:
- OAuth2 - 配置授权服务器、客户端 ID 和几个 OpenID Connect 相关选项的位置
- JWKS - 从 jwks_uri 获取的公钥缓存时间,这是公开授权服务器使用的公钥的端点。
- JWT 令牌配置 - 有关声明(JSON Web Token 中的字段)的信息,其中包含与经过身份验证的用户关联的角色。我们还允许将授权服务器中定义的角色映射到应用程序(HawtIO 服务器和 Jolokia)使用的角色。
- HTTP 配置 - 服务器端的 HTTP 客户端用于连接授权服务器(用于获取 OpenID Connect 元数据和公开的公钥)。
这个示例配置可根据特定的需求进行调整,但它在与容器化 Keycloak 一起使用时也可以按原样工作。(请参阅以下)。