Worklight:自定义验证模块例外

时间:2013-05-22 10:09:28

标签: exception authentication login adapter ibm-mobilefirst

我正在调用适配器并使用自定义登录模块保护该适配器,但我未定义任何自定义身份验证器

然后我创建了一个我调用此适配器的Web服务,现在当它调用它时,它会显示调用进入自定义登录模块的凭据,然后出现以下异常。

[5/22/13 10:53:34:359 AST] 0000003a SystemOut     O login was called: aahad1234/aahad1234
5/22/13 10:53:34:359 AST] 0000003a Authenticatio E com.worklight.core.auth.impl.AuthenticationFilter doFilter FWLSE0048E: Unhandled exception caught: null
                                 java.lang.NullPointerException
    at com.worklight.core.auth.impl.AuthenticationContext.logLoginActivity(AuthenticationContext.java:352)
    at com.worklight.core.auth.impl.AuthenticationContext.checkAuthentication(AuthenticationContext.java:495)
    at com.worklight.core.auth.impl.AuthenticationContext.processRealms(AuthenticationContext.java:396)
    at com.worklight.core.auth.impl.AuthenticationContext.pushCurrentResource(AuthenticationContext.java:373)
    at com.worklight.core.auth.impl.AuthenticationServiceBean.accessResource(AuthenticationServiceBean.java:63)
    at com.worklight.core.auth.impl.AuthenticationFilter.doFilter(AuthenticationFilter.java:162)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:895)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1784)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)

[5/22/13 10:53:34:359 AST] 0000003a LocalTranCoor E   WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[5/22/13 10:53:34:359 AST] 0000003a webapp        E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[Static File wrapper]: java.lang.NullPointerException
    at com.worklight.core.auth.impl.AuthenticationContext.logLoginActivity(AuthenticationContext.java:352)
    at com.worklight.core.auth.impl.AuthenticationContext.checkAuthentication(AuthenticationContext.java:495)
    at com.worklight.core.auth.impl.AuthenticationContext.processRealms(AuthenticationContext.java:396)
    at com.worklight.core.auth.impl.AuthenticationContext.pushCurrentResource(AuthenticationContext.java:373)
    at com.worklight.core.auth.impl.AuthenticationServiceBean.accessResource(AuthenticationServiceBean.java:63)
    at com.worklight.core.auth.impl.AuthenticationFilter.doFilter(AuthenticationFilter.java:162)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:895)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1784)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)

我的自定义登录模块:

public class MyCustomLoginModule implements WorkLightLoginModule {

                private String USERNAME ,PASSWORD;

                public void init(Map<String, String> options) throws MissingConfigurationOptionException {
                }
                public MyCustomLoginModule() {
                    ResourceBundle rb = ResourceBundle.getBundle("cardappsettings", Locale.ENGLISH);
                    USERNAME = rb.getString("DispatcherPushUserID") ;
                    PASSWORD = rb.getString("DispatcherPushUserPassword") ;
                }
                public boolean login(Map<String, Object> authenticationData) {
                    System.out.println("Inside Push Adapter ");
                    System.out.println("login was called: " + ((String)authenticationData.get("user.name")) +"/"+ ((String)authenticationData.get("user.password")));
                     System.out.println("user name:"+ ((String)authenticationData.get("user.name")).equals(USERNAME) );
                     System.out.println("user password:"+  ((String)authenticationData.get("user.password")).equals(PASSWORD) );
                     if (((String)authenticationData.get("user.name")).equals(USERNAME) && ((String)authenticationData.get("user.password")).equals(PASSWORD)) 
                        { System.out.println("MyCustomLoginModule - User authenticated Successfully"); 
                         return true;
                        }
                     else 
                        { System.out.println("MyCustomLoginModule - throwing exception..."); 
                         throw new RuntimeException("Invalid credentials");}
                }
                public UserIdentity createIdenity(String loginModule) {
                    HashMap<String, Object> customAttributes = new HashMap<String, Object>();
                    customAttributes.put("AuthenticationDate", new Date());

                    UserIdentity identity = new UserIdentity(loginModule, USERNAME, null, null, customAttributes, PASSWORD);
                    return identity;
                }

                public void logout() {
                    USERNAME = null;
                    PASSWORD = null;
                }

                public void abort() {
                    USERNAME = null;
                    PASSWORD = null;
                }

                @Override
                public MyCustomLoginModule clone() throws CloneNotSupportedException {
                    return (MyCustomLoginModule) super.clone();
                }
            }

我的 authenticationConfig.xml

 <loginModule name="PushAppLoginModule">
            <className>com.rc.MyCustomLoginModule</className>
        </loginModule>

请建议,我是否需要声明自定义身份验证器?或者其他任何东西都缺失了。

非常感谢

1 个答案:

答案 0 :(得分:1)

首先,您必须一起使用authenticator和loginmodule。登录模块知道如何验证凭据,但它没有关于如何收集凭据的线索。根据您的登录模块代码看起来您​​的凭据是用户名和密码。在这种情况下,您可以使用开箱即用的FormBasedAuthenticator(参见WL入门)。如果您需要一些自定义逻辑,则需要实现自定义验证器以及登录模块。