mfp 中 scope 元素中的安​​全检查是什么关系?

问题描述

美好的一天,

在我的适配器中,我配置了一个 securityCheckDeFinition 如下:

<securityCheckDeFinition name="UserAuthentication" class="com.mobile.authentication.UserAuthentication">
        <property name="maxAttempts" defaultValue="3" description="How many attempts are allowed"/>
    </securityCheckDeFinition>

在我的 mfp 控制台应用程序中,在“安全”选项卡下,我配置了一个范围调用 push.mobileclient

enter image description here

在我的前端代码中,我调用 mfp 登录方法如下以使用 mfp“验证”我的客户端:

WLAuthorizationManager.login('UserAuthentication',authObj)

我看到我的 .handleSuccess() 被触发,意味着“身份验证”部分成功。 (如果我错了,请纠正我。)

在.handleSuccess()之后,我调用mfp获取访问令牌()方法来检查我的客户端是否已经通过mfp“认证”成功,代码如下:

WLAuthorizationManager.obtainAccesstoken('push.mobileclient').then(
            function (accesstoken) {
                WL.Logger.debug("obtainAccesstoken onSuccess");
                console.log("obtainAccesstoken onSuccess");
                console.log(accesstoken)
            },function (response) {
                WL.Logger.debug("obtainAccesstoken onFailure: " + JSON.stringify(response));
                console.log("obtainAccesstoken onFailure: " + JSON.stringify(response));
        });

答案是肯定的,我得到了“obtainAccesstoken onSuccess”。

我的问题是我调用 WLAuthorizationManager.login('UserAuthentication',authObj) 来“注册/验证”到 mfp,但是当我想检查它是否成功时,我使用的是 WLAuthorizationManager.obtainAccesstoken('push.mobileclient'),1 是 UserAuthentication,另一个 1 是 push.mobileclient,2 种不同的东西,WLAuthorizationManager.obtainAccesstoken('push.mobileclient') 怎么知道我的客户已经“注册/认证”成功了?

解决方法

当您触发 WLAuthorizationManager.login(SecurityCheckName,authObj) 时,您正在使用 MobileFirst Server 对用户进行身份验证。您正在创建一个 AuthenticatedUser 对象并设置一个 AuthenticationContext。此过程创建保留在服务器中的身份验证状态并将响应发送到客户端。在客户端,响应进入 ChallengeHandler 类中的 handleSuccess() 方法,这完成了身份验证流程。

稍后,当您调用 WLAuthorizationManager.obtainAccessToken(scopename) 时,您是在请求 MobileFirst Authorization Server 为范围 <scopename> 颁发 OAuth 令牌。就您而言,"push.mobileclient"

如果范围是在 MobileFirst 管理控制台中定义的,但未映射到安全检查(在您的情况下为 UserAuthentication),MobileFirst Server 会为范围 <scopeName> 发出 OAuth 令牌。

MobileFirst 服务器如何知道客户端已注册或已通过身份验证?

MobileFirst 服务器保留客户端的注册和认证状态。即使没有登录自定义安全检查,MobileFirst 服务器也会应用默认的安全级别并维护身份验证状态。当客户端登录到定制安全检查时,MobileFirst 服务器使用此信息更新认证状态。这样,身份验证状态将与所有信息一起维护,直到它过期或客户端注销。

但是,在 MobileFirst 控制台中,如果范围被映射到安全检查(例如 UserAuthentication),那么首先 MobileFirst 服务器会检查您是否已经登录 UserAuthentication(您首先登录)并且身份验证上下文仍然有效(未过期)。如果是,MobileFirst Server 将继续发出带有 <scopeName> 的 OAuth 令牌。 如果没有,MobileFirst Server 首先要求您进行身份验证。此挑战将到达 ChallengeHandler 类的 handleChallenge() 方法。一旦质询-响应成功完成并且流进入 handleSuccess(),MobileFirst Server 将发出范围为 <scopeName> 的 OAuth 令牌。