0
votes

I am developing jQuery based mobile app and trying to use Single Step authentication using my custom login page. The login page collects loan# and pin from the user and use them to query MS SQL Server database as shown below.

I created SQL adapter to access MS SQL Server database and it works successfully from workspace when I select adapter -> Run As -> Invoke Adapter procedure. But it does not work from my challaengerHandler.js and throws the exception. I already stored the sqljdbc4.jar file into project's server/lib folder.

Here is the contents from adapter.xml


<displayName>LoanInfoMSSQLAdapter</displayName>
<description>LoanInfoMSSQLAdapter</description>
<connectivity>
    <connectionPolicy xsi:type="sql:SQLConnectionPolicy">
        <!-- Example for using a JNDI data source, replace with actual data source name -->
        <!-- <dataSourceJNDIName>java:/data-source-jndi-name</dataSourceJNDIName> -->

        <!-- Example for using MySQL connector, do not forget to put the MySQL connector library in the project's lib folder -->
        <dataSourceDefinition>
           <driverClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</driverClass>
           <url>jdbc:sqlserver://9.22.93.21:1433;database=CustDB</url>
           <user>lbps</user>
           <password>lbps</password>
        </dataSourceDefinition>
    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="5" />
</connectivity>

<!-- Replace this with appropriate procedures -->
<procedure name="getLoanInfoFromDB"/>

Here is the contents from adapter-impl.js


var getLoanInfoStatement = WL.Server.createSQLStatement( 
"SELECT account_id, pin, borr_ssn " +
"FROM vw_wcc_cust " +
"WHERE vw_wcc_cust.account_id = ? AND pin = ?;"
);


function getLoanInfoFromDB(loan, pin) {
return WL.Server.invokeSQLStatement({
    preparedStatement : getLoanInfoStatement,
    parameters : [loan, pin]
});
}

Here is the contents Challangerhandler.js


$("#AuthSubmitButton").bind('click', function () {
WL.Logger.debug("SUBMIT button clicked...");

var loan = $("#AuthLoan").val();
var pin = $("#AuthPin").val();

WL.Logger.debug("AuthLoan = " + loan);
WL.Logger.debug("AuthPin = " + pin);

WL.Logger.debug("Invoking WL.Client.connect() function to check for connectivity...");

var connectOptions = {
    onSuccess : function() {
        WL.Logger.debug("Device is connected to WL server");

        var invocationData = {
            adapter : "SetSnapshotAuthAdapter",
            procedure : "submitAuthentication",
            parameters : [ loan, pin ]
        };

            SetSnapshotAuthRealmChallengeHandler.submitAdapterAuthentication(invocationData, {});
    }, 
     onFailure: function() { 
        WL.Logger.debug("Device is NOT connected to WL server");
        alert("Worklight Server Unavailable.  Try your request later-001");
     }  
};

WL.Client.connect(connectOptions);
});

Here is the contents of submitAuthentication () function for SIngle Step Authentication Adapeter's js file


function submitAuthentication(loan, pin){

WL.Logger.info("Inside submitAuthentication");

WL.Logger.info("Loan = " + loan);
WL.Logger.info("Pin = " + pin);


var loanInfos = WL.Server.invokeSQLStatement({
    preparedStatement : getLoanInfoStatement,
    parameters : [loan, pin]
});




var username = "seterus";

// if (username === "seterus" && password === "seterus"){

if (loanInfos) {

    var userIdentity = {
            userId: username,
            displayName: username, 
            attributes: {
                foo: "bar",
                loan: loan,
                pin: pin,
                isSuccessful: loanInfos.isSuccessful
            }
    };

    WL.Logger.info("Loan from userIdentity = " + userIdentity.attributes.loan);
    WL.Logger.info("Pin from userIdentity = " + userIdentity.attributes.pin);

    WL.Server.setActiveUser("SetSnapshotAuthRealm", userIdentity);

    WL.Logger.info("Returning authRequired as FALSE to display loan info...");

    return { 
        authRequired: false
    };
}

return onAuthRequired(null, "Invalid login credentials");
}

Upon entering the loan# and pin and then slicking Submit button, I get the following exception in the eclipse console view:


    [ERROR   ] FWLSE0099E: An error occurred while invoking procedure  [project SeterusSnapShotJQ]SetSnapshotAuthAdapter/SqlStatementFWLSE0100E:  parameters: [project SeterusSnapShotJQ]{
   "arr": [
      {
         "parameters": [
            "1111111",
            "3333"
         ],
         "preparedStatement": "SELECT account_id, pin, borr_ssn FROM vw_wcc_cust WHERE vw_wcc_cust.account_id = ? AND pin = ?;"
      }
   ]
}

