geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r923622 - /geronimo/external/trunk/tomcat-parent-6.0.26/catalina/src/main/java/org/apache/catalina/authenticator/BasicAuthenticator.java
Date Tue, 16 Mar 2010 08:08:18 GMT
Author: xuhaihong
Date: Tue Mar 16 08:08:18 2010
New Revision: 923622

URL: http://svn.apache.org/viewvc?rev=923622&view=rev
Log:
GERONIMO-5129 Fix to be picked from tomcat for Spnego support in geronimo (Patch from Ashish
Jain)

Modified:
    geronimo/external/trunk/tomcat-parent-6.0.26/catalina/src/main/java/org/apache/catalina/authenticator/BasicAuthenticator.java

Modified: geronimo/external/trunk/tomcat-parent-6.0.26/catalina/src/main/java/org/apache/catalina/authenticator/BasicAuthenticator.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-6.0.26/catalina/src/main/java/org/apache/catalina/authenticator/BasicAuthenticator.java?rev=923622&r1=923621&r2=923622&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-6.0.26/catalina/src/main/java/org/apache/catalina/authenticator/BasicAuthenticator.java
(original)
+++ geronimo/external/trunk/tomcat-parent-6.0.26/catalina/src/main/java/org/apache/catalina/authenticator/BasicAuthenticator.java
Tue Mar 16 08:08:18 2010
@@ -21,9 +21,8 @@ package org.apache.catalina.authenticato
 
 import java.io.IOException;
 import java.security.Principal;
-
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.deploy.LoginConfig;
@@ -82,6 +81,8 @@ public class BasicAuthenticator
      */
     protected static final String info =
         "org.apache.catalina.authenticator.BasicAuthenticator/1.0";
+    
+    protected static final String negotiate="org.apache.tomcat.config.NEGOTIATE" ;
 
 
     // ------------------------------------------------------------- Properties
@@ -113,11 +114,31 @@ public class BasicAuthenticator
      *
      * @exception IOException if an input/output error occurs
      */
+    
     public boolean authenticate(Request request,
                                 Response response,
                                 LoginConfig config)
         throws IOException {
-
+        HttpServletResponse httpResponse=response.getResponse();
+        HttpServletRequest httpRequest=request.getRequest();        
+        if (System.getProperty(negotiate, "false").equalsIgnoreCase("true")) {
+            String header = httpRequest.getHeader("Authorization");
+            if (header == null) {
+                httpResponse.setHeader("WWW-Authenticate", "Negotiate");
+                httpResponse.setStatus(401);
+                return false;
+            } else if (header != null && header.startsWith("Negotiate")) {
+                Principal principal = request.getUserPrincipal();
+                String username = header.substring(10);
+                String password = null;
+                principal = context.getRealm().authenticate(username, password);
+                if (principal != null) {
+                    register(request, response, principal, Constants.BASIC_METHOD, username,
password);
+                    return true;
+                } else
+                    request.getCoyoteRequest().getMimeHeaders().removeHeader("authorization");
+            }
+        }
         // Have we already authenticated someone?
         Principal principal = request.getUserPrincipal();
         String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
@@ -173,11 +194,10 @@ public class BasicAuthenticator
                     username = new String(buf, 0, colon);
                     password = new String(buf, colon + 1, 
                             authorizationCC.getEnd() - colon - 1);
-                }
+                       }
                 
                 authorizationBC.setOffset(authorizationBC.getOffset() - 6);
             }
-
             principal = context.getRealm().authenticate(username, password);
             if (principal != null) {
                 register(request, response, principal, Constants.BASIC_METHOD,
@@ -186,7 +206,6 @@ public class BasicAuthenticator
             }
         }
         
-
         // Send an "unauthorized" response and an appropriate challenge
         MessageBytes authenticate = 
             response.getCoyoteResponse().getMimeHeaders()
@@ -205,8 +224,5 @@ public class BasicAuthenticator
         response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
         //response.flushBuffer();
         return (false);
-
     }
-
-
 }



Mime
View raw message