From 2b35321b7c1a7e4de7ab268e3fd327f82970ecdf Mon Sep 17 00:00:00 2001 From: Phy Date: Fri, 6 Mar 2020 23:48:41 -0500 Subject: [PATCH] KEYCLOAK-13253 read rpId from policy in WebAuthnAuthenticator A new method, getRpID, is created. --- .../browser/WebAuthnAuthenticator.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java index deb9bf73dc..e0eb158773 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java @@ -76,8 +76,7 @@ public class WebAuthnAuthenticator implements Authenticator, CredentialValidator form.setAttribute(WebAuthnConstants.CHALLENGE, challengeValue); WebAuthnPolicy policy = getWebAuthnPolicy(context); - String rpId = policy.getRpId(); - if (rpId == null || rpId.isEmpty()) rpId = context.getUriInfo().getBaseUri().getHost(); + String rpId = getRpID(context); form.setAttribute(WebAuthnConstants.RP_ID, rpId); UserModel user = context.getUser(); @@ -108,6 +107,13 @@ public class WebAuthnAuthenticator implements Authenticator, CredentialValidator return context.getRealm().getWebAuthnPolicy(); } + protected String getRpID(AuthenticationFlowContext context){ + WebAuthnPolicy policy = getWebAuthnPolicy(context); + String rpId = policy.getRpId(); + if (rpId == null || rpId.isEmpty()) rpId = context.getUriInfo().getBaseUri().getHost(); + return rpId; + } + protected String getCredentialType() { return WebAuthnCredentialModel.TYPE_TWOFACTOR; } @@ -126,7 +132,7 @@ public class WebAuthnAuthenticator implements Authenticator, CredentialValidator } String baseUrl = UriUtils.getOrigin(context.getUriInfo().getBaseUri()); - String rpId = context.getUriInfo().getBaseUri().getHost(); + String rpId = getRpID(context); Origin origin = new Origin(baseUrl); Challenge challenge = new DefaultChallenge(context.getAuthenticationSession().getAuthNote(WebAuthnConstants.AUTH_CHALLENGE_NOTE));