Worklight单步验证和SQL适配器

时间:2014-05-20 17:10:58

标签: sql sql-server authentication ibm-mobilefirst worklight-adapters

我正在开发基于jQuery的移动应用程序并尝试使用我的自定义登录页面进行单步验证。登录页面从用户收集贷款#和pin并使用它们查询MS SQL Server数据库,如下所示。

我创建了SQL适配器来访问MS SQL Server数据库,当我选择适配器时,它可以从工作区成功运行 - >运行方式 - >调用适配器过程。但它不能从我的challaengerHandler.js起作用并抛出异常。我已经将sqljdbc4.jar文件存储到项目的server / lib文件夹中。

以下是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"/>

以下是来自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]
});
}

以下是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);
});

以下是SIngle Step Authentication Adapeter的js文件的submitAuthentication()函数的内容


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”&amp;&amp; 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");
}

输入贷款#和pin然后点击提交按钮后,我在eclipse控制台视图中收到以下异常:


    [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

我尝试按照SQL Adapter示例以及单步身份验证适配器示例进行操作。该代码适用于单步授权适配器和硬编码数据,但只要我尝试将SQL适配器包含在硬编码数据中,它就会给我这个问题。

有一些帖子有同样的问题,我试图按照那里的代码实现这一点,但我仍然没有得到理想的结果。

如果您还需要更多信息,请与我们联系。如果代码片段在发布时效果不好,请原谅我,因为我是Stack Overflow网站的新手。

谢谢, SHAILESH

1 个答案:

答案 0 :(得分:0)

我成功连接到数据库并在测试应用程序中执行查询。我使用了Worklight InfoCenter的“高级适配器使用和mashup”部分的示例练习。我在我的实际应用程序中使用了相同的样式,并且我成功地从Microsft SQL Server检索记录。谢谢你的建议。 - Shailesh