Note that there are some explanatory texts on larger screens.

plurals
  1. POWorklight: WL.Server.setActiveUser - Can't modify - Illegal State: Cannot change identity
    primarykey
    data
    text
    <p>I am trying to modify the logged in user identity, </p> <pre><code>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())); </code></pre> <p>but its <strong>giving below exception</strong>.</p> <pre><code>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. </code></pre> <p>How can I modify this?</p> <p><strong>Edit:</strong></p> <p>@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. </p> <p><strong>WL 6.3 docs:</strong></p> <ul> <li><a href="http://www-01.ibm.com/support/knowledgecenter/SSHS8R_6.3.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html?cp=SSHS8R_6.3.0%2F9-1-0-1-6" rel="nofollow noreferrer">MobileFirst server-side API>JavaScript server-side API>Classes>WL.Server</a></li> </ul> <blockquote> <p>Accessing an HttpServletRequest object. </p> <ul> <li>WL.Server.getClientRequest</li> </ul> </blockquote> <p>This gives you direct access to <strong>HttpServletRequest</strong> object and then you can use all of its methods as you would do in JEE applications.</p> <p><em>For example:</em></p> <blockquote> <p>WL.Server.getClientRequest().getSession().getAttribute("mykey") WL.Server.getClientRequest().getSession().setAttribute("mykey", myobj)</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload