在 IBM Worklight 中使用适配器调用服务调用安全适配器

Posted

技术标签:

【中文标题】在 IBM Worklight 中使用适配器调用服务调用安全适配器【英文标题】:Invoking a secure adapter using Adapter Invocation Service in IBM Worklight 【发布时间】:2014-10-12 12:42:26 【问题描述】:

我们有一个 HTTP 适配器,其中包含如下声明的几个安全过程:

<wl:adapter name="PushAdapter" ...
  .
  .
<procedure name="submitNotification" securityTest="AdapterSecurityTest"/>
<procedure name="submitNotificationMass" securityTest="AdapterSecurityTest"/>

使用基于适配器的身份验证执行安全测试,如下所示:

 <securityTests>
    <mobileSecurityTest name="AdapterSecurityTest">
        <testUser realm="MyRealm"/>
        <testDeviceId provisioningType="none"/>
    </mobileSecurityTest>
</securityTests> 

<realms>
    <realm name="MyRealm" loginModule="NonValidatingLoginModule">
        <className>com.worklight.integration.auth.AdapterAuthenticator</className>
        <parameter name="login-function">AuthenticationAdapter.onAuthRequired</parameter>
        <parameter name="logout-function">AuthenticationAdapter.onLogout</parameter>
    </realm>
</realms>

我们需要能够使用适配器调用服务在 HTTP 中调用适配器过程。使用调用服务,调用 URL 如下:

http://<server>:<port>/<Context>/invoke?adapter=PushAdapter&procedure=submitNotification&parameters=[userId, notification text to be sent]

当过程安全测试设置为“wl_unprotected”时,调用按预期工作。但如果使用安全测试,调用会返回以下响应:

/*-secure-"WL-Authentication-Failure":"wl_remoteDisableRealm":"reason":"Login Failed"*/

问题是,我们如何使用调用服务进行身份验证?我们尝试设置授权 HTTP 标头,现在很幸运。

谢谢

【问题讨论】:

启用移动安全测试时,为什么要通过调用 URL 对适配器进行身份验证? 我们有一个用例,我们希望后端系统通过使用适配器调用服务调用适配器过程来向应用程序用户发送推送通知,我们不希望发送通知的 URL不安全且对任何人公开。 【参考方案1】:

我已按照程序在 Worklight 6.2 示例中的基于适配器的身份验证的帮助下实施。

第 1 步: 根据您的环境实际情况在标题中添加以下值

 x-wl-app-details:"applicationDetails":"platformVersion":"6.2.0.00.20140613-0730","nativeVersion":""

 x-wl-app-version:1.0

请求:http://x.x.x.x:10080/AdapterBasedAuth/apps/services/api/SingleStepAuth/common/init

回复:

/*-secure- "challenges":"wl_antiXSRFRealm":"WL-Instance-Id":"gi1cqaqd3p89763l1amoklsq3u"*/

第 2 步:

在标头中添加 WL-Instance-Id: gi1cqaqd3p89763l1amoklsq3u,这是先前响应的一部分

请求: http://xx.xx.xx.xx:10080/AdapterBasedAuth/apps/services/api/SingleStepAuth/common/query?adapter=SingleStepAuthAdapter&amp;procedure=submitAuthentication&amp;parameters=['worklight','worklight']

回复:

/*-secure-
"isSuccessful":true,"WL-Authentication-Success":"SingleStepAuthRealm":"userId":"worklight","isUserAuthenticated":1,"attributes":"foo":"bar","displayName":"worklight","wl_antiXSRFRealm":"userId":"j136h3aus2v1vlbjr860mmossc","attributes":,"isUserAuthenticated":1,"displayName":"j136h3aus2v1vlbjr860mmossc","wl_anonymousUserRealm":"userId":"747809a4-3574-4958-a55a-f084b2c9f02c","attributes":,"isUserAuthenticated":1,"displayName":"747809a4-3574-4958-a55a-f084b2c9f02c","authRequired":false*/

第 3 步:

添加 Authorization 标头和先前响应的值

"SingleStepAuthRealm":"userId":"worklight","isUserAuthenticated":1,"attributes":"foo":"bar","displayName":"worklight"

请求:http://xx.xx.xx.xx:10080/AdapterBasedAuth/apps/services/api/SingleStepAuth/common/query?adapter=SingleStepAuthAdapter&amp;procedure=getSecretData

回复:

 /*-secure-
"isSuccessful":true,"secretData":"A very very very very secret data"*/

要了解有关此过程的更多信息,请关注IBM Community Blog。

我相信这就是你要找的。​​p>

【讨论】:

谢谢 :) 我会对此进行测试,然后告诉你进展如何。

以上是关于在 IBM Worklight 中使用适配器调用服务调用安全适配器的主要内容,如果未能解决你的问题,请参考以下文章

IBM Worklight:调用 Worklight 适配器时没有 SessionManager

如何使用自定义 IN 参数在 IBM Worklight SQL 适配器中调用存储过程

IBM worklight - 从另一个 html 文件调用 worklight 适配器

IBM worklight - “找不到适配器,过程调用错误”

IBM Worklight - 如何使用“OUT”参数调用存储过程?

IBM Worklight 6.1 - 升级到 v6.1 后,iOS 5 中的适配器调用失败