尝试针对 OAuth 2 服务器 UAA 对 RabbitMQ 进行身份验证

问题描述

我在 Spring Boot 中有一个工作应用程序,我使用 application.properties 文件中定义的属性建立连接并验证到 RabbitMQ,如下所示

spring:
 rabbitmq:
 host: xx.xx.xx.111
 port: 5672
 username: user
 password: password

现在我想使用访问令牌针对 OAuth-2 对与 RabbitMQ 的每次通信进行身份验证,以便对队列进行读/写操作。为此,我现在正在尝试使用 Cloud Foundry UAA 授权服务器。 我按照以下链接实现上述

  1. https://www.rabbitmq.com/api-guide.html#oauth2-support
  2. https://github.com/rabbitmq/rabbitmq-auth-backend-oauth2#examples

我在 RabbitMQ 中启用了以下插件

rabbitmq_auth_backend_oauth2,rabbitmq_management

并且我已经使用以下详细信息更新了本地 RabbitMQ 特定配置文件 */RabbitMQ/advanced.config

[
% Enable auth backend
{rabbit,[
    {auth_backends,[rabbit_auth_backend_oauth2,rabbit_auth_backend_internal]}
]},{rabbitmq_management,[
     {enable_uaa,true},{uaa_client_id,"rabbit_client"},{uaa_location,"http://localhost:8080/uaa"}
]},{rabbitmq_auth_backend_oauth2,[
{resource_server_id,<<"rabbitmq">>},{key_config,[
  {default_key,<<"legacy-token-key">>},{signing_keys,#{
    <<"legacy-token-key">> => {map,#{<<"kty">> => <<"MAC">>,<<"alg">> => <<"HS256">>,<<"use">> => <<"sig">>,<<"value">> => <<"tokenKey">>}}
  }}
]} ]}].

我正在使用 UAA 对称签名密钥,以便在 RabbitMQ 上解密和验证客户端提供的令牌。 然后我准备好了所有基本客户端的 env,用户在 UAA 和 RabbitMQ 中都设置了。我按照步骤从 configure a user and groups

配置客户端、用户及其权限

现在,在完成上述所有设置后,我编写了基本的 Java 程序以使用 OAuth-2 授权作为 UAA 连接到 RabbitMQ,并且能够按照 Link-1 中的建议成功连接到 RabbitMQ。

但是,当我想查看 RabbitMQ 管理 UI 时,我访问 http://localhost:15672/ 并在那里访问 RabbitMQ 管理页面,如下所示

enter image description here

一旦单击“单击此处登录”,它就会将我带到 UAA 页面,它要求我提供我提供的用户名和密码,但它不接受我的凭据,并给出如下错误

enter image description here

我能够从 Java 程序成功登录到 RabbitMQ,使用 UAA 作为授权服务器,客户端为 rabbit_client,用户为 rabbit_super,grant_type 为密码.

CredentialsProvider credentialsProvider =
              new OAuth2ClientCredentialsGrantCredentialsProviderBuilder()
                .tokenEndpointUri("http://localhost:8080/uaa/oauth/token/")
                .clientId("rabbit_client").clientSecret("rabbit_secret")
                .grantType("password")
                .parameter("username","rabbit_super")
                .parameter("password","rabbit_super")
                .build();

当我在 RabbitMQ 管理页面上使用与 rabbit_super 相同的用户名和密码以及它的 access_tokon 作为密码时,UAA 要求我提供它不起作用的详细信息,并给出错误

提供的凭据无效。请重试。

所以我在本地检查了UAA的后端日志,日志详细信息如下

uaa_event.log

Audit: IdentityProviderAuthenticationFailure ('rabbit_super'): principal=null,origin=[remoteAddress=0:0:0:0:0:0:0:1,sessionId=<SESSION>],identityZoneId=[uaa],authenticationType=[uaa]
Audit: UserAuthenticationFailure ('rabbit_super'): principal=72e53395-1c54-4136-b239-34845f09ef96,identityZoneId=[uaa]
Audit: PrincipalAuthenticationFailure ('null'): principal=rabbit_super,origin=[0:0:0:0:0:0:0:1],identityZoneId=[uaa]

uaa.log

 ERROR --- SecurityFilterChainPostProcessor$HttpsEnforcementFilter: Uncaught Exception:
org.springframework.security.oauth2.common.exceptions.InvalidGrantException: A redirect_uri can only be used by implicit or authorization_code grant types.

我不知道为什么会出现 IdentityProviderAuthenticationFailure ('rabbit_super') 错误,它无法将 IdentityZone 中的用户理解为 UAA。 我已在 UAA 中将客户端设置为 rabbit_client 并将其授予类型设置为 password,client_credentials 并使用以下 gem 命令

uaac client add rabbit_client --name rabbit_client --scope 'rabbitmq.*' --authorized_grant_types password,client_credentials --authorities rabbitmq --secret rabbit_secret --redirect_uri 'http://localhost:15672'

请在这个问题上帮助我,我在这一点上感到震惊,不知道为什么 rabbitMQ 管理 UI 不接受 rabbit_super 及其 access_token 作为密码。 OAuth 2 插件已在 RabbitMQ 服务器端启用,并且已在本地配置为使用相同的 OAuth 2 UAA 服务器。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...