tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security HttpBasicValve.java HttpDigestValve.java HttpSecurityBase.java
Date Thu, 22 Jun 2000 03:00:48 GMT
craigmcc    00/06/21 20:00:47

  Modified:    proposals/catalina/src/share/org/apache/tomcat/realm
                        LocalStrings.properties
               proposals/catalina/src/share/org/apache/tomcat/security
                        HttpBasicValve.java HttpDigestValve.java
                        HttpSecurityBase.java
  Log:
  Enable caching of authenticated Principals for the BASIC and DIGEST
  authenticators, if the incoming request is part of a session.  This can
  save potentially expensive user lookups on every request (such as when
  the underlying Realm is a database or directory server).
  
  Revision  Changes    Path
  1.4       +1 -1      jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/realm/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/realm/LocalStrings.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalStrings.properties	2000/05/09 22:30:25	1.3
  +++ LocalStrings.properties	2000/06/22 03:00:32	1.4
  @@ -2,7 +2,7 @@
   memoryRealm.authenticateFailure=Authentication unsuccessful for user {0}
   memoryRealm.authenticateSuccess=Authentication successful for user {0}
   memoryRealm.hasRoleFailure=User {0} does NOT have role {1}
  -memoryRealm.hasRoleNone=No user has role {1}
  +memoryRealm.hasRoleNone=No user has role {0}
   memoryRealm.hasRoleSuccess=User {0} has role {1}
   memoryRealm.hasRoleUser=User {0} is not in this realm database
   memoryRealm.loadExist=Memory realm file {0} does not exist
  
  
  
  1.5       +20 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicValve.java
  
  Index: HttpBasicValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicValve.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HttpBasicValve.java	2000/05/31 01:33:32	1.4
  +++ HttpBasicValve.java	2000/06/22 03:00:37	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicValve.java,v
1.4 2000/05/31 01:33:32 remm Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/05/31 01:33:32 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicValve.java,v
1.5 2000/06/22 03:00:37 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2000/06/22 03:00:37 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import org.apache.tomcat.HttpRequest;
   import org.apache.tomcat.HttpResponse;
   import org.apache.tomcat.Realm;
  +import org.apache.tomcat.Session;
   import org.apache.tomcat.deploy.LoginConfig;
   import org.apache.tomcat.util.Base64;
   
  @@ -83,7 +84,7 @@
    * and Digest Access Authentication."
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2000/05/31 01:33:32 $
  + * @version $Revision: 1.5 $ $Date: 2000/06/22 03:00:37 $
    */
   
   public final class HttpBasicValve
  @@ -146,6 +147,19 @@
   	if (principal != null)
   	    return (true);
   
  +	// Have we got a cached authenticated Principal?
  +	Session session = null;
  +	if (cache)
  +	    session = getSession(request);
  +	if (session != null) {
  +	    principal = session.getPrincipal();
  +	    if (principal != null) {
  +	        request.setAuthType("BASIC");
  +		request.setUserPrincipal(principal);
  +		return (true);
  +	    }
  +	}
  +
   	// Validate any credentials already included with this request
   	HttpServletRequest hreq =
   	    (HttpServletRequest) request.getRequest();
  @@ -157,6 +171,8 @@
   	    if (principal != null) {
   	        request.setAuthType("BASIC");
   		request.setUserPrincipal(principal);
  +		if (cache && (session != null))
  +		    session.setPrincipal(principal);
   		return (true);
   	    }
   	}
  
  
  
  1.2       +20 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpDigestValve.java
  
  Index: HttpDigestValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpDigestValve.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpDigestValve.java	2000/05/31 01:33:32	1.1
  +++ HttpDigestValve.java	2000/06/22 03:00:37	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpDigestValve.java,v
