This is my js code. In this two functions are working, one is ChallengeHandler.isCustomResponse and another one is ChallengeHandler.handleChallenge
Here i am creating challengeHandler for "sampleAppRealm" for security reasons using FormBasedAuthenticator
Here i used HTTP adapter procedure named as "getValidate()". This procedure is working without securityTest but with securityTest, it is not working...
i dont know where going wrong.. i am in lot of confusion
i am using worklight version 7.0 and jquery version 1.11 and jquery mobile 1.4.5
My js code:
<script>
$(document).ready(function(){
alert("Hi");
});
function getValidate(){
alert();
var invocationData = {
adapter : 'Go2needsHTTP',
procedure : 'getValidate',
parameters : []
};
var options = {
onSuccess : getValidateSuccess,
onFailure : getValidateFailure,
invocationContext: {}
};
WL.Client.invokeProcedure(invocationData, options);
}
function getValidateSuccess(){
alert("Success");
}
function getValidateFailure(){
alert("Failure");
}
var SampleAppRealmChallengeHandler = WL.Client.createChallengeHandler("SampleAppRealm");
sampleAppRealmChallengeHandler.isCustomResponse = function(response) {
alert(response);
if (!response || response.responseText === null) {
return false;
}
var indicatorIdx = response.responseText.search('j_security_check');
if (indicatorIdx >= 0){
return true;
}
return false;
};
sampleAppRealmChallengeHandler.handleChallenge = function(response) {
alert("handleChallenge");
$('#AppDiv').hide();
$('#AuthDiv').show();
$('#AuthPassword').val('');
};
$(function(){
$('#AuthSubmitButton').bind('click', function () {
alert("AuthSubmitButton");
var reqURL = '/j_security_check';
var options = {};
options.parameters = {
j_username : $('#AuthUsername').val(),
j_password : $('#AuthPassword').val()
};
options.headers = {}; sampleAppRealmChallengeHandler.submitLoginForm(reqURL, options, sampleAppRealmChallengeHandler.submitLoginFormCallback);
});
});
$(function(){
$('#AuthCancelButton').bind('click', function () {
alert("AuthCancelButton");
sampleAppRealmChallengeHandler.submitFailure();
$('#AppDiv').show();
$('#AuthDiv').hide();
});
});
</script>
This is my html code:
My html code:
<div data-role="page" id="page">
<div data-role="content" style="padding: 15px">
<div id="AppDiv">
<input type="button" id="getSecretDataButton" value="Call protected adapter proc" onclick="getValidate()" />
<input type="button" class="appButton" value="Logout" onclick="WL.Client.logout('SampleAppRealm',{onSuccess: WL.Client.reloadApp})" />
<div id="ResponseDiv"></div>
</div>
<div id="AuthDiv" style="display: block;">
<p id="AuthInfo"></p>
<div id="loginForm">
<input type="text"`enter code here` id="AuthUsername" placeholder="Enter username" />
<br/>
<br/>
<input type="password" id="AuthPassword" placeholder="Enter password" />
<br/>
<input type="button" id="AuthSubmitButton" onclick="WL.Client.Login('SampleAppRealm');" class="formButton" value="Login" />
<input type="button" id="AuthCancelButton" class="formButton" value="Cancel" />
</div>
</div>
</div>
</div>
This is my authenticationConfig.xml file:
<customSecurityTest name="SampleAppRealm-securityTest"> <test realm="SampleAppRealm" isInternalUserID="true"/></customSecurityTest> <loginModule name="StrongDummy" expirationInSeconds="-1"> <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className> </loginModule> <realm name="SampleAppRealm" loginModule="StrongDummy"> <className>com.worklight.core.auth.ext.FormBasedAuthenticator</className> </realm>
This is my HTTPadapter prodedure:
<procedure name="getValidate" securityTest="SampleAppRealm-securityTest"></procedure>
Just test and tell where i am doing wrong unable to find out the error. Please help me....
So you are saying that isCustomResponse
does not get triggered at all? Your alert
does not appear?
In this case, I think the error is very simple:
You declared: var SampleAppRealmChallengeHandler = ...
And then you set sampleAppRealmChallengeHandler.isCustomResponse = ...
Notice the first one is a capital S
while the second one is a lower-case s
.
Javascript is case-sensitive. If you declare a variable one way, you need to keep using the exact same casing everywhere.