15.5. 使用带有 Microsoft Entra ID 的 HawtIO 和 OpenID Connect 身份验证
HawtIO 4 还使用 Microsoft Entra ID 测试。在理论上,应该使用任何 OpenID Connect 供应商的所有内容都是访问相关的 OpenID 提供程序元数据,在实践中,我们需要一些特定于供应商的配置。
客户端使用 "App registrations" 刀片在 Entra ID 中注册。在注册应用程序时,最重要的决定是平台类型的 Redirect URI:

有 2 个选项可供选择(我们不考虑"Public client/native (mobile & desktop) "平台)。稍后配置 Redirect URI 时会显示此 UI:

虽然这不太明显了在第一眼中选择的内容,但它足以出现:
Web 平台 :
这种类型的客户端适合服务器端应用程序和 API。
SPA 平台 :
SPA 应用程序在浏览器中运行,它自然使用"Authorization Code Flow"和所谓的公共客户端。其原因是,在浏览器应用程序中存储凭证和 secret 没有好的方式。
选择 SPA 平台为我们提供了在 Entra ID UI 中的标记:

15.5.1. 在 Entra ID 中使用单个 SPA 客户端
在 Entra ID 中配置 SPA 客户端后,我们可以已在 hawtio-oidc.properties
中设置相关选项。在 Entra ID 中的"应用程序注册"刀片中,我们可以单击"Endpoints"选项卡并显示以下信息:

租户 ID 是特定于正在使用的 Entra ID / Azure 租户的 UUID。以下是 HawtIO 配置,其中 provider
是租户的基本 URL,client_id 是 App Registration 页面概述中的"应用程序(客户端)ID"。
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
# 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 = https://login.microsoftonline.com/00000000-1111-2222-3333-444444444444/v2.0
# OpenID client identifier
client_id = 55555555-6666-7777-8888-999999999999
# 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
此类配置的问题(其中 openid email profile
作为 范围
参数发送)是假定的范围位于事实上 openid profile 用户
。读和授予的访问令牌为 (仅显示相关的 JWT 声明):
{ "aud": "00000003-0000-0000-c000-000000000000", "iss": "https://sts.windows.net/8fd8ed3d-c739-410f-83ab-ac2228fa6bbf/", ... "app_displayname": "hawtio", ... "scp": "email openid profile User.Read", ... }
{
"aud": "00000003-0000-0000-c000-000000000000",
"iss": "https://sts.windows.net/8fd8ed3d-c739-410f-83ab-ac2228fa6bbf/",
...
"app_displayname": "hawtio",
...
"scp": "email openid profile User.Read",
...
}
aud
(audience)声明为 00000003-0000-0000-c000-000000000000
,它是 … Microsoft Graph API 的 OAuth2 客户端 ID。
HawtIO 服务器(使用 Jolokia 代理)不应使用这样的访问令牌,也使用与 Microsoft Graph API 关联的密钥创建签名。
为了正确配置 Entra ID 并确保由 HawtIO 服务器 可使用 的访问令牌,我们需要 两个应用程序注册 - 适用于 HawtIO 客户端和 HawtIO 服务器。请参见以下子章节。
15.5.2. 在 Entra ID 中将 SPA 与 Web 客户端一起使用
建议您在 Entra ID 中设置两个应用程序注册:
- HawtIO 客户端应用程序的 SPA 客户端 - 这是配置启用了 PKCE 的 OAuth2 公共客户端 的方法。
-
HawtIO 服务器应用程序的 Web (API)客户端(实际上,其 Jolokia API)- 这是 Entra ID,它公开为名为范围(例如)
api://hawtio-server/Jolokia.Access
,然后在上面的 HawtIO 客户端应用程序中配置它作为允许的 API。
最后,当启动 Authorization Code Flow 在 scope
参数中的其中一个请求范围时,为 HawtIO Server 应用程序(如 api://hawtio-server/Jolokia.Access
)定义的范围。
我们来总结 Entra ID 中所需的配置。
-
使用 "Web" Redirect URI 创建
hawtio-server
应用注册。 在 "Expose a API" 部分,添加一个代表来自 HawtIO 客户端请求的访问范围的范围:
这将创建一个可引用的
api://hawtio-server/Jolokia.Access
范围。在
hawtio-server
的"App roles"部分中定义您要分配给此客户端范围内用户的任何角色,例如:在"企业应用程序"用于
hawtio-server
的刀片式中,转至"用户和组"选项卡并添加用户角色分配。例如:使用 "SPA" Redirect URI 创建
hawtio-client
应用程序注册。在用于
hawtio-client
应用程序注册的"API Permissions"部分,为hawtio-server
公开 API 添加 委托权限 :这应该配置一组委托的权限,如下所示:
注意阅读 Microsoft Entra ID 文档中的 委托权限的更多信息。
-
对于企业应用刀片中的
hawtio-client
,不需要 User-Role 映射。 在配置了以上配置后,我们可以在 HawtIO 配置中正确设置
scope
参数:这将创建一个可引用的
api://hawtio-server/Jolokia.Access
范围。-
在
hawtio-server
的"App roles"部分中定义您要分配给此客户端范围内用户的任何角色,例如: -
在"企业应用程序"用于
hawtio-server
的刀片式中,转至"用户和组"选项卡并添加用户角色分配。例如: -
使用 "SPA" Redirect URI 创建
hawtio-client
应用程序注册 在用于
hawtio-client
应用程序注册的"API Permissions"部分,为hawtio-server
公开 API 添加委托权限:这应该配置一组委托的权限,如下所示:
注意阅读 Microsoft Entra ID 文档中的 委托权限的更多信息。
-
对于企业应用刀片中的
hawtio-client
,不需要 User-Role 映射。
在配置了以上配置后,我们可以在 HawtIO 配置中正确设置 scope 参数:
scope to request when performing OpenID authentication. MUST include "openid" and required permissions
# scope to request when performing OpenID authentication. MUST include "openid" and required permissions
scope = openid email profile api://hawtio-server/Jolokia.Access
15.5.3. 访问令牌配置
最后,但非常重要的配置项是 Token Configuration。对于 hawtio-server
应用注册,这是代表 HawtIO 服务器(并且是消耗授予访问令牌的组件)的应用程序,我们必须确保将组声明添加到访问令牌中。
以下是最小配置:

