IBM Mobile First 7.1 HTTP 适配器安全测试

IBM Mobile First 7.1 HTTP Adapter Security test

我正在开发一个使用 node.js 网络服务来验证用户名和密码的 http 适配器。

程序authenticatePatient和authenticateDoctor不受保护,所以我将在其他程序中使用安全测试。

但是,当我尝试调用其中之一时,质询处理程序也被调用,尽管它们不受保护,如果我删除质询处理程序它工作正常!

PatientAuthRealmChallengeHandler.js

var patientAuthRealmChallengeHandler = WL.Client.createChallengeHandler("PatientAuthRealm");
patientAuthRealmChallengeHandler.isCustomResponse= function(response){

if(!response|| !response.responseJSON || response.responseText===null){
    return false;
}
if(typeof (response.responseJSON.authRequired)!== 'undefined'){
    return true;
}
else {
    return false;
   }
 }

patientAuthRealmChallengeHandler.handleChallenge = function(response){
 var authRequired = response.responseJSON.authRequired;

    if(authRequired==true){

        console.log("accées réfusé!!");
    }
 else if(authRequired==false){
        console.log(" déja authentifié ");
        patientAuthRealmChallengeHandler.submitSuccess();
    }

  }

Authentication.xml

  <procedure name="authenticatePatient" securityTest="wl_unprotected"/>
  <procedure name="authenticateDoctor"  securityTest="wl_unprotected"/>

Authentication-impl.js(只是 authenticatePatient 函数)

  function authenticatePatient(params){
  var url="/patient/authenticate";
  var response= callWS(url,params,"post");
  var size= response.patients.length;

 if(size!=0){
   userIdentity = {
            userId: params.username,
            displayName: params.username,
            attributes: {
            }
    };
    //WL.Server.setActiveUser("PatientAuthRealm", null);
    WL.Server.setActiveUser("PatientAuthRealm", userIdentity); // create session 

    return {
        authRequired: false,
        "response": response
    };
}
return onAuthRequired(null, "Invalid login credentials");
}
function onAuthRequired(headers, errorMessage){
errorMessage = errorMessage ? errorMessage : null;

return {
    authRequired: true,
    errorMessage: errorMessage
  };
   }
 function onLogout(){
  WL.Logger.debug("Logged out");
 }

authentificationConfig.xml(领域)

    <realm name="PatientAuthRealm" loginModule="PatientAuthLoginModule">
        <className>com.worklight.integration.auth.AdapterAuthenticator </className>
        <parameter name="login-function" value="authentication.onAuthRequired"/>
        <parameter name="logout-function" value="authentication.onLogout"/>
    </realm>

    <realm name="DoctorAuthRealm" loginModule="DoctorAuthLoginModule">
        <className>com.worklight.integration.auth.AdapterAuthenticator </className>
        <parameter name="login-function" value="authentication.onAuthRequired"/>
        <parameter name="logout-function" value="authentication.onLogout"/>
    </realm>

authentificationConfig.xml(登录模块)

<loginModule name="PatientAuthLoginModule">
            <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
    </loginModule>
    <loginModule name="DoctorAuthLoginModule">
        <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
    </loginModule>

authentificationConfig.xml(安全测试)

  <customSecurityTest name="authenticatePatient">
        <test isInternalUserID="true" realm="PatientAuthRealm"/>
    </customSecurityTest>
    <customSecurityTest name="authenticateDoctor">
        <test isInternalUserID="true" realm="DoctorAuthRealm"/>
    </customSecurityTest>

重要的是要记住函数 isCustomResponse 可以被任何 http 响应调用,而不仅仅是受保护的请求。此函数 (isCustomResponse) 的工作是确定此特定响应是否与此质询处理程序相关。

根据我在您的示例中的理解,您向 authenticatePatient 发出了不受保护的请求。
然后,authenticatePatient returns:

return {
        authRequired: false,
        "response": response
    };

这个JSON对象被发送到客户端。

您的 isCustomResponse 函数被触发(它不检查这是否是一个受保护的请求,它会在每次响应时被触发)。

您的 isCustomResponse 实现应该足够智能,可以确定是忽略此响应 (return false;),还是触发质询处理程序 (return true;)。

对于您的实施,您似乎只检查 response.responseJSON.authRequired 是否已定义。您没有检查它的值是 true 还是 false。这意味着,您的代码确定此响应需要由质询处理程序处理。

我建议您更改 isCustomResponse 的实现,以便仅在 authRequired 为 [=20 时检查 response.responseJSON.authRequired 和 return true 的值=].