我正在尝试修改登录的用户身份,
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)