You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/09/09 08:46:16 UTC

[tomcat] 04/06: Refactor in preparation for fixinf BZ 62312

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit a747a41f509df1568c5467ece9d9db65f31f0adf
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Sep 9 09:16:04 2022 +0100

    Refactor in preparation for fixinf BZ 62312
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=62312
---
 .../org/apache/tomcat/websocket/Authenticator.java | 32 ++++++++++++++++++++--
 .../tomcat/websocket/BasicAuthenticator.java       |  8 ++----
 .../tomcat/websocket/DigestAuthenticator.java      |  8 ++----
 .../tomcat/websocket/WsWebSocketContainer.java     |  5 +++-
 4 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/Authenticator.java b/java/org/apache/tomcat/websocket/Authenticator.java
index a49e18cb51..0c82ea7fb0 100644
--- a/java/org/apache/tomcat/websocket/Authenticator.java
+++ b/java/org/apache/tomcat/websocket/Authenticator.java
@@ -43,9 +43,37 @@ public abstract class Authenticator {
      * @return The generated authorization header value
      *
      * @throws AuthenticationException When an error occurs
+     *
+     * @deprecated Use {@link
+     *             #getAuthorization(String, String, String, String, String)}.
+     *             Will be removed in Tomcat 10.1.x
+     */
+    @Deprecated
+    public String getAuthorization(String requestUri, String authenticateHeader, Map<String, Object> userProperties)
+            throws AuthenticationException {
+        return getAuthorization(requestUri, authenticateHeader,
+                (String) userProperties.get(Constants.WS_AUTHENTICATION_USER_NAME),
+                (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD),
+                (String) userProperties.get(Constants.WS_AUTHENTICATION_REALM));
+    }
+
+    /**
+     * 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 userName              The user name
+     * @param userPassword          The user password
+     * @param userRealm             The realm for which the provided user name
+     *                                  and password are valid. {@code null} to
+     *                                  indicate all realms.
+     *
+     * @return The generated authorization header value
+     *
+     * @throws AuthenticationException When an error occurs
      */
-    public abstract String getAuthorization(String requestUri, String authenticateHeader,
-            Map<String, Object> userProperties) throws AuthenticationException;
+    public abstract String getAuthorization(String requestUri, String authenticateHeader, String userName,
+            String userPassword, String userRealm) throws AuthenticationException;
 
 
     /**
diff --git a/java/org/apache/tomcat/websocket/BasicAuthenticator.java b/java/org/apache/tomcat/websocket/BasicAuthenticator.java
index e7731cbdb5..d993ccf40d 100644
--- a/java/org/apache/tomcat/websocket/BasicAuthenticator.java
+++ b/java/org/apache/tomcat/websocket/BasicAuthenticator.java
@@ -30,12 +30,8 @@ public class BasicAuthenticator extends Authenticator {
     public static final String charsetparam = "charset";
 
     @Override
-    public String getAuthorization(String requestUri, String authenticateHeader,
-            Map<String, Object> userProperties) throws AuthenticationException {
-
-        String userName = (String) userProperties.get(Constants.WS_AUTHENTICATION_USER_NAME);
-        String userPassword = (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD);
-        String userRealm = (String) userProperties.get(Constants.WS_AUTHENTICATION_REALM);
+    public String getAuthorization(String requestUri, String authenticateHeader, String userName, String userPassword,
+            String userRealm) throws AuthenticationException {
 
         validateUsername(userName);
         validatePassword(userPassword);
diff --git a/java/org/apache/tomcat/websocket/DigestAuthenticator.java b/java/org/apache/tomcat/websocket/DigestAuthenticator.java
index cb6c9318de..f9511537be 100644
--- a/java/org/apache/tomcat/websocket/DigestAuthenticator.java
+++ b/java/org/apache/tomcat/websocket/DigestAuthenticator.java
@@ -36,12 +36,8 @@ public class DigestAuthenticator extends Authenticator {
     private long cNonce;
 
     @Override
-    public String getAuthorization(String requestUri, String authenticateHeader,
-            Map<String, Object> userProperties) throws AuthenticationException {
-
-        String userName = (String) userProperties.get(Constants.WS_AUTHENTICATION_USER_NAME);
-        String userPassword = (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD);
-        String userRealm = (String) userProperties.get(Constants.WS_AUTHENTICATION_REALM);
+    public String getAuthorization(String requestUri, String authenticateHeader, String userName, String userPassword,
+            String userRealm) throws AuthenticationException {
 
         validateUsername(userName);
         validatePassword(userPassword);
diff --git a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
index 608e854bf9..6b301aa086 100644
--- a/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
+++ b/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
@@ -422,7 +422,10 @@ public class WsWebSocketContainer implements WebSocketContainer, BackgroundProce
                     }
 
                     userProperties.put(Constants.AUTHORIZATION_HEADER_NAME, auth.getAuthorization(
-                            requestUri, wwwAuthenticateHeaders.get(0), userProperties));
+                            requestUri, wwwAuthenticateHeaders.get(0),
+                            (String) userProperties.get(Constants.WS_AUTHENTICATION_USER_NAME),
+                            (String) userProperties.get(Constants.WS_AUTHENTICATION_PASSWORD),
+                            (String) userProperties.get(Constants.WS_AUTHENTICATION_REALM)));
 
                     return connectToServerRecursive(
                             clientEndpointHolder, clientEndpointConfiguration, path, redirectSet);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org