I am trying to change the registered user ID,
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()));
but it gives below exceptions .
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.
How can i change this?
Edit:
@Xv. Well, at that time I had a requirement to store some values in a user session object. To do this, I first tried to modify the user object, as mentioned above, but then I found the APIs mentioned below that help in getting, changing, or adding values to the session object.
WL 6.3 docs:
Access to the HttpServletRequest object.
- WL.Server.getClientRequest
HttpServletRequest, , JEE.
:
WL.Server.getClientRequest(). GetSession(). GetAttribute ( "MyKey" ) WL.Server.getClientRequest(). GetSession(). SetAttribute ( "mykey", myobj)