0

我有一個非常簡單的混合示例應用程序有3個適配器。IBM MobileFirst 7.1 - 調用適配器從他們的URL失敗與全局變量和setActiveUser()

  1. submitAuthStep1(用戶名,密碼)
  2. submitAuthStep2(回答)
  3. getSecretData()

適配器1和2所使用的 「wl_unprotected」 安全測試。 適配器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"); 
} 

當調用此代碼,它工作正常的混合應用程序,當我嘗試測試和使用eclipse調用這些適配器(呼叫MobileFirst適配器選件)submitAuthStep1作品,那麼得到submitAuthStep2我的全局變量'userIdentity'消失了。我也嘗試使用Chrome瀏覽器選項卡中的相應URL按順序調用適配器,並獲得相同的結果!

worklight.properties使用會話依賴

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

這究竟是爲什麼?

+0

它在Studio外工作嗎? –

+0

@IdanAdar我無法訪問MobileFirst Studio只是eclipse和瀏覽器。這段代碼唯一可以按預期工作的時間是在Web瀏覽器中將其用作應用程序預覽的時間。有其他的方法可以測試嗎? –

+0

你在說什麼......如果你不使用Studio插件,在Eclipse中如何在eclipse中預覽它?我在說,你需要測試它是否在設備上失敗 - 對於你的應用程序是一個真實的測試。 –

回答

2

MobileFirst Studio的「呼叫適配器」功能不能用於測試身份驗證和安全性。它的工作方式是直接訪問資源並跳過所有MobileFirst安全框架。它旨在測試常規適配器。

如果您嘗試直接從瀏覽器訪問適配器,則會出現同樣的情況。

您沒有MobileFirst會話,因此您可以爲每個請求重新開始。全局變量將不會傳遞到下一個請求。

您只能使用應用程序測試身份驗證和安全功能。

相關問題