Ibm mobilefirst 登录期间后端(链中第二个)适配器的Worklight安全设置

Ibm mobilefirst 登录期间后端(链中第二个)适配器的Worklight安全设置,ibm-mobilefirst,worklight-adapters,worklight-server,worklight-security,Ibm Mobilefirst,Worklight Adapters,Worklight Server,Worklight Security,我有一个Worklight应用程序,可以为每个客户端稍微定制。我还或多或少地为每个客户机重写了适配器代码。现在我决定将适配器分为两部分:一部分包含每个客户机使用的一般功能(登录、消息传递等),另一部分包含每个客户可能不同的实现细节 设置如下所示: 应用程序调用主适配器(ProjectAdapter)登录过程 登录过程执行正常登录,调用WL.Server.setActiveUser 登录过程调用(WL.Server.invokeProcedure)自定义适配器,用自定义数据补充登录响应 登录过程将

我有一个Worklight应用程序,可以为每个客户端稍微定制。我还或多或少地为每个客户机重写了适配器代码。现在我决定将适配器分为两部分:一部分包含每个客户机使用的一般功能(登录、消息传递等),另一部分包含每个客户可能不同的实现细节

设置如下所示:

  • 应用程序调用主适配器(ProjectAdapter)登录过程
  • 登录过程执行正常登录,调用
    WL.Server.setActiveUser
  • 登录过程调用(
    WL.Server.invokeProcedure
    )自定义适配器,用自定义数据补充登录响应
  • 登录过程将完整的结果对象返回给应用程序
  • 但是,我在尝试为自定义(链中第二个)适配器设置安全性时遇到了麻烦。如果我将其设置为我在应用程序中使用的正常安全测试,它将失败:

    [ERROR   ] FWLSE0059E: Login into realm 'WLRemoteDisableNullLoginModule' failed. null. [project Project]
    [ERROR   ] FWLSE0117E: Error code: 4, error description: AUTHENTICATION_ERROR, error message: An error occurred while performing authentication using loginModule WLRemoteDisableNullLoginModule, User Identity {wl_directUpdateRealm=null, wl_authenticityRealm=null, Project=(name:1, loginModule:ProjectLoginModule), wl_remoteDisableRealm=null, SampleAppRealm=null, wl_antiXSRFRealm=null, wl_deviceAutoProvisioningRealm=null, WorklightConsole=null, wl_deviceNoProvisioningRealm=null, myserver=(name:1, loginModule:ProjectLoginModule), wl_anonymousUserRealm=null}. [project Project] [project Project]
    
    似乎用
    WL.Server.setActiveUser
    设置用户标识没有帮助。如果我紧接着执行了
    WL.Server.getUserIdentity
    ,我也会遇到这种情况,它将返回未定义;不确定这是否应该如此

    我必须将第二个链内适配器安全测试设置为
    wl\u unprotected
    ,以便它工作

    我该怎么做

    Worklight版本6.2.0.00-20140922-2259

    更新

    我现在看到这只与登录过程有关。设置用户标识后,第二个适配器将通过正常的适配器安全测试进行调用,不会出现问题


    因此,问题应该是:如何在登录过程中设置用户标识,以便成功调用第二个适配器?正如我所说,在
    WL.Server.setActiveUser
    之后,对
    WL.Server.getUserIdentity
    的调用返回未定义。

    您应该调用WL.Server.getActiveUser(“yourRealm”)。就适配器的调用而言,我从IBMdeveloperWorks页面下载了该项目,并做了以下更改

    SingleStepAuthAdapter的submitAuthentication方法现在如下所示:

    function submitAuthentication(username, password){
        if (username==="worklight" && password === "worklight"){
    
            var userIdentity = {
                    userId: username,
                    displayName: username, 
                    attributes: {
                        foo: "bar"
                    }
            };
    
            WL.Server.setActiveUser("SingleStepAuthRealm", userIdentity);
    
            var invocationData = {
                    adapter : "CustomAdapter",
                    procedure: "getTheCoolStuff",
                    parameters: [username]
            };
    
            var response = WL.Server.invokeProcedure(invocationData);
    
    
            var iden = WL.Server.getActiveUser("SingleStepAuthRealm");
    
            return { 
                authRequired: false,
                myResponse: response,
                myIden: iden
            };
    
    
        }
    
        return onAuthRequired(null, "Invalid login credentials");
    }
    
    我还使用创建了一个新适配器“CustomAdapter”,并添加了以下行

    <procedure name="getTheCoolStuff" securityTest="SingleStepAuthAdapter-securityTest"/>
    
    
    
    我希望这有帮助