【发布时间】: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