本文介绍了Worklight:WL.Server.setActiveUser - 无法修改 - 非法状态:无法更改标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改登录的用户身份,

I am trying to modify the logged in user identity,

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有助于在会话对象中检索,修改或添加值。

@Xv. Well, that time I had requirement to save some values in a user's session object. For that I first tried modifying user's object as mentioned above but then I found below mentioned APIs that helps in retrieving , modifying or adding values in a session object.

WL 6.3 docs:



  • MobileFirst server-side API>JavaScript server-side API>Classes>WL.Server

  • WL.Server.getClientRequest

这使您可以直接访问 HttpServletRequest 对象,然后就像在JEE应用程序中一样使用它的所有方法。

This gives you direct access to HttpServletRequest object and then you can use all of its methods as you would do in JEE applications.

例如:


推荐答案


  1. 始终中提供领域名称getActiveUser API,例如 WL.Server.getActiveUser(myRealm)

  1. Always supply a realm name in getActiveUser API, e.g. WL.Server.getActiveUser("myRealm")

就像错误信息所说 - 你无法改变活跃的用户身份,可变。您需要做的是首先通过调用 WL.Server.setActiveUser(myRealm,null)来处置现有用户身份,然后调用 WL .Server.setActiveUser(myRealm,{...})

Just like error message says - you cannot alter active user identity, it is not mutable. What you need to do is to dispose of existing user identity first by invoking WL.Server.setActiveUser("myRealm", null) and then call WL.Server.setActiveUser("myRealm", {...})

这篇关于Worklight:WL.Server.setActiveUser - 无法修改 - 非法状态:无法更改标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:11