问题
Using Mobilefirst Platform 7.1,
I have a custom authenticator and login module. It the similar as the sample in the docs
I also have an java adapter with an endpoint that is protected with a realm that uses the authenticator and login modules.
WLServerAPI serverAPI= WLServerAPIProvider.getWLServerAPI();
@Path("/qdef")
@Produces("application/json")
@GET
@OAuthSecurity(scope="MyAuthenticatorRealm")
public Response getQdef(){
SecurityAPI security = serverAPI.getSecurityAPI();
/** Next line appears in below stack trace as com.ibm.jp.SubqmjrPcApiResource.getQdef(SubqmjrPcApiResource.java:92) **/
OAuthUserIdentity identity = security.getSecurityContext().getUserIdentity();
String username = identity.getId(); // *** identity is null ***
String displayName = identity.getDisplayName();
logger.info("id:"+username+", name:"+displayName);
...
}
However that endpoint return 500 since an exception occurs. identity object is null
. Why is this? Is this the correct way of accessing user id?
Things that I have checked:
Authenticator seems to works fine: The first time I call the api, my browser app enters the login flow. I have checked with the debugger that the authenticator correctly holds
username
andpassword
. Also I have checked thatgetAuthenticationData()
method correctly makes a Map with such info.Login module seems to work fine too. It is correctly initialised and it receives correct info at
login(Map<String, Object> authenticationData)
method. It stores the username and password to later create anUserIdentity
object inUserIdentity createIdentity(String loginModule)
method. I have checked that this method contains the right data.The client browser app successfully received
{authStatus:"required"}
and then{authStatus:"completed"}
. Prior to reach inside thegetQdef()
method.
This is just the tip of the error and stack trace (scroll right to see the file/lines):
[8/27/15 15:53:39:235 JST] 0000008b ication.internal.jaas.modules.UsernameAndPasswordLoginModule A CWWKS1100A: Authentication did not succeed for user ID oLs3jn4fNG. An invalid user ID or password was specified.
[8/27/15 15:53:39:350 JST] 000000b0 SystemErr R java.util.zip.ZipException: zip file is empty
[8/27/15 15:53:39:350 JST] 000000b0 SystemErr R at java.util.zip.ZipFile.open(Native Method)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.zip.ZipFile.<init>(ZipFile.java:220)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.zip.ZipFile.<init>(ZipFile.java:150)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.jar.JarFile.<init>(JarFile.java:166)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at java.util.jar.JarFile.<init>(JarFile.java:130)
[8/27/15 15:53:39:351 JST] 000000b0 SystemErr R at com.worklight.adapters.rest.ParentLastClassLoader.findResourceInURL(ParentLastClassLoader.java:522)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at com.worklight.adapters.rest.ParentLastClassLoader.internalFindResource(ParentLastClassLoader.java:472)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at com.worklight.adapters.rest.ParentLastClassLoader.internalFindClass(ParentLastClassLoader.java:212)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at com.worklight.adapters.rest.ParentLastClassLoader.loadClass(ParentLastClassLoader.java:128)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at com.ibm.jp.SubqmjrPcApiResource.getQdef(SubqmjrPcApiResource.java:92)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[8/27/15 15:53:39:352 JST] 000000b0 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[8/27/15 15:53:39:353 JST] 000000b0 SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[8/27/15 15:53:39:353 JST] 000000b0 SystemErr R at java.lang.reflect.Method.invoke(Method.java:497)
[8/27/15 15:53:39:353 JST] 000000b0 SystemErr R at org.apache.wink.server.internal.handlers.InvokeMethodHandler.handleRequest(InvokeMethodHandler.java:63)
Entire stack trace is here
The user/password I tried was admin
/admin
. So I have no idea were does that message comes from. I wonder what I am missing?
Any help is highly appreciated.
EDIT 2015/08/27 17:28 +0900
Is this kind of message: Authentication did not succeed for user ID KRJxLToMJb. An invalid user ID or password was specified.
related to
the result of securityContext.toJSON().toString()
?
{"imf.application":{"environment":"common","id":"subqmgr","version":"1.0"}, "imf.sub":"::KRJxLToMJb","imf.device":{"osVersion":"","model":"","id":"","platform":null}, "imf.user":null}`
回答1:
In order for adapters to have access to the User ID, your application descriptor needs contains a value for userIdentityRealms
.
来源:https://stackoverflow.com/questions/32243330/how-to-get-user-id-from-adapter