2016-03-29 7 views
0

Kullanıcı adı ve parola doğrulamak için node.js web hizmetini kullanan bir http bağdaştırıcısı üzerinde çalışıyorum.IBM Mobile First 7.1 HTTP Bağdaştırıcısı Güvenlik testi

Prosedürler authentineHizmet ve authenticateDoctor korunmasız olduğundan güvenlik prosedürünü diğer prosedürlerde kullanacağım.

Ancak, bunlardan birini çağırmaya çalıştığımda, bu güvenlik açığından etkilenmemekle birlikte, sorun gidericiye de çağrılır ve eğer sorun gidericisini silersem, iyi çalışır!

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"/> 

Doğrulama-impl.js (sadece authenticatePatient fonksiyonu)

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 (alanları)

<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)

<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 (Güvenlik testleri)

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

cevap

1

fonksiyon isCustomResponse herhangi http tepki ile çağrıda edilebileceğini hatırlamak önemlidir, sadece korunan istekleri değil. Bu özelliğin bu sorun giderici için geçerli olup olmadığını belirlemek, bu işlevin (isCustomResponse) görevidir.

Örneğinizde anladığım kadarıyla korumasız olan authenticatePatient için istekte bulunabilirsiniz.
Ardından authenticatePatient döner:

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

Bu JSON nesnesi istemciye gönderilir.

isCustomResponse işleviniz tetiklenir (korumalı bir istek olup olmadığını kontrol etmez, her yanıt için tetiklenir).

isCustomResponse Sizin uygulaması bu yanıtı (return false;) görmezden veya zorluk işleyici (return true;) tetiklemek için olup olmadığını belirlemek için yeterince akıllı olmalıdır.

Uygulamanız için, yalnızca response.responseJSON.authRequired'un tanımlandığını kontrol ettiğiniz görülüyor. Değerinin true veya false olup olmadığını kontrol etmediniz. Yani, kodunuz bu cevabın, meydan okuma işleyicisi tarafından ele alınması gerektiğini belirledi.

Ben senin değişikliği isCustomResponse sizin uygulanması response.responseJSON.authRequired değeri denetlemek ve authRequiredtrue olduğu zaman true dönmek öneriyoruz.

İlgili konular