如何将用户凭据传递给 WebLogic 11g 身份验证提供程序?

How do you pass user credentials to a WebLogic 11g Authentication Provider?

我认为我对 WebLogic 的 AuthenticationProviders 有较高的了解,但我无法理解如何将用户凭据传递给提供者。


我的理解

在阅读 JAAS 时,我想我已经掌握了如何使用 LoginContext 执行登录。 LoginContext 从 JAAS 配置文件中获取 LoginModule 和 JAAS 选项。通过定义一些 CallbackHandler 的实例,您可以传递用户凭据。调用LoginContext.login()后,使用关联的LoginModule.

进行登录

在阅读了 Oracle 关于 AuthorizationProviders 的文档之后,其中的大部分内容看起来都非常简单。 AuthenticationProvider 利用 JAAS 执行登录。似乎 AuthenticationProvider 在内部管理着 LoginContext

我遇到的困难 grasping/finding 是 WebLogic 如何管理 LoginContext 和最终传递给 [=23= 的 CallbackHandler ]方法。


情况

应用程序:

目前,该应用程序使用表单登录并通过 "j_security_check" 操作提交。有一个自定义 AuthenticationProviderLoginModule 处理登录并处理在表单中提交的用户名和密码。

我假设 WebLogic 可以在内部处理 "j_security_check" 操作,并且知道如何将表单输入字段映射到传递给自定义 LoginModule.[=39 的 CallbackHandler =]


我的目标

我正在尝试创建第二个登录过程,该过程涉及从 HTTP 请求 header 中提取凭据 (username/password)。当前使用 servlet 过滤器提取凭据。无论如何,我想将这些凭据传递给已经用于表单登录的 LoginModule

我想执行以下操作之一:

  1. 直接从 header 获取凭据并将它们传递给 AuthenticationProvider(通过一些自定义 AuthenticationProvider 实现 and/or 配置)
  2. 使用 servlet 过滤器提取 header 凭据并手动将它们传递给 AuthenticationProvider

我的问题

如何将 header 凭据传递给 LoginModule

  1. 是否有预定义的 AuthenticationProvider 可以从 header 中提取用户名和密码?您能描述一下从请求到登录的流程吗?
  2. 有什么方法可以访问 AuthenticationProvider 使用的 CallbackHandlerLoginContext 吗?这样我就可以自己将凭据传递给 AuthenticationProvider
  3. WebLogic 如何知道从何处获取用户凭据以及如何将它们绑定到特定 AuthenticationProvider

我很可能在整个过程中遗漏了一些关键概念,所以请随时让我对我提到的任何事情都走上正轨。

谢谢!

我在理解 WebLogic AuthenticationProviders 方面最大的障碍是理解如何传递凭据。似乎 "automagically" 发生了太多事情 behind-the-scenes。我觉得我必须以某种方式访问​​ WebLogic 在后台操作的 LoginContext and/or CallbackHandler。我在正确的轨道上,但错过了一些关于 JAAS 身份验证的重要信息...

Authentication Providers - How JAAS Works With the WebLogic Security Framework

JAAS 身份验证的第 3 步和第 4 步列为:

  1. The WebLogic Server container calls into the WebLogic Security Framework. If there is a client-side CallbackHandler containing authentication information, this is passed into the WebLogic Security Framework.

  2. For each of the configured Authentication providers, the WebLogic Security Framework creates a CallbackHandler using the authentication information that was passed in. (These are internal CallbackHandlers created on the server-side by the WebLogic Security Framework, and are not related to the client's CallbackHandler.)

这是让我失望的部分。我的想法是 CallbackHandler 向 WebLogic 传递身份验证信息。我没有注意到步骤末尾显示的注释:

Note:

For authentication performed entirely on the server-side, the process would begin at step 3, and the WebLogic Server container would call the weblogic.security.services.authentication.login method prior to step 4.

Authentication - Method Summary

你不知道吗...Authentication有四个 login 方法,每个方法都接受一个 CallbackHandler!

对于我的情况,我可以使用 servlet 过滤器从请求 header 中挑选出凭据,将它们传递给 CallbackHandler,然后调用 Authentication.login(CallbackHandler callbackHandler) 以成功登录自定义 LoginModule.

这是一个旧线程,但我觉得可能值得添加一个与容器无关的选项,即调用 httpRequest.login(username,password) 方法。