【问题标题】:IBM Mobile First 7.1 HTTP Adapter Security testIBM Mobile First 7.1 HTTP 适配器安全测试
【发布时间】:2016-03-29 16:04:17
【问题描述】:

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

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

  }

身份验证.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>

【问题讨论】:

    标签: authentication ibm-mobilefirst


    【解决方案1】:

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

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

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

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

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

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

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

    我建议您更改isCustomResponse 的实现以检查response.responseJSON.authRequired 的值并仅在authRequiredtrue 时返回true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多