自适应身份验证 (SMS 2FA) 和服务提供商强制声明

问题描述

我已按照 here 所述为 WSO2 身份服务器配置了 SMS OTP,并且我为给定的服务提供商(基本和 SMS OTP)设置了 2 个身份验证步骤。

2FA 流当前由用户管理,并通过更新 http://wso2.org/claims/identity/smsotp_disabled 声明值来启用/禁用。

现在我们想利用自适应身份验证并强制用户通过 2FA 流程,以防他们多次尝试登录失败。我们通过稍微修改基于登录尝试的模板生成了以下脚本:

// Custom mapped claim
var FailedLoginAttemptsClaim= 'http://wso2.org/claims/identity/loginAttempts';
var verifiedMobileClaim = 'http://wso2.org/claims/verifiedMobile';
var smsOtpdisabledClaim = 'http://wso2.org/claims/identity/smsotp_disabled';
var FailedLoginsUntilSMSOTP = 3;

var onLoginRequest = function(context) {
    doLogin(context);
};

var doLogin = function(context) {
    executeStep(1,{
        onSuccess : function(context) {
            var username = context.steps[1].subject.username;
            var otpdisabled = getSMSOtpdisabledClaimValue(context.steps[1].subject);
            // SMS OTP is enabled by user,send him for 2FA in every case.
            if (!otpdisabled || otpdisabled === 'false') {
                executeStep(2);
            } else {
                // Do perform mandatory SMS OTP in case the user has exceeded certain amount of retries 
                if (getFailedLoginAttemptsClaim(context.steps[1].subject) && parseInt(getFailedLoginAttemptsClaim(context.steps[1].subject)) >= FailedLoginsUntilSMSOTP) {
                    // THIS is where we notice the issue
                    executeStep(2);
                }
            }
        },onFail : function(context) {
            // Retry the login..
            doLogin(context);
        }
    });
};

var getSMSOtpdisabledClaimValue = function(user) {
    return user.localClaims[smsOtpdisabledClaim];
};

var getFailedLoginAttemptsClaim = function(user) {
    return user.localClaims[FailedLoginAttemptsClaim];
};

我们还修改了 SMS OTP Authenticator 以禁用 SMS OTP 的声明检查,方法修改 SMSOTPUtils 文件以始终为用户启用 2FA,而不考虑声明值并将其更改为:

    public static boolean isSMSOTPdisableForLocalUser(String username,AuthenticationContext context)
            throws SMSOTPException {
        // Apply IP filtering!
        // AuthenticationContext related operation with whitelisted IPs,code omitted
        return false;
    }

这通常通过强制用户通过 2FA 来按预期工作,但我们注意到服务提供商要求的某些强制性声明存在问题。

在至少一次登录尝试失败后,系统会提示用户完成服务提供商要求的强制声明,并显示以下屏幕(大多数声明已从屏幕截图中删除,但每个强制声明都被要求作为输入来自用户)。如果第一次尝试登录成功并且与用户 SMS OTP 状态无关(在启用/禁用两种情况下都会发生),则不会发生这种情况

enter image description here

这在任何情况下都不应该发生,因为我们系统中的每个用户都已经为 SP 标记为强制的声明定义了值。

我似乎无法追踪为什么这些声明确实对某些案例有价值,而对其他案例没有价值,我正在这里寻找提示

我使用的是 WSO2 5.9,服务提供者使用带有 POST 绑定的 SAML2 SSO 进行配置,并且在服务提供者高级本地身份验证步骤配置中,我在步骤 1(基本授权)中启用了 Subject IdentifierAttributes )。如果重要的话,用户存储管理器是 JDBC。以下是描述相关(自定义) accountId 声明的服务提供商声明配置的屏幕截图。

enter image description here

更新:经过进一步测试,我们注意到只有在我们启用自定义脚本设置为自适应身份验证时才会发生这种情况,即使它是认设置也是如此。

var onLoginRequest = function(context) { 
   executeStep(1);
   executeStep(2);
}

删除自适应身份验证脚本完全可以正常工作(即使如上所述的“相同”脚本由 IDS 自动添加到相关字段)我们假设用户声明值不是由自适应身份验证机制自动设置的多步验证,我们必须在找到它们的步骤(即第 1 步)上手动设置它们,请指教。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)