IBM MobileFirst Platform Foundation 7 - 适配器身份验证 - 更新用户身份属性

时间:2015-09-09 10:36:13

标签: authentication cookies ibm-mobilefirst mobilefirst-adapters mobilefirst-server

我正在使用基于适配器的身份验证来保护资源以及管理整个身份验证逻辑(凭据验证)。 如果用户/密码验证成功通过,则调用WL.Server.setActiveUser方法为Realm创建经过身份验证的会话,用户数据存储在userIdentity对象中。

如果验证通过,用户/密码验证过程将返回OK / Fail以及cookie。这个cookie应该在以下适配器调用上发送,所以我也将它添加到userIdentity数据对象中。 我的想法是将它存储在userIdentity对象中,因为它可以在其他适配器(var userIdentity = WL.Server.getActiveUser();)上检索,以便将cookie值添加到适配器的请求标头中,并且它可以正常工作!

有什么问题?适配器响应可以包含此cookie的新值,因此我应该更新userIdentity对象,以便用新值替换cookie的旧值。 尽管如此,userIdentity对象是不可变的,因此它始终包含登录过程获得的原始cookie。

有没有办法更新userIdentity对象?否则,我如何管理一个可变表来保存和更新链接到每个用户会话的cookie,以便将它在适配器请求上发送到后端?

是否有更好的方法来管理每个用户适配器请求所需的后端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())检索时,它包含原始值!

1 个答案:

答案 0 :(得分:1)

  1. 您可以删除userIdentity(WL.Server.setActiveUser("realm", null);),然后设置新的活动用户对象。

  2. 如果您可以依赖HTTP会话(单个服务器或粘性会话),则可以访问会话对象并存储您想要的任何内容。 (WL.Server.getClientRequest().getSession()

  3. 如果您不想使用HTTP会话,则可以使用SQL或Cloudant等外部存储机制来存储该信息。您可以使用Client-ID作为标识符(请参阅示例https://ibm.biz/BdXUHt)。