1.1 2000/05/31 01:33:32 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/31 01:33:32 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpDigestValve.java,v
1.2 2000/06/22 03:00:37 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/22 03:00:37 $
    *
    * ====================================================================
    *
  @@ -76,6 +76,7 @@
   import org.apache.tomcat.HttpRequest;
   import org.apache.tomcat.HttpResponse;
   import org.apache.tomcat.Realm;
  +import org.apache.tomcat.Session;
   import org.apache.tomcat.deploy.LoginConfig;
   import org.apache.tomcat.util.MD5Encoder;
   
  @@ -87,7 +88,7 @@
    * 
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.1 $ $Date: 2000/05/31 01:33:32 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/22 03:00:37 $
    */
   
   public final class HttpDigestValve
  @@ -220,6 +221,19 @@
   	if (principal != null)
   	    return (true);
   
  +	// Have we got a cached authenticated Principal?
  +	Session session = null;
  +	if (cache)
  +	    session = getSession(request);
  +	if (session != null) {
  +	    principal = session.getPrincipal();
  +	    if (principal != null) {
  +	        request.setAuthType("DIGEST");
  +		request.setUserPrincipal(principal);
  +		return (true);
  +	    }
  +	}
  +
   	// Validate any credentials already included with this request
   	HttpServletRequest hreq =
   	    (HttpServletRequest) request.getRequest();
  @@ -231,6 +245,8 @@
   	    if (principal != null) {
   	        request.setAuthType("DIGEST");
   		request.setUserPrincipal(principal);
  +		if (cache && (session != null))
  +		    session.setPrincipal(principal);
   		return (true);
   	    }
   	}
  
  
  
  1.2       +61 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityBase.java
  
  Index: HttpSecurityBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpSecurityBase.java	2000/05/05 18:25:13	1.1
  +++ HttpSecurityBase.java	2000/06/22 03:00:38	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityBase.java,v
1.1 2000/05/05 18:25:13 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/05 18:25:13 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityBase.java,v
1.2 2000/06/22 03:00:38 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/06/22 03:00:38 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import javax.servlet.http.HttpSession;
   import org.apache.tomcat.Authenticator;
   import org.apache.tomcat.Container;
   import org.apache.tomcat.Context;
  @@ -82,9 +83,11 @@
   import org.apache.tomcat.LifecycleException;
   import org.apache.tomcat.LifecycleListener;
   import org.apache.tomcat.Logger;
  +import org.apache.tomcat.Manager;
   import org.apache.tomcat.Realm;
   import org.apache.tomcat.Request;
   import org.apache.tomcat.Response;
  +import org.apache.tomcat.Session;
   import org.apache.tomcat.Valve;
   import org.apache.tomcat.deploy.LoginConfig;
   import org.apache.tomcat.deploy.SecurityConstraint;
  @@ -110,7 +113,7 @@
    * requests.  Requests of any other type will simply be passed through.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/05/05 18:25:13 $
  + * @version $Revision: 1.2 $ $Date: 2000/06/22 03:00:38 $
    */
   
   
  @@ -123,6 +126,13 @@
   
   
       /**
  +     * Should we cache authenticated Principals if the request is part of
  +     * an HTTP session?
  +     */
  +    protected boolean cache = true;
  +
  +
  +    /**
        * The Context to which this Valve is attached.
        */
       protected Context context = null;
  @@ -164,6 +174,28 @@
   
   
       /**
  +     * Return the cache authenticated Principals flag.
  +     */
  +    public boolean getCache() {
  +
  +	return (this.cache);
  +
  +    }
  +
  +
  +    /**
  +     * Set the cache authenticated Principals flag.
  +     *
  +     * @param cache The new cache flag
  +     */
  +    public void setCache(boolean cache) {
  +
  +	this.cache = cache;
  +
  +    }
  +
  +
  +    /**
        * Return the Container to which this Valve is attached.
        */
       public Container getContainer() {
  @@ -426,6 +458,31 @@
   
   	// No applicable security constraint was found
   	return (null);
  +
  +    }
  +
  +
  +    /**
  +     * Return the internal Session that is associated with this request,
  +     * if there is one; otherwise return <code>null</code>.
  +     */
  +    protected Session getSession(HttpRequest request) {
  +
  +	HttpServletRequest hreq =
  +	    (HttpServletRequest) request.getRequest();
  +	HttpSession hses = hreq.getSession(false);
  +	if (hses == null)
  +	    return (null);
  +	Manager manager = context.getManager();
  +	if (manager == null)
  +	    return (null);
  +	else {
  +	    try {
  +		return (manager.findSession(hses.getId()));
  +	    } catch (IOException e) {
  +		return (null);
  +	    }
  +	}
   
       }
   
  
  
  

Mime
View raw message