[java-idp-plugin-webauthn] branch main updated: Add raw username to extraction action

Phil Smart philip.smart at jisc.ac.uk
Tue Nov 12 14:06:22 UTC 2024


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch main
in repository java-idp-plugin-webauthn.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-webauthn.git;a=commit;h=6f04c3fab4917d5b2d462a512790d76782acf478

The following commit(s) were added to refs/heads/main by this push:
     new 6f04c3f  Add raw username to extraction action
6f04c3f is described below

commit 6f04c3fab4917d5b2d462a512790d76782acf478
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Tue Nov 12 14:06:20 2024 +0000

    Add raw username to extraction action
    
     - Can be used to pre-populate views etc.
---
 .../webauthn/context/BaseWebAuthnContext.java      | 27 ++++++++++++++++++++++
 .../webauthn/impl/ExtractUsernameFromForm.java     | 24 +++++++++++++++----
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/BaseWebAuthnContext.java b/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/BaseWebAuthnContext.java
index 63b0261..b9476de 100644
--- a/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/BaseWebAuthnContext.java
+++ b/webauthn-api/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/context/BaseWebAuthnContext.java
@@ -46,6 +46,12 @@ public class BaseWebAuthnContext extends BaseContext {
      */
     @Nullable private String username;
     
+    /** 
+     * The raw username entered by the user in one of the username collection steps. Is not transformed or 
+     * canonicalized in anyway.
+     */
+    @Nullable private String rawUsername;
+    
     /** 
      * Credentials that have already been registered with the IdP. The authenticator should use these to avoid creating
      * duplicate credentials during registration, or to tell the browser which credentials to use during authentication.
@@ -93,6 +99,27 @@ public class BaseWebAuthnContext extends BaseContext {
         username = name;
         return this;
     }
+    
+    /**
+     * Gets the raw username entered by the user in one of the username collection steps.
+     * 
+     * @return the raw username entered by the user
+     */
+    @Nullable public String getRawUsername() {
+        return rawUsername;
+    }
+
+    /**
+     * Sets the raw username entered by the user in one of the username collection steps.
+     * 
+     * @param name the raw username entered by the user
+     * 
+     * @return this context
+     */
+    @Nonnull public BaseWebAuthnContext setRawUsername(@Nullable final String name) {
+        rawUsername = name;
+        return this;
+    }
 
     /**
      * Set the user's credentials that have already been registered with the credential repository.
diff --git a/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromForm.java b/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromForm.java
index 24cc75f..e4fcbe0 100644
--- a/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromForm.java
+++ b/webauthn-impl/src/main/java/net/shibboleth/idp/plugin/authn/webauthn/impl/ExtractUsernameFromForm.java
@@ -129,7 +129,7 @@ public class ExtractUsernameFromForm extends AbstractExtractionAction {
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext,
             @Nonnull final AuthenticationContext authenticationContext) {        
 
-        final String username = getUsernameFromForm(profileRequestContext, authenticationContext);
+        final String username = processFormSubmission(profileRequestContext, authenticationContext);
         if (username == null) {
             log.warn("{} Unable to find username in HTTP request", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, AuthnEventIds.UNKNOWN_USERNAME);
@@ -137,20 +137,34 @@ public class ExtractUsernameFromForm extends AbstractExtractionAction {
         }
         log.trace("{} Populating username '{}' from form",getLogPrefix(), username);
         webAuthnContext.setUsername(username);
+        // Set the original, unmodified username.
+        webAuthnContext.setRawUsername(getUsernameFromForm());
         
     }
     
     /**
      * Gets the username from a form submission.
      * 
-     * <p>Also processes do-not-cache instruction.</p>
+     * @return the raw submitted username
+     */
+    @Nullable private String getUsernameFromForm() {
+        
+        final HttpServletRequest request = getHttpServletRequest();
+        if (request != null) {
+            return request.getParameter(usernameFieldName);
+        }
+        return null;
+    }
+    
+    /**
+     * Process the form submission: extract and transform the username, processes do-not-cache instruction.
      * 
      * @param profileRequestContext profile request context
      * @param authenticationContext authentication context
      * 
-     * @return submitted username, after applying any configured transforms
+     * @return the submitted username, after applying any configured transforms
      */
-    @Nullable private String getUsernameFromForm(@Nonnull final ProfileRequestContext profileRequestContext,
+    @Nullable private String processFormSubmission(@Nonnull final ProfileRequestContext profileRequestContext,
             @Nonnull final AuthenticationContext authenticationContext) {
         
         final HttpServletRequest request = getHttpServletRequest();
@@ -162,7 +176,7 @@ public class ExtractUsernameFromForm extends AbstractExtractionAction {
             } else {
                 authenticationContext.setResultCacheable(true);
             }            
-            return applyTransforms(request.getParameter(usernameFieldName));            
+            return applyTransforms(getUsernameFromForm());            
         }        
         return null;
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list