【发布时间】:2015-09-09 10:36:13
【问题描述】:
我正在使用基于适配器的身份验证来保护资源以及管理整个身份验证逻辑(凭据验证)。
如果用户/密码验证成功通过,则调用 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]): 我尝试了以下代码来更新用户身份:
var newUserIdentity = {
userId: userIdentity.userId,
attributes: {
cookies: newValue
}
};
WL.Server.setActiveUser(realm, null);
WL.Server.setActiveUser(realm, newUserIdentity);
但是当它从另一个适配器 (var userIdentity = WL.Server.getActiveUser()) 检索时,它包含原始值!
【问题讨论】:
-
为什么链接的问题对您无效?
-
问题中添加了说明。
-
我尝试直接管理cookie,但没有成功stackoverflow.com/questions/28753979/…
标签: authentication cookies ibm-mobilefirst mobilefirst-adapters mobilefirst-server