AAhad
AAhad

Reputation: 2845

Worklight: Custom Authentication Module exception

I am calling an adapter and have protected that adapter with custom login module but I have NOT defined any custom authenticator.

Then i created a Webservice that i calling this adapter, now when it is calling it then it shows that the call goes inside the custom login module with credentials but then below exception appears.

[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)

My Custom Login Module:

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

My authenticationConfig.xml

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

Please suggest, Do i need to declare custom authenticator ? Or anything else is missing.

Thanks alot

Upvotes: 0

Views: 885

Answers (1)

Anton
Anton

Reputation: 3166

First of all, you always must use authenticator and loginmodule together. Login module knows how to validate credentials, but it doesn't have a clue on how to collect them. According to your login module code looks like your credentials are username and password. In this case you can use FormBasedAuthenticator which is available out of the box (see WL gettings started). In case you need some custom logic you will need to implement your custom authenticator as well as login module.

Upvotes: 1

Related Questions