0

I've been working with two security tests for the adapters.

One of the security tests is to see if the users is an admin

Second security test is to see if the user is a project manager.

Both of these roles have different kind of access and need to be handled separate.

So i have defined two security tests in the in the authenticationConfiguration.xml

For both security tests i have made their realm handlers in the mobile application in javascript

All the code is found below.

The problem:

If a procedure is called that needs a security check Both the the secruity realms are invoked. But only the security test that was loaded first is the one that continues to validate and the other security test does not even recieves a challange.

Can some one tell my why both of these security tests are invoked and how i can make sure it only invokes the security tests for the right adapter. Both security tests are single step authentication

    <securityTests>
    <customSecurityTest name="Admin-securityTest">
        <test isInternalUserID="true" realm="AdminAuthRealm"/>
    </customSecurityTest>
    <customSecurityTest name="PM-securityTest">
        <test isInternalUserID="true" realm="PMAuthRealm"/>
    </customSecurityTest>
</securityTests>

<realms>


    <realm loginModule="AuthLoginModule" name="AdminAuthRealm">
        <className>com.worklight.integration.auth.AdapterAuthenticator</className>
        <parameter name="login-function" value="AdminAdapter.onAuthRequired"/>
        <parameter name="logout-function" value="AdminAdapter.onLogout"/>
    </realm>
     <realm loginModule="AuthLoginModule" name="PMAuthRealm">
        <className>com.worklight.integration.auth.AdapterAuthenticator</className>
        <parameter name="login-function" value="ProjectAdapter.onAuthRequired"/>
        <parameter name="logout-function" value="ProjectAdapter.onLogout"/>
    </realm>
</realms>

<loginModules>    

    <loginModule name="AuthLoginModule">
        <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
    </loginModule>
</loginModules> 

AdminAdapter

    <procedure name="submitAuthentication"/>
<procedure name="getUsers" securityTest="Admin-securityTest"/>

PMAdapter

    <procedure name="submitAuthentication"/>
<procedure name="updateProject" securityTest="PM-securityTest"/>

AdminRealmHandler

var AdminAuthRealmChallengeHandler = WL.Client.createChallengeHandler("AdminAuthRealm")
AdminAuthRealmChallengeHandler.isCustomResponse = function(response) {
console.log("ADMIN AUTH");
console.log(response);
if (!response || !response.responseJSON || response.responseText === null) {
    console.log("is costumresponse false 1 No json");
    return false;
}
if (typeof(response.responseJSON.authRequired) !== 'undefined'){
    console.log("is costumresponse true needs auth");
    return true;
} 
else {
    console.log("is costumresponse false 2 else");
    return false;
}

};

AdminAuthRealmChallengeHandler.handleChallenge = function(response){

var authRequired = response.responseJSON.authRequired;

 if (authRequired == true){
     if(response.responseJSON.errorMessage !== null){
            AdminAuthRealmChallengeHandler.submitFailure();
        }else{
        var invocationData = {
                adapter : "AdminAdapter",
                procedure : "submitAuthentication",
                parameters : [ userId, email, connectionsUid ]
            };
        AdminAuthRealmChallengeHandler.submitAdapterAuthentication(invocationData, {});
        }
}
else if (authRequired == false){
    AdminAuthRealmChallengeHandler.submitSuccess();
}

};

ProjectRealmHandler

var PMAdminAuthRealmChallengeHandler = WL.Client.createChallengeHandler("PMAuthRealm");
PMAdminAuthRealmChallengeHandler.isCustomResponse = function(response) {
console.log(response);
if (!response || !response.responseJSON || response.responseText === null) {
    return false;
}
if (typeof(response.responseJSON.authRequired) !== 'undefined'){
    return true;
} else {
    return false;
}

};

PMAdminAuthRealmChallengeHandler.handleChallenge = function(response){
var authRequired = response.responseJSON.authRequired;
console.log(response);

if(response.responseJSON.errorMessage !== null && typeof(response.responseJSON.errorMessage) !== 'undefined'){
    PMAdminAuthRealmChallengeHandler.submitFailure();
}
if (authRequired == true){
     if(response.responseJSON.errorMessage !== null){
            PMAdminAuthRealmChallengeHandler.submitFailure();
        }else{


            var invocationDataPM = {
                    adapter : "ProjectAdapter",
                    procedure : "submitAuthentication",
                    parameters : [ userId, email, connectionsUid ]
                };
            PMAdminAuthRealmChallengeHandler.submitAdapterAuthentication(invocationDataPM, {});
        }

}
else if (authRequired == false){
    PMAdminAuthRealmChallengeHandler.submitSuccess();
}

};

1 Answer 1

0

I think you cannot use two different security tests for one authentication. But what you can do is to use two realms protected by the same custom security test and choose the order of checking. Read page 23 in this document

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.