Keycloak:绕过身份验证器流程

Keycloak: Bypass an authenticator flow

我有两个UsernamePasswordForm类作为authenticators

SampleUsernamePasswordFormSecurityUsernamePasswordForm

如果 SampleUsernamePasswordForm 成功,则无需移动到 SecurityUsernamePasswordForm,但如果存在任何凭据错误,我想绕过 SampleUsernamePasswordForm 身份验证器并移动到 SecurityUsernamePasswordForm

两者都在ALTERNATIVE下,这意味着如果一个失败,它应该移动到下一个

SampleUsernamePasswordForm,我试过

if (!validateForm(context, formData)) {
        Response challengeResponse = challenge(context, getDefaultChallengeMessage(context), FIELD_PASSWORD);
        context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, challengeResponse);
 }

if (!validateForm(context, formData)) {
        context.failure(AuthenticationFlowError.INVALID_CREDENTIALS);
 }

我以为在此调用 context.failure 会触发 SecurityUsernamePasswordForm,但它只是在同一个登录表单上显示错误消息

目前,我不得不求助于我必须从 SecurityUsernamePasswordForm 登录到 SampleUsernamePasswordForm 的地方,这看起来不太整洁。如何跳到 SecurityUsernamePasswordForm?

此外,由于某种原因,SampleUsernamePasswordForm 对象在 authenticate 被调用之前创建了 3-5 次,这是 Authenticators 会发生的事情吗?

如果这两个执行是 ALTERNATİVE,您只需调用 attempt
在 SampleUsernamePasswordForm 上传递给下一次执行(SecurityUsernamePasswordForm)。但只要确保 at-least 必须在流程结束时返回一次失败或成功。