Unknown realm [myRealm]. null returned for key: is

2020-08-02 04:33发布

问题:

I am using IBM Worklight 6.1 and trying to check if the user is authenticated or not:

I have a Realm defined in server/conf/authenticationConfig.xml

<realm name="myRealm" loginModule="myLoginModule">
<className>com.worklight.integration.auth.AdapterAuthenticator</className>
<parameter name="login-function" value="authentication.onAuthRequired" />
<parameter name="logout-function" value="authentication.onLogout" />
</realm>

and its login module

<loginModule name="myLoginModule">
<className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
</loginModule>

and after logging in, or even before that, when I try to check if the user is authenticated or not using

WL.Client.isUserAuthenticated("myRealm")

I have the following response

 Unknown realm [myRealm]. null returned for key: isUserAuthenticated 

Anyone have an idea about that ? Is there something wrong with my Realm definition ? Is there a better way to check if a user is authenticated ?

回答1:

Did you first call to WL.Client.updateUserInfo();?

From the documentation:

updateUserInfo(options)

This method refreshes user data after an exception. Use this method when the application receives an exception after calling the invokeProcedure() method. The method refreshes the data for the following methods:

WL.Client.getUserName(realm)
WL.Client.getLoginName(realm)
WL.Client.isUserAuthenticated(realm)

After such an exception, you can verify the user authentication status by calling this function first, and then the isUserAuthenticated() method.

Parameters: options - Optional. A standard options object.