组
声明需要包含 安全组和 目录角色和 组,需要按名称而不是 UUID 表示:

请参考以下的 hawtio-server
应用程序注册清单的相关 JSON 片断:
"optionalClaims": { "idToken": [ { "name": "groups", "source": null, "essential": false, "additionalProperties": [] } ], "accessToken": [ { "name": "groups", "source": null, "essential": false, "additionalProperties": [ "sam_account_name" ] }, ...
"optionalClaims":
{
"idToken":
[
{
"name": "groups",
"source": null,
"essential": false,
"additionalProperties": []
}
],
"accessToken":
[
{
"name": "groups",
"source": null,
"essential": false,
"additionalProperties":
[
"sam_account_name"
]
},
...
现在,授予的访问令牌不再特定于 Microsft Graph API audience。它适用于 hawtio-server
- aud
声明是 hawtio-server
应用程序注册和 appid
声明的 UUID 是 hawtio-client
应用程序注册的 UUID:
{ "aud": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", "iss": "https://sts.windows.net/.../", "iat": 1709626257, "nbf": 1709626257, "exp": 1709630939, ... "appid": "55555555-6666-7777-8888-999999999999", ... "groups": [ ... ], ... "name": "hawtio-viewer", ... "roles": [ "HawtIO.User" ], "scp": "Jolokia.Access",
{
"aud": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"iss": "https://sts.windows.net/.../",
"iat": 1709626257,
"nbf": 1709626257,
"exp": 1709630939,
...
"appid": "55555555-6666-7777-8888-999999999999",
...
"groups":
[
...
],
...
"name": "hawtio-viewer",
...
"roles":
[
"HawtIO.User"
],
"scp": "Jolokia.Access",
然后,转换的角色(可能使用映射)可在 角色
声明中找到,这反映在配置中:
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 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
# 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
...
# 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.HawtIO.User = user
...