IBM MobileFirst Platform Foundation 7 - 适配器认证 - 更新用户身份属性
IBM MobileFirst Platform Foundation 7 - Adapter authentication - Update the user identity attributes
我正在使用基于适配器的身份验证来保护资源以及管理整个身份验证逻辑(凭证验证)。
如果 user/password 验证成功通过,将调用 WL.Server.setActiveUser
方法为 Realm 创建经过身份验证的 session,用户数据存储在 userIdentity object.[=15= 中]
user/password 验证过程 returns OK/Fail 如果验证通过,还有一个 cookie。此 cookie 应在以下适配器调用中发送,因此我也将其添加到 userIdentity 数据 object 中。
我的想法是将它存储在 userIdentity object 中,因为它可以在其他适配器 (var userIdentity = WL.Server.getActiveUser();
) 上检索,以便将 cookie 值添加到适配器的请求 header 中并且它可以正常工作!
有什么问题吗?适配器响应可以包含此 cookie 的新值,因此我应该更新 userIdentity object 以用新值替换 cookie 的旧值。
然而,userIdentity object 是 immutable 因此它始终包含登录过程获得的原始 cookie。
有没有办法更新 userIdentity object?否则,我如何管理一个 mutable table 来保存和更新链接到每个用户的 cookie session 以便根据适配器请求将其发送到后端?
是否有更好的方法来管理每个用户适配器请求所需的后端 cookie?
非常感谢!
塞尔吉
PS: 有一个问题试图解决这个问题,但可能的答案对我无效 (IBM MobileFirst Platform Foundation 6.3: Can we edit the custom attributes of User Identity Object [MobileFirst Session]):
我尝试了以下代码来更新 userIdentity:
var newUserIdentity = {
userId: userIdentity.userId,
attributes: {
cookies: newValue
}
};
WL.Server.setActiveUser(realm, null);
WL.Server.setActiveUser(realm, newUserIdentity);
但是当它从另一个适配器 (var userIdentity = WL.Server.getActiveUser()
) 检索时,它包含原始值!
您可以删除 userIdentity (WL.Server.setActiveUser("realm", null);
),然后设置一个新的活动用户对象。
如果你可以依赖 HTTP 会话(单服务器或粘性会话),你可以访问会话对象并存储任何你想要的东西。 (WL.Server.getClientRequest().getSession()
)
如果您不想使用 HTTP 会话,您可以使用外部存储机制,例如 SQL 或 Cloudant 来存储该信息。您可以使用 Client-ID 作为标识符(参见示例 https://ibm.biz/BdXUHt)。
我正在使用基于适配器的身份验证来保护资源以及管理整个身份验证逻辑(凭证验证)。
如果 user/password 验证成功通过,将调用 WL.Server.setActiveUser
方法为 Realm 创建经过身份验证的 session,用户数据存储在 userIdentity object.[=15= 中]
user/password 验证过程 returns OK/Fail 如果验证通过,还有一个 cookie。此 cookie 应在以下适配器调用中发送,因此我也将其添加到 userIdentity 数据 object 中。
我的想法是将它存储在 userIdentity object 中,因为它可以在其他适配器 (var userIdentity = WL.Server.getActiveUser();
) 上检索,以便将 cookie 值添加到适配器的请求 header 中并且它可以正常工作!
有什么问题吗?适配器响应可以包含此 cookie 的新值,因此我应该更新 userIdentity object 以用新值替换 cookie 的旧值。 然而,userIdentity object 是 immutable 因此它始终包含登录过程获得的原始 cookie。
有没有办法更新 userIdentity object?否则,我如何管理一个 mutable table 来保存和更新链接到每个用户的 cookie session 以便根据适配器请求将其发送到后端?
是否有更好的方法来管理每个用户适配器请求所需的后端 cookie?
非常感谢! 塞尔吉
PS: 有一个问题试图解决这个问题,但可能的答案对我无效 (IBM MobileFirst Platform Foundation 6.3: Can we edit the custom attributes of User Identity Object [MobileFirst Session]): 我尝试了以下代码来更新 userIdentity:
var newUserIdentity = {
userId: userIdentity.userId,
attributes: {
cookies: newValue
}
};
WL.Server.setActiveUser(realm, null);
WL.Server.setActiveUser(realm, newUserIdentity);
但是当它从另一个适配器 (var userIdentity = WL.Server.getActiveUser()
) 检索时,它包含原始值!
您可以删除 userIdentity (
WL.Server.setActiveUser("realm", null);
),然后设置一个新的活动用户对象。如果你可以依赖 HTTP 会话(单服务器或粘性会话),你可以访问会话对象并存储任何你想要的东西。 (
WL.Server.getClientRequest().getSession()
)如果您不想使用 HTTP 会话,您可以使用外部存储机制,例如 SQL 或 Cloudant 来存储该信息。您可以使用 Client-ID 作为标识符(参见示例 https://ibm.biz/BdXUHt)。