简体   繁体   English

IBM MobileFirst 7.1-从其URL调用适配器失败,并带有全局变量和setActiveUser()

[英]IBM MobileFirst 7.1 - Calling adapters from their URL failing with global variables and setActiveUser()

I have a very simple hybrid sample app which has 3 adapters. 我有一个非常简单的混合示例应用程序,其中有3个适配器。

  1. submitAuthStep1(username, password) SubmitAuthStep1(用户名,密码)
  2. submitAuthStep2(answer) SubmitAuthStep2(答案)
  3. getSecretData() getSecretData()

Adapter 1 and 2 are using the "wl_unprotected" security test. 适配器1和2正在使用“ wl_unprotected”安全测试。 Adapter 3 is using "AuthRealm" 适配器3正在使用“ AuthRealm”

var userIdentity;

function onAuthRequired(headers, errorMessage){
    WL.Logger.warn(" in OAuth Reuired...");
    WL.Logger.debug(" in OAuth Reuired...");

    errorMessage = errorMessage ? errorMessage : null;
    WL.Logger.debug(" in OAuth Reuired errorMessage..."+errorMessage);
    return {
        authRequired: true,
        authStep: 1,
        errorMessage: errorMessage
    };
}

function submitAuthStep1(username, password){
    if (username === "wl" && password === "wl"){
        WL.Logger.debug("Step 1 :: SUCCESS");
        userIdentity = {
                userId: username,
                displayName: username, 
                attributes: {}
        };

        return {
            authRequired: true,
            authStep: 2,
            question: "What is your pet's name?",
            errorMessage : ""
        };

    }

    else{
        WL.Logger.debug("Step 1 :: FAILURE");
        return onAuthRequired(null, "Invalid login credentials");
    }
}

function submitAuthStep2(answer){
    if (answer === "wl2"){
        WL.Logger.debug("Step 2 :: SUCCESS");
        WL.Server.setActiveUser("AuthRealm", userIdentity);
        WL.Logger.debug("Authorized access granted");

        return {
            authRequired: false
        };
    }

    else{
        WL.Logger.debug("Step 2 :: FAILURE");
        return onAuthRequired(null, "Wrong security question answer");
    }

}

function getSecretData(){
    /*return {
        secretData: "A very very very very secret data"
    };*/
    WL.Logger.info(" Active User INfo "+JSON.stringify(WL.Server.getActiveUser("AuthRealm")));
    WL.Logger.info(" .... User INfo "+ WL.Server.getClientRequest().getSession().getAttribute("AuthRealm"));

    return userIdentity;
}

function onLogout(){
    userIdentity = null;
    WL.Server.setActiveUser("AuthRealm", userIdentity);
    WL.Logger.debug("Logged out");
}

function signOut(){
    userIdentity = null;
    WL.Server.setActiveUser("AuthRealm", userIdentity);
    WL.Logger.debug("Logged out");
}

When invoking this code with the hybrid application it works fine, when I try to test and invoke these adapters using eclipse (Call MobileFirst Adapter option) submitAuthStep1 works, then when I get to submitAuthStep2 my global variable 'userIdentity' is gone. 当使用混合应用程序调用此代码时,它工作正常,当我尝试使用Eclipse(调用MobileFirst Adapter选项)测试并调用这些适配器时,submitAuthStep1起作用,然后当我提交SubmitAuthStep2时,我的全局变量“ userIdentity”就消失了。 I have also tried to invoke the adapters in sequence using their corresponding URL's in a chrome browser tab with the same result! 我还尝试在chrome浏览器标签中使用它们对应的URL依次调用适配器,结果相同!

worklight.properties is using session dependence worklight.properties使用会话依赖

mfp.session.independent=false
mfp.attrStore.type=httpsession

Why is this happening? 为什么会这样呢?

The "Call Adapter" feature of the MobileFirst Studio cannot be used to test authentication and security. MobileFirst Studio的“呼叫适配器”功能不能用于测试身份验证和安全性。 The way it works, it gets direct access to the resource and skips all of the MobileFirst security framework. 它的工作方式可以直接访问资源,并跳过所有MobileFirst安全框架。 It is meant to test regular adapters. 它旨在测试常规适配器。

Same thing if you try to get to the adapter directly from the browser. 如果您尝试直接从浏览器访问适配器,也是如此。

You have no MobileFirst session, therefore you start fresh for every request. 您没有MobileFirst会话,因此您将为每个请求重新开始。 Global variables won't be carried on to the next request. 全局变量不会继续到下一个请求。

You can only test authentication and security features using an application. 您只能使用应用程序测试身份验证和安全功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM