我们正在构建一个 Worklight 应用程序,该应用程序具有两步身份验证过程。
第 1 步:表单例份验证
我们使用开箱即用的 WASLTPARealm,它根据 WebSphere 中的自定义 JAAS 模块对我们进行身份验证并返回 LTPA token 。这按预期工作。
第 2 步:自定义身份 validator
第二步是自定义身份 validator 和登录模块,其中:
- 读取第 1 步中设置的 LTPA cookie
- 使用 LTPA cookie 向另一个应用程序发出 POST 请求(这 2 个应用程序通过单点登录受到信任)
- POST 请求返回带有附加 session Cookie 的响应
- 用户已通过身份验证
问题是,使用文档中提供的客户端代码时,自定义身份 validator 不会触发。基本上
customAuthenticator 是通过通常的方式创建的
var customAuthenticator = WL.Client.createChallengeHandler("MyCustomRealm");
然后在客户端代码中进一步
var reqURL = '/my_custom_auth_request_url';
var options = {};
options.parameters = {};
options.headers = {};
customAuthenticator.submitLoginForm(reqURL, options, customAuthenticator.submitLoginFormCallback);
导致 404
[27/05/13 10:35:07:616 NZST] 00000326 WebSphereForm I com.worklight.core.auth.ext.WebSphereFormBasedAuthenticator processRequest FWLSE0055I: Not recognized.
[27/05/13 10:35:07:616 NZST] 00000326 Authenticatio E com.worklight.core.auth.impl.AuthenticationFilter doFilter FWLSE0048E: Unhandled exception caught: SRVE0190E: File not found: /apps/services/my_custom_auth_request_url
java.io.FileNotFoundException: SRVE0190E: File not found: /apps/services/my_custom_auth_request_url
发生这种情况是因为请求是由 WebSphereFormBasedAuthenticator 而不是我们的自定义 validator 接收的。
我们通过
将请求 URL 写入自定义 validator 内的日志public AuthenticationResult processRequest(HttpServletRequest request, HttpServletResponse response, boolean isAccessToProtectedResource) throws IOException, ServletException {
logger.info("Request URL is: " + request.getRequestURI());
但是这条线永远不会被击中。
2 个 validator 可以并行工作吗?我看到的行为是这样的
var wlFormsAuthenticator = WL.Client.createChallengeHandler("WASLTPARealm");
和
var customAuthenticator = WL.Client.createChallengeHandler("MyCustomRealm");
好像有点搞混了。我认为在 customAuthenticator 上调用 submitLoginForm
不应该被 WebSphereForms validator 接收,而应该转到我们的自定义 validator 。
您能否澄清预期的行为和潜在的解决方法?
此外,有效的是调用
WL.Client.login("MyCustomRealm", {
onSuccess: function() {
},
onFailure: function() {
}
});
在这种情况下,Java 代码被命中,我们成功地进行了身份验证但是,URL 是
http://localhosT:9080/worklight/apps/services/api/MyApp/common/login
而不是 my_custom_auth_request_url
,这意味着我们无法过滤掉 Java 代码中的请求。
希望这是有道理的。提前致谢。
最佳答案
您的描述中似乎混合了术语。 validator 是服务器端实体。自定义 validator 是用 Java 实现的。 挑战处理程序是客户端实体。它是用 JavaScript 实现的。
根据您的描述,我猜测您在实际尝试从 WL 服务器获取某些资源之前尝试提交自定义身份 validator 的登录表单。问题是只有在您尝试访问 protected 资源时才会创建自定义身份 validator 的实例。除非您首先触发身份验证,否则身份 validator 将拒绝接收凭据(或者更一般地说 - 它不会真正存在)。所以你的方法是正确的,你可以先调用 WL.Client.login("realm") 来触发身份验证过程。其他选项有:
- 使用安全测试保护应用程序环境并设置 connectOnStartup:true
- 使用安全测试保护应用环境,设置 connectOnStartup:false 并使用 WL.Client.connect() API。
关于java - 多领域身份验证(表单+自定义身份 validator ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16764446/