![](/img/trans.png)
[英]device user mapping in mobile first platform 7.1 console while log in through adapterbased auhentication
[英]IBM Mobile First 7.1 HTTP Adapter Security test
我正在使用http适配器使用node.js Web服务来验证用户名和密码。
程序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)
<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
返回:
return {
authRequired: false,
"response": response
};
此JSON对象发送到客户端。
您的isCustomResponse
函数将被触发(它不会检查这是否是受保护的请求,它会为每个响应触发)。
您对isCustomResponse
实现应该足够聪明,以确定是忽略此响应( return false;
)还是触发质询处理程序( return true;
)。
对于您的实现,看起来您仅检查是否已定义response.responseJSON.authRequired
。 您没有检查其值是true
还是false
。 这意味着,您的代码确定此响应需要由质询处理程序处理。
我建议你改变你的执行isCustomResponse
检查的价值response.responseJSON.authRequired
并返回true
只有当authRequired
是true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.