Implement recovery key support for user storage providers#2
Conversation
closes #38445 Signed-off-by: rtufisi <rtufisi@phasetwo.io>
Codoki PR ReviewSummary: Add recovery codes handling, ensure null-safety and flow hygiene Issues (Medium)
Showing up to 1 medium issue(s). See inline suggestions for more details. Key Feedback (click to expand)
Confidence: 4/5 — Looks good; minor fixes (1 medium) Sequence DiagramsequenceDiagram
participant RA as RecoveryAuthnCodesAction
participant CH as CredentialHelper
participant UCM as user.credentialManager()
participant CP as CredentialProvider(keycloak-recovery-authn-codes)
RA->>CH: createRecoveryCodesCredential(session, realm, user, model, codes)
alt userStorage update
CH->>UCM: updateCredential(UserCredentialModel)
UCM-->>CH: true
CH-->>RA: (created in user storage)
else local storage
CH->>UCM: updateCredential(UserCredentialModel)
UCM-->>CH: false
CH->>CP: createCredential(realm, user, model)
CP-->>CH: Credential created
CH-->>RA: (created in local storage)
end
React with 👍 or 👎 if you found this review useful. |
| Optional<CredentialModel> credentialModelOpt = RecoveryAuthnCodesUtils.getCredential(user); | ||
|
|
||
| RecoveryAuthnCodesCredentialModel recoveryCodeCredentialModel = RecoveryAuthnCodesCredentialModel.createFromCredentialModel(credentialModel); | ||
| RecoveryAuthnCodesCredentialModel recoveryCodeCredentialModel = RecoveryAuthnCodesCredentialModel.createFromCredentialModel(credentialModelOpt.get()); |
There was a problem hiding this comment.
🔷 Medium: Possible NoSuchElementException if the recovery codes credential is absent (or removed concurrently), and getNextRecoveryAuthnCode().get() can also be empty when all codes are used. Guard both Optionals to avoid runtime 500s during login.
| .clear() | ||
| .addAuthenticatorExecution(AuthenticationExecutionModel.Requirement.REQUIRED, UsernamePasswordFormFactory.PROVIDER_ID) | ||
| .addSubFlowExecution(AuthenticationExecutionModel.Requirement.REQUIRED, reqSubFlow -> reqSubFlow | ||
| .addSubFlowExecution("Recovery-Authn-Codes subflow", AuthenticationFlow.BASIC_FLOW, AuthenticationExecutionModel.Requirement.ALTERNATIVE, altSubFlow -> altSubFlow |
There was a problem hiding this comment.
💡 Low: Minor typo in the alias string ('suthenticator'); fixing it improves readability and consistency in flow debugging.
| .addSubFlowExecution("Recovery-Authn-Codes subflow", AuthenticationFlow.BASIC_FLOW, AuthenticationExecutionModel.Requirement.ALTERNATIVE, altSubFlow -> altSubFlow | |
| config.setAlias("delayed-authenticator-config"); |
No description provided.