如何从适配器获取用户 ID

How to get user id from adapter

使用 Mobilefirst Platform 7.1,

我有一个自定义验证器和登录模块。它类似于 docs

中的示例

我还有一个 java 适配器,其端点受到使用身份验证器和登录模块的领域的保护。

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);
    ... 
}

但是那个端点return500因为出现了异常。标识对象是 null。为什么是这样?这是访问用户 ID 的正确方法吗?

我检查过的东西:

这只是错误提示和堆栈跟踪(向右滚动以查看 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

我试过的user/password是admin/admin。所以我不知道这条消息是从哪里来的。我想知道我错过了什么?

非常感谢任何帮助。

编辑 2015/08/27 17:28 +0900 这种消息:Authentication did not succeed for user ID KRJxLToMJb. An invalid user ID or password was specified.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}`

为了让适配器能够访问用户 ID,您的应用程序描述符需要包含 userIdentityRealms 的值。