This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 27cbe3dcae Clean-up / improve naming. No functional change. 27cbe3dcae is described below commit 27cbe3dcaefd823d2d91247fe01c0a745fbb1700 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Sep 8 19:38:40 2022 +0100 Clean-up / improve naming. No functional change. --- .../org/apache/tomcat/websocket/Authenticator.java | 44 ++++++++++++---------- .../tomcat/websocket/BasicAuthenticator.java | 16 ++++---- .../tomcat/websocket/DigestAuthenticator.java | 23 ++++++----- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/java/org/apache/tomcat/websocket/Authenticator.java b/java/org/apache/tomcat/websocket/Authenticator.java index bc14d5792f..aacbdb47f0 100644 --- a/java/org/apache/tomcat/websocket/Authenticator.java +++ b/java/org/apache/tomcat/websocket/Authenticator.java @@ -22,50 +22,54 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Base class for the authentication methods used by the websocket client. + * Base class for the authentication methods used by the WebSocket client. */ public abstract class Authenticator { - private static final Pattern pattern = Pattern - .compile("(\\w+)\\s*=\\s*(\"([^\"]+)\"|([^,=\"]+))\\s*,?"); + + private static final Pattern pattern = Pattern.compile("(\\w+)\\s*=\\s*(\"([^\"]+)\"|([^,=\"]+))\\s*,?"); /** - * Generate the authentication header that will be sent to the server. - * @param requestUri The request URI - * @param WWWAuthenticate The server auth challenge - * @param UserProperties The user information - * @return The auth header + * Generate the authorization header value that will be sent to the server. + * + * @param requestUri The request URI + * @param authenticateHeader The server authentication header received + * @param userProperties The user information + * + * @return The generated authorization header value + * * @throws AuthenticationException When an error occurs */ - public abstract String getAuthorization(String requestUri, String WWWAuthenticate, - Map<String, Object> UserProperties) throws AuthenticationException; + public abstract String getAuthorization(String requestUri, String authenticateHeader, + Map<String, Object> userProperties) throws AuthenticationException; /** * Get the authentication method. - * @return the auth scheme + * + * @return the authentication scheme */ public abstract String getSchemeName(); /** * Utility method to parse the authentication header. - * @param WWWAuthenticate The server auth challenge - * @return the parsed header + * + * @param authenticateHeader The server authenticate header received + * + * @return a map of authentication parameter names and values */ - public Map<String, String> parseWWWAuthenticateHeader(String WWWAuthenticate) { + public Map<String, String> parseWWWAuthenticateHeader(String authenticateHeader) { - Matcher m = pattern.matcher(WWWAuthenticate); - Map<String, String> challenge = new HashMap<>(); + Matcher m = pattern.matcher(authenticateHeader); + Map<String, String> parameterMap = new HashMap<>(); while (m.find()) { String key = m.group(1); String qtedValue = m.group(3); String value = m.group(4); - challenge.put(key, qtedValue != null ? qtedValue : value); + parameterMap.put(key, qtedValue != null ? qtedValue : value); } - return challenge; - + return parameterMap; } - } diff --git a/java/org/apache/tomcat/websocket/BasicAuthenticator.java b/java/org/apache/tomcat/websocket/BasicAuthenticator.java index 13a25e22de..07b583004f 100644 --- a/java/org/apache/tomcat/websocket/BasicAuthenticator.java +++ b/java/org/apache/tomcat/websocket/BasicAuthenticator.java @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.tomcat.util.codec.binary.Base64; /** - * Authenticator supporting the BASIC auth method. + * Authenticator supporting the BASIC authentication method. */ public class BasicAuthenticator extends Authenticator { @@ -31,24 +31,24 @@ public class BasicAuthenticator extends Authenticator { public static final String charsetparam = "charset"; @Override - public String getAuthorization(String requestUri, String WWWAuthenticate, + public String getAuthorization(String requestUri, String authenticateHeader, Map<String, Object> userProperties) throws AuthenticationException { String userName = (String) userProperties.get(Constants.WS_AUTHENTICATION_USER_NAME); - String password = (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD); + String userPassword = (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD); - if (userName == null || password == null) { + if (userName == null || userPassword == null) { throw new AuthenticationException( "Failed to perform Basic authentication due to missing user/password"); } - Map<String, String> wwwAuthenticate = parseWWWAuthenticateHeader(WWWAuthenticate); + Map<String, String> parameterMap = parseWWWAuthenticateHeader(authenticateHeader); - String userPass = userName + ":" + password; + String userPass = userName + ":" + userPassword; Charset charset; - if (wwwAuthenticate.get(charsetparam) != null - && wwwAuthenticate.get(charsetparam).equalsIgnoreCase("UTF-8")) { + if (parameterMap.get(charsetparam) != null + && parameterMap.get(charsetparam).equalsIgnoreCase("UTF-8")) { charset = StandardCharsets.UTF_8; } else { charset = StandardCharsets.ISO_8859_1; diff --git a/java/org/apache/tomcat/websocket/DigestAuthenticator.java b/java/org/apache/tomcat/websocket/DigestAuthenticator.java index 5bd513fc2f..53c3f45a28 100644 --- a/java/org/apache/tomcat/websocket/DigestAuthenticator.java +++ b/java/org/apache/tomcat/websocket/DigestAuthenticator.java @@ -25,7 +25,7 @@ import java.util.Map; import org.apache.tomcat.util.security.MD5Encoder; /** - * Authenticator supporting the DIGEST auth method. + * Authenticator supporting the DIGEST authentication method. */ public class DigestAuthenticator extends Authenticator { @@ -36,25 +36,24 @@ public class DigestAuthenticator extends Authenticator { private long cNonce; @Override - public String getAuthorization(String requestUri, String WWWAuthenticate, + public String getAuthorization(String requestUri, String authenticateHeader, Map<String, Object> userProperties) throws AuthenticationException { String userName = (String) userProperties.get(Constants.WS_AUTHENTICATION_USER_NAME); - String password = (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD); + String userPassword = (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD); - if (userName == null || password == null) { + if (userName == null || userPassword == null) { throw new AuthenticationException( "Failed to perform Digest authentication due to missing user/password"); } - Map<String, String> wwwAuthenticate = parseWWWAuthenticateHeader(WWWAuthenticate); + Map<String, String> parameterMap = parseWWWAuthenticateHeader(authenticateHeader); - String realm = wwwAuthenticate.get("realm"); - String nonce = wwwAuthenticate.get("nonce"); - String messageQop = wwwAuthenticate.get("qop"); - String algorithm = wwwAuthenticate.get("algorithm") == null ? "MD5" - : wwwAuthenticate.get("algorithm"); - String opaque = wwwAuthenticate.get("opaque"); + String realm = parameterMap.get("realm"); + String nonce = parameterMap.get("nonce"); + String messageQop = parameterMap.get("qop"); + String algorithm = parameterMap.get("algorithm") == null ? "MD5" : parameterMap.get("algorithm"); + String opaque = parameterMap.get("opaque"); StringBuilder challenge = new StringBuilder(); @@ -78,7 +77,7 @@ public class DigestAuthenticator extends Authenticator { challenge.append("uri=\"" + requestUri + "\","); try { - challenge.append("response=\"" + calculateRequestDigest(requestUri, userName, password, + challenge.append("response=\"" + calculateRequestDigest(requestUri, userName, userPassword, realm, nonce, messageQop, algorithm) + "\","); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org