com.worklight.adapters.http.HttpClientContext cannot be cast to java.sql.Connection
FWLSE0101E: Caused by:  [project SeterusSnapShotJQ]nulljava.lang.ClassCastException: com.worklight.adapters.http.HttpClientContext cannot be cast to java.sql.Connection
    at com.worklight.adapters.sql.SQLQuery.invoke(SQLQuery.java:71)
    at com.worklight.integration.model.ProcedureInvoker.invokeProcedure(ProcedureInvoker.java:57)
    at com.worklight.integration.model.Procedure.invoke(Procedure.java:166)
    at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:169)
    at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:38)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at com.worklight.integration.model.InvocationContext$DirectExecutorService.execute(InvocationContext.java:284)
    at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
    at com.worklight.integration.model.InvocationContext.submit(InvocationContext.java:138)
    at com.worklight.integration.model.InvocationContextManager.submitInvocation(InvocationContextManager.java:58)
    at com.worklight.integration.services.impl.DataAccessServiceImpl.callProcedure(DataAccessServiceImpl.java:484)
    at com.worklight.integration.services.impl.DataAccessServiceImpl.access$100(DataAccessServiceImpl.java:56)
    at com.worklight.integration.services.impl.DataAccessServiceImpl$4.execute(DataAccessServiceImpl.java:387)
    at com.worklight.core.auth.impl.AuthenticationServiceBean.accessResource(AuthenticationServiceBean.java:76)
    at com.worklight.integration.services.impl.DataAccessServiceImpl.invokeProcedureInternal(DataAccessServiceImpl.java:384)
    at com.worklight.integration.services.impl.DataAccessServiceImpl.invokeDynamicProcedure(DataAccessServiceImpl.java:443)
    at com.worklight.integration.services.impl.DataAccessServiceImpl.invokeDynamicProcedure(DataAccessServiceImpl.java:427)
    at com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation.invokeDynamicProcedure(JavaScriptIntegrationLibraryImplementation.java:125)
    at sun.reflect.GeneratedMethodAccessor206.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:225)
    at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:52)
    at org.mozilla.javascript.gen._integration_js_16._c_anonymous_19(/integration.js:226)
    at org.mozilla.javascript.gen._integration_js_16.call(/integration.js)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
    at org.mozilla.javascript.gen.C_3A_5CUsers_5CIBM_ADMIN_5CDesktop_5CworkspaceJQuery_5CSeterusSnapShotJQ_5Cadapters_5CSetSnapshotAuthAdapter_SetSnapshotAuthAdapter_impl_js_78._c_submitAuthentication_2(C%3A%5CUsers%5CIBM_ADMIN%5CDesktop%5CworkspaceJQuery%5CSeterusSnapShotJQ%5Cadapters%5CSetSnapshotAuthAdapter/SetSnapshotAuthAdapter-impl.js:57)
    at org.mozilla.javascript.gen.C_3A_5CUsers_5CIBM_ADMIN_5CDesktop_5CworkspaceJQuery_5CSeterusSnapShotJQ_5Cadapters_5CSetSnapshotAuthAdapter_SetSnapshotAuthAdapter_impl_js_78.call(C%3A%5CUsers%5CIBM_ADMIN%5CDesktop%5CworkspaceJQuery%5CSeterusSnapShotJQ%5Cadapters%5CSetSnapshotAuthAdapter/SetSnapshotAuthAdapter-impl.js)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
    at org.mozilla.javascript.gen.C_3A_5CUsers_5CIBM_ADMIN_5CDesktop_5CworkspaceJQuery_5CSeterusSnapShotJQ_5Cadapters_5CSetSnapshotAuthAdapter_SetSnapshotAuthAdapter_impl_js_78.call(C%3A%5CUsers%5CIBM_ADMIN%5CDesktop%5CworkspaceJQuery%5CSeterusSnapShotJQ%5Cadapters%5CSetSnapshotAuthAdapter/SetSnapshotAuthAdapter-impl.js)
    at com.worklight.integration.js.JavaScriptManager.callFunction(JavaScriptManager.java:240)
    at com.worklight.integration.js.JavaScriptManager.invokeFunction(JavaScriptManager.java:214)
    at com.worklight.integration.js.JavaScriptManager.invokeFunction(JavaScriptManager.java:194)
    at com.worklight.integration.services.impl.AdapterManagerImpl.invokeFunction(AdapterManagerImpl.java:104)
    at com.worklight.integration.js.JavaScriptProcedureInvoker.invoke(JavaScriptProcedureInvoker.java:42)
    at com.worklight.integration.model.ProcedureInvoker.invokeProcedure(ProcedureInvoker.java:57)
    at com.worklight.integration.model.Procedure.invoke(Procedure.java:166)
    at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:169)
    at com.worklight.integration.model.InvocationContext.call(InvocationContext.java:38)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at com.worklight.server.util.ProjectLocal$1RunnableWrapper.run(ProjectLocal.java:267)
    at java.lang.Thread.run(Unknown Source)

                                                                                                               com.worklight.common.log.filters.ErrorFilter

I tried to follow the SQL Adapter example along with Single step auth adapter example. The code works fine with Single step auth adapter and hard coded data but it is giving me this problem as soon as I tried to include SQL adapter for hard coded data.

There are some postings which had same issue and I tried to follow there code in implementing this, but I am still not getting the desired the results.

Please let me know if you need anything more. Please forgive me if the code snippets don't come out good in the posting as I am new with Stack Overflow site.

Thanks, Shailesh

1
Did your connection to the database ever work at some point in the past? Can you verify this does not happen in a new SQL adapter that just does a very simply query to the database w/out anything related to authentication or your application? - Idan Adar
I successfully connected to database and executed the query in the test application. I used the sample exercise for "Advanced adapter usage and mashup" section of Worklight InfoCenter. I used the same style in my actual app and I was successful in retrieving the records from Microsft SQL Server. Thanks for your suggestion. - Shailesh - user3338612
Can you please write this as an answer? - Idan Adar

1 Answers

0
votes

I successfully connected to database and executed the query in the test application. I used the sample exercise for "Advanced adapter usage and mashup" section of Worklight InfoCenter. I used the same style in my actual app and I was successful in retrieving the records from Microsft SQL Server. Thanks for your suggestion. - Shailesh