我正在尝试修改登录的用户身份
var mydata="this is custom data array";
var user = JSON.parse(JSON.stringify(WL.Server.getActiveUser()));
WL.Logger.debug("Before Update" + user.attributes);
WL.Logger.debug(" displayName =" + user.displayName );
WL.Logger.debug("isUserAuthenticated ="+ user.isUserAuthenticated );
WL.Logger.debug("userId =" + user.userId );
WL.Server.setActiveUser ("myAppRealm" ,{ userId: user.userId ,
displayName: user.displayName,
isUserAuthenticated: user.isUserAuthenticated,
attributes: { userdata: mydata }
} );
WL.Logger.debug(" ---- Updateed user ---- " );
var user = JSON.parse(JSON.stringify(WL.Server.getActiveUser()));
但给出以下异常。
response [/apps/services/api/myApp/common/query] success: /*-secure-
{"isSuccessful":false,"warnings":[],"errors":["Illegal State: Cannot change identity of an already logged in user in realm 'myAppRealm'. The application must logout first."],"responseID":"67","info":[]}*/ worklight.js:1097
Procedure invocation error. Illegal State: Cannot change identity of an already logged in user in realm 'myAppRealm'. The application must logout first.
我该如何修改?
修改
@Xv。好吧,那次我需要在用户的会话对象中保存一些值。为此,我首先尝试修改用户的对象,如上所述,但后来我发现下面提到的API有助于在会话对象中检索,修改或添加值。
WL 6.3文档:
访问HttpServletRequest对象。
- WL.Server.getClientRequest
这使您可以直接访问 HttpServletRequest 对象,然后就像在JEE应用程序中一样使用它的所有方法。
例如:
WL.Server.getClientRequest()。的getSession()。的getAttribute( “的myKey”) WL.Server.getClientRequest()。getSession()。setAttribute(“mykey”,myobj)
答案 0 :(得分:2)
始终在getActiveUser
API中提供领域名称,例如WL.Server.getActiveUser("myRealm")
正如错误消息所示 - 您无法更改活动用户身份,不可变。您需要做的是首先通过调用WL.Server.setActiveUser("myRealm", null)
处理现有用户身份,然后调用WL.Server.setActiveUser("myRealm", {...})