在适配器(getMyRecords
)中调用受保护的过程并且服务器会话已过期时,应用程序重新登录以获取新会话,但它不会再次调用getMyRecords
。 / p>
以下是示例代码:
适配器XML文件
<procedure name="getMyRecords" securityTest="appSecurityTest" />
challengeHandler JS文件
challengeHandler.isCustomResponse = function(response) {
if (!response || !response.responseJSON || response.responseText === null) {
return false;
}
if (typeof (response.responseJSON.authRequired) !== 'undefined') {
//Should enter automatically to handleChallenge but not always
return true;
} else {
return false;
}
};
之后,这将执行以下代码(处理挑战):
challengeHandler.handleChallenge = function(response) {
var hasGlobalHeader = (WL.Client.__getGlobalHeaders()['ENC-USER'] != undefined);
if(hasGlobalHeader ){ //Re-login response
//this will invoke the relogin procedure to get a new session and to authenticate the user
challengeHandler.handleRelogin(response);
}else{
...
}
};
challengeHandler.handleRelogin = function(response){
var authRequired = response.responseJSON.authRequired;
if (authRequired == true) {
var input = {
adapter: "AuthenticationAdapter",
procedure: "autoLogin",
parameters: [localStorage.getItem('encryptedUser'), lang]
};
WL.Client.invokeProcedure(input, {
onSuccess: function(response){
$logger.log('service :: autoLoginSuccess :: response : ', response);
def.resolve(response);
},
onFailure: function(err){
$logger.log('service :: autoLoginFailure :: err : ', err);
def.reject(err);
}
});
}else{
//InitContext
initContext(response);
goHome();
//challengeHandler.activeRequest = null ;
}
};
问题是当调用submitSuccess时,它不会发出原始请求,而是无限地调用autoLogin过程。
答案 0 :(得分:0)
确保每次调用handleChallenge
时,都会调用submitSuccess
或submitFailure
。
在您拨打其中一个之前,该框架并不知道您已完成应答挑战。永远不要让挑战无人接听。
我认为不是:
if (typeof (response.responseJSON.authRequired) !== 'undefined') {
你应该试试
if (typeof (response.responseJSON.authRequired) !== 'undefined' && response.responseJSON.authRequired == true) {