You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pi...@apache.org on 2001/07/22 21:20:12 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator AuthenticatorBase.java BasicAuthenticator.java Constants.java DigestAuthenticator.java FormAuthenticator.java NonLoginAuthenticator.java SSLAuthenticator.java SavedRequest.java SingleSignOn.java
pier 01/07/22 12:20:12
Modified: catalina/src/share/org/apache/catalina/authenticator
AuthenticatorBase.java BasicAuthenticator.java
Constants.java DigestAuthenticator.java
FormAuthenticator.java NonLoginAuthenticator.java
SSLAuthenticator.java SavedRequest.java
SingleSignOn.java
Log:
Converted tabs-to-spaces and trimmed right-hand side of each line.
Revision Changes Path
1.18 +284 -284 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java
Index: AuthenticatorBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- AuthenticatorBase.java 2001/05/16 19:30:38 1.17
+++ AuthenticatorBase.java 2001/07/22 19:20:11 1.18
@@ -1,13 +1,13 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java,v 1.17 2001/05/16 19:30:38 craigmcc Exp $
- * $Revision: 1.17 $
- * $Date: 2001/05/16 19:30:38 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/AuthenticatorBase.java,v 1.18 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.18 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -15,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -23,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -59,7 +59,7 @@
*
* [Additional notices, if required by prior licensing conditions]
*
- */
+ */
package org.apache.catalina.authenticator;
@@ -121,7 +121,7 @@
* requests. Requests of any other type will simply be passed through.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.17 $ $Date: 2001/05/16 19:30:38 $
+ * @version $Revision: 1.18 $ $Date: 2001/07/22 19:20:11 $
*/
@@ -192,7 +192,7 @@
* Descriptive information about this implementation.
*/
protected static final String info =
- "org.apache.catalina.authenticator.AuthenticatorBase/1.0";
+ "org.apache.catalina.authenticator.AuthenticatorBase/1.0";
/**
@@ -218,7 +218,7 @@
* The string manager for this package.
*/
protected static final StringManager sm =
- StringManager.getManager(Constants.Package);
+ StringManager.getManager(Constants.Package);
/**
@@ -242,7 +242,7 @@
*/
public String getAlgorithm() {
- return (this.algorithm);
+ return (this.algorithm);
}
@@ -254,7 +254,7 @@
*/
public void setAlgorithm(String algorithm) {
- this.algorithm = algorithm;
+ this.algorithm = algorithm;
}
@@ -264,7 +264,7 @@
*/
public boolean getCache() {
- return (this.cache);
+ return (this.cache);
}
@@ -276,7 +276,7 @@
*/
public void setCache(boolean cache) {
- this.cache = cache;
+ this.cache = cache;
}
@@ -286,7 +286,7 @@
*/
public Container getContainer() {
- return (this.context);
+ return (this.context);
}
@@ -298,12 +298,12 @@
*/
public void setContainer(Container container) {
- if (!(container instanceof Context))
- throw new IllegalArgumentException
- (sm.getString("authenticator.notContext"));
+ if (!(container instanceof Context))
+ throw new IllegalArgumentException
+ (sm.getString("authenticator.notContext"));
- super.setContainer(container);
- this.context = (Context) container;
+ super.setContainer(container);
+ this.context = (Context) container;
}
@@ -336,11 +336,11 @@
*/
public String getEntropy() {
- // Calculate a semi-useful value if this has not been set
- if (this.entropy == null)
- setEntropy(this.toString());
+ // Calculate a semi-useful value if this has not been set
+ if (this.entropy == null)
+ setEntropy(this.toString());
- return (this.entropy);
+ return (this.entropy);
}
@@ -352,7 +352,7 @@
*/
public void setEntropy(String entropy) {
- this.entropy = entropy;
+ this.entropy = entropy;
}
@@ -362,7 +362,7 @@
*/
public String getInfo() {
- return (this.info);
+ return (this.info);
}
@@ -372,7 +372,7 @@
*/
public String getRandomClass() {
- return (this.randomClass);
+ return (this.randomClass);
}
@@ -384,7 +384,7 @@
*/
public void setRandomClass(String randomClass) {
- this.randomClass = randomClass;
+ this.randomClass = randomClass;
}
@@ -406,26 +406,26 @@
*/
public void invoke(Request request, Response response,
ValveContext context)
- throws IOException, ServletException {
+ throws IOException, ServletException {
- // If this is not an HTTP request, do nothing
- if (!(request instanceof HttpRequest) ||
+ // If this is not an HTTP request, do nothing
+ if (!(request instanceof HttpRequest) ||
!(response instanceof HttpResponse)) {
- context.invokeNext(request, response);
- return;
- }
- if (!(request.getRequest() instanceof HttpServletRequest) ||
- !(response.getResponse() instanceof HttpServletResponse)) {
- context.invokeNext(request, response);
- return;
- }
- HttpRequest hrequest = (HttpRequest) request;
- HttpResponse hresponse = (HttpResponse) response;
- if (debug >= 1)
- log("Security checking request " +
- ((HttpServletRequest) request.getRequest()).getMethod() + " " +
- ((HttpServletRequest) request.getRequest()).getRequestURI());
- LoginConfig config = this.context.getLoginConfig();
+ context.invokeNext(request, response);
+ return;
+ }
+ if (!(request.getRequest() instanceof HttpServletRequest) ||
+ !(response.getResponse() instanceof HttpServletResponse)) {
+ context.invokeNext(request, response);
+ return;
+ }
+ HttpRequest hrequest = (HttpRequest) request;
+ HttpResponse hresponse = (HttpResponse) response;
+ if (debug >= 1)
+ log("Security checking request " +
+ ((HttpServletRequest) request.getRequest()).getMethod() + " " +
+ ((HttpServletRequest) request.getRequest()).getRequestURI());
+ LoginConfig config = this.context.getLoginConfig();
// Have we got a cached authenticated Principal to record?
if (cache) {
@@ -447,46 +447,46 @@
}
}
}
+
+ // Special handling for form-based logins to deal with the case
+ // where the login form (and therefore the "j_security_check" URI
+ // to which it submits) might be outside the secured area
+ String contextPath = this.context.getPath();
+ String requestURI =
+ ((HttpServletRequest) request.getRequest()).getRequestURI();
+ if (requestURI.startsWith(contextPath) &&
+ requestURI.endsWith(Constants.FORM_ACTION)) {
+ if (!authenticate(hrequest, hresponse, config)) {
+ if (debug >= 1)
+ log(" Failed authenticate() test");
+ return;
+ }
+ }
- // Special handling for form-based logins to deal with the case
- // where the login form (and therefore the "j_security_check" URI
- // to which it submits) might be outside the secured area
- String contextPath = this.context.getPath();
- String requestURI =
- ((HttpServletRequest) request.getRequest()).getRequestURI();
- if (requestURI.startsWith(contextPath) &&
- requestURI.endsWith(Constants.FORM_ACTION)) {
- if (!authenticate(hrequest, hresponse, config)) {
- if (debug >= 1)
- log(" Failed authenticate() test");
- return;
- }
- }
-
- // Is this request URI subject to a security constraint?
- SecurityConstraint constraint = findConstraint(hrequest);
- if ((constraint == null) /* &&
- (!Constants.FORM_METHOD.equals(config.getAuthMethod())) */ ) {
- if (debug >= 1)
- log(" Not subject to any constraint");
- context.invokeNext(request, response);
- return;
- }
- if ((debug >= 1) && (constraint != null))
- log(" Subject to constraint " + constraint);
+ // Is this request URI subject to a security constraint?
+ SecurityConstraint constraint = findConstraint(hrequest);
+ if ((constraint == null) /* &&
+ (!Constants.FORM_METHOD.equals(config.getAuthMethod())) */ ) {
+ if (debug >= 1)
+ log(" Not subject to any constraint");
+ context.invokeNext(request, response);
+ return;
+ }
+ if ((debug >= 1) && (constraint != null))
+ log(" Subject to constraint " + constraint);
- // Enforce any user data constraint for this security constraint
+ // Enforce any user data constraint for this security constraint
if (debug >= 1)
log(" Calling checkUserData()");
- if (!checkUserData(hrequest, hresponse, constraint)) {
- if (debug >= 1)
- log(" Failed checkUserData() test");
+ if (!checkUserData(hrequest, hresponse, constraint)) {
+ if (debug >= 1)
+ log(" Failed checkUserData() test");
// ASSERT: Authenticator already set the appropriate
// HTTP status code, so we do not have to do anything special
- return;
- }
+ return;
+ }
- // Authenticate based upon the specified login configuration
+ // Authenticate based upon the specified login configuration
if (constraint.getAuthConstraint()) {
if (debug >= 1)
log(" Calling authenticate()");
@@ -499,7 +499,7 @@
}
}
- // Perform access control based on the specified role(s)
+ // Perform access control based on the specified role(s)
if (constraint.getAuthConstraint()) {
if (debug >= 1)
log(" Calling accessControl()");
@@ -512,10 +512,10 @@
}
}
- // Any and all specified constraints have been satisfied
- if (debug >= 1)
- log(" Successfully passed all security constraints");
- context.invokeNext(request, response);
+ // Any and all specified constraints have been satisfied
+ if (debug >= 1)
+ log(" Successfully passed all security constraints");
+ context.invokeNext(request, response);
}
@@ -535,56 +535,56 @@
* @exception IOException if an input/output error occurs
*/
protected boolean accessControl(HttpRequest request,
- HttpResponse response,
- SecurityConstraint constraint)
- throws IOException {
-
- if (constraint == null)
- return (true);
-
- // Specifically allow access to the form login and form error pages
- LoginConfig config = context.getLoginConfig();
- if ((config != null) &&
- (Constants.FORM_METHOD.equals(config.getAuthMethod()))) {
- String requestURI =
- ((HttpServletRequest) request.getRequest()).getRequestURI();
- String loginPage = context.getPath() + config.getLoginPage();
- if (loginPage.equals(requestURI)) {
- if (debug >= 1)
- log(" Allow access to login page " + loginPage);
- return (true);
- }
- String errorPage = context.getPath() + config.getErrorPage();
- if (errorPage.equals(requestURI)) {
- if (debug >= 1)
- log(" Allow access to error page " + errorPage);
- return (true);
- }
- if (requestURI.endsWith(Constants.FORM_ACTION)) {
- if (debug >= 1)
- log(" Allow access to username/password submission");
- return (true);
- }
- }
-
- // Which user principal have we already authenticated?
- Principal principal =
- ((HttpServletRequest) request.getRequest()).getUserPrincipal();
- if (principal == null) {
+ HttpResponse response,
+ SecurityConstraint constraint)
+ throws IOException {
+
+ if (constraint == null)
+ return (true);
+
+ // Specifically allow access to the form login and form error pages
+ LoginConfig config = context.getLoginConfig();
+ if ((config != null) &&
+ (Constants.FORM_METHOD.equals(config.getAuthMethod()))) {
+ String requestURI =
+ ((HttpServletRequest) request.getRequest()).getRequestURI();
+ String loginPage = context.getPath() + config.getLoginPage();
+ if (loginPage.equals(requestURI)) {
+ if (debug >= 1)
+ log(" Allow access to login page " + loginPage);
+ return (true);
+ }
+ String errorPage = context.getPath() + config.getErrorPage();
+ if (errorPage.equals(requestURI)) {
+ if (debug >= 1)
+ log(" Allow access to error page " + errorPage);
+ return (true);
+ }
+ if (requestURI.endsWith(Constants.FORM_ACTION)) {
+ if (debug >= 1)
+ log(" Allow access to username/password submission");
+ return (true);
+ }
+ }
+
+ // Which user principal have we already authenticated?
+ Principal principal =
+ ((HttpServletRequest) request.getRequest()).getUserPrincipal();
+ if (principal == null) {
if (debug >= 2)
log(" No user authenticated, cannot grant access");
- ((HttpServletResponse) response.getResponse()).sendError
- (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- sm.getString("authenticator.notAuthenticated"));
- return (false);
- }
-
- // Check each role included in this constraint
- Realm realm = context.getRealm();
- String roles[] = constraint.findAuthRoles();
- if (roles == null)
- roles = new String[0];
- if (roles.length == 0) {
+ ((HttpServletResponse) response.getResponse()).sendError
+ (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ sm.getString("authenticator.notAuthenticated"));
+ return (false);
+ }
+
+ // Check each role included in this constraint
+ Realm realm = context.getRealm();
+ String roles[] = constraint.findAuthRoles();
+ if (roles == null)
+ roles = new String[0];
+ if (roles.length == 0) {
if (constraint.getAuthConstraint() &&
!constraint.getAllRoles()) {
((HttpServletResponse) response.getResponse()).sendError
@@ -592,18 +592,18 @@
sm.getString("authenticator.forbidden"));
return (false); // No listed roles means no access at all
} else
- return (true); // Authenticated user is sufficient
+ return (true); // Authenticated user is sufficient
}
- for (int i = 0; i < roles.length; i++) {
- if (realm.hasRole(principal, roles[i]))
- return (true);
- }
-
- // Return a "Forbidden" message denying access to this resource
- ((HttpServletResponse) response.getResponse()).sendError
- (HttpServletResponse.SC_FORBIDDEN,
- sm.getString("authenticator.forbidden"));
- return (false);
+ for (int i = 0; i < roles.length; i++) {
+ if (realm.hasRole(principal, roles[i]))
+ return (true);
+ }
+
+ // Return a "Forbidden" message denying access to this resource
+ ((HttpServletResponse) response.getResponse()).sendError
+ (HttpServletResponse.SC_FORBIDDEN,
+ sm.getString("authenticator.forbidden"));
+ return (false);
}
@@ -622,9 +622,9 @@
* @exception IOException if an input/output error occurs
*/
protected abstract boolean authenticate(HttpRequest request,
- HttpResponse response,
- LoginConfig config)
- throws IOException;
+ HttpResponse response,
+ LoginConfig config)
+ throws IOException;
/**
@@ -640,30 +640,30 @@
* @exception IOException if an input/output error occurs
*/
protected boolean checkUserData(HttpRequest request,
- HttpResponse response,
- SecurityConstraint constraint)
- throws IOException {
+ HttpResponse response,
+ SecurityConstraint constraint)
+ throws IOException {
- // Is there a relevant user data constraint?
- if (constraint == null) {
+ // Is there a relevant user data constraint?
+ if (constraint == null) {
if (debug >= 2)
- log(" No applicable security constraint defined");
- return (true);
+ log(" No applicable security constraint defined");
+ return (true);
}
- String userConstraint = constraint.getUserConstraint();
- if (userConstraint == null) {
+ String userConstraint = constraint.getUserConstraint();
+ if (userConstraint == null) {
if (debug >= 2)
- log(" No applicable user data constraint defined");
- return (true);
+ log(" No applicable user data constraint defined");
+ return (true);
}
- if (userConstraint.equals(Constants.NONE_TRANSPORT)) {
+ if (userConstraint.equals(Constants.NONE_TRANSPORT)) {
if (debug >= 2)
log(" User data constraint has no restrictions");
- return (true);
+ return (true);
}
- // Validate the request against the user data constraint
- if (request.getRequest().isSecure()) {
+ // Validate the request against the user data constraint
+ if (request.getRequest().isSecure()) {
if (debug >= 2)
log(" User data constraint already satisfied");
return (true);
@@ -728,36 +728,36 @@
*/
protected SecurityConstraint findConstraint(HttpRequest request) {
- // Are there any defined security constraints?
- SecurityConstraint constraints[] = context.findConstraints();
- if ((constraints == null) || (constraints.length == 0)) {
- if (debug >= 2)
- log(" No applicable constraints defined");
- return (null);
- }
-
- // Check each defined security constraint
- HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
- String uri = hreq.getRequestURI();
- String contextPath = hreq.getContextPath();
- if (contextPath.length() > 0)
- uri = uri.substring(contextPath.length());
+ // Are there any defined security constraints?
+ SecurityConstraint constraints[] = context.findConstraints();
+ if ((constraints == null) || (constraints.length == 0)) {
+ if (debug >= 2)
+ log(" No applicable constraints defined");
+ return (null);
+ }
+
+ // Check each defined security constraint
+ HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
+ String uri = hreq.getRequestURI();
+ String contextPath = hreq.getContextPath();
+ if (contextPath.length() > 0)
+ uri = uri.substring(contextPath.length());
uri = RequestUtil.URLDecode(uri); // Before checking constraints
- String method = hreq.getMethod();
- for (int i = 0; i < constraints.length; i++) {
- if (debug >= 2)
- log(" Checking constraint '" + constraints[i] +
- "' against " + method + " " + uri + " --> " +
- constraints[i].included(uri, method));
- if (constraints[i].included(uri, method))
- return (constraints[i]);
- }
-
- // No applicable security constraint was found
- if (debug >= 2)
- log(" No applicable constraint located");
- return (null);
+ String method = hreq.getMethod();
+ for (int i = 0; i < constraints.length; i++) {
+ if (debug >= 2)
+ log(" Checking constraint '" + constraints[i] +
+ "' against " + method + " " + uri + " --> " +
+ constraints[i].included(uri, method));
+ if (constraints[i].included(uri, method))
+ return (constraints[i]);
+ }
+ // No applicable security constraint was found
+ if (debug >= 2)
+ log(" No applicable constraint located");
+ return (null);
+
}
@@ -767,27 +767,27 @@
*/
protected synchronized String generateSessionId() {
- // Generate a byte array containing a session identifier
- Random random = getRandom();
- byte bytes[] = new byte[SESSION_ID_BYTES];
- getRandom().nextBytes(bytes);
- bytes = getDigest().digest(bytes);
-
- // Render the result as a String of hexadecimal digits
- StringBuffer result = new StringBuffer();
- for (int i = 0; i < bytes.length; i++) {
- byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
- byte b2 = (byte) (bytes[i] & 0x0f);
- if (b1 < 10)
- result.append((char) ('0' + b1));
- else
- result.append((char) ('A' + (b1 - 10)));
- if (b2 < 10)
- result.append((char) ('0' + b2));
- else
- result.append((char) ('0' + (b2 - 10)));
- }
- return (result.toString());
+ // Generate a byte array containing a session identifier
+ Random random = getRandom();
+ byte bytes[] = new byte[SESSION_ID_BYTES];
+ getRandom().nextBytes(bytes);
+ bytes = getDigest().digest(bytes);
+
+ // Render the result as a String of hexadecimal digits
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < bytes.length; i++) {
+ byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
+ byte b2 = (byte) (bytes[i] & 0x0f);
+ if (b1 < 10)
+ result.append((char) ('0' + b1));
+ else
+ result.append((char) ('A' + (b1 - 10)));
+ if (b2 < 10)
+ result.append((char) ('0' + b2));
+ else
+ result.append((char) ('0' + (b2 - 10)));
+ }
+ return (result.toString());
}
@@ -799,19 +799,19 @@
*/
protected synchronized MessageDigest getDigest() {
- if (this.digest == null) {
- try {
- this.digest = MessageDigest.getInstance(algorithm);
- } catch (NoSuchAlgorithmException e) {
- try {
- this.digest = MessageDigest.getInstance(DEFAULT_ALGORITHM);
- } catch (NoSuchAlgorithmException f) {
- this.digest = null;
- }
- }
- }
+ if (this.digest == null) {
+ try {
+ this.digest = MessageDigest.getInstance(algorithm);
+ } catch (NoSuchAlgorithmException e) {
+ try {
+ this.digest = MessageDigest.getInstance(DEFAULT_ALGORITHM);
+ } catch (NoSuchAlgorithmException f) {
+ this.digest = null;
+ }
+ }
+ }
- return (this.digest);
+ return (this.digest);
}
@@ -823,22 +823,22 @@
*/
protected synchronized Random getRandom() {
- if (this.random == null) {
- try {
- Class clazz = Class.forName(randomClass);
- this.random = (Random) clazz.newInstance();
- long seed = System.currentTimeMillis();
- char entropy[] = getEntropy().toCharArray();
- for (int i = 0; i < entropy.length; i++) {
- long update = ((byte) entropy[i]) << ((i % 8) * 8);
- seed ^= update;
- }
- } catch (Exception e) {
- this.random = new java.util.Random();
- }
- }
+ if (this.random == null) {
+ try {
+ Class clazz = Class.forName(randomClass);
+ this.random = (Random) clazz.newInstance();
+ long seed = System.currentTimeMillis();
+ char entropy[] = getEntropy().toCharArray();
+ for (int i = 0; i < entropy.length; i++) {
+ long update = ((byte) entropy[i]) << ((i % 8) * 8);
+ seed ^= update;
+ }
+ } catch (Exception e) {
+ this.random = new java.util.Random();
+ }
+ }
- return (this.random);
+ return (this.random);
}
@@ -851,7 +851,7 @@
*/
protected Session getSession(HttpRequest request) {
- return (getSession(request, false));
+ return (getSession(request, false));
}
@@ -866,21 +866,21 @@
*/
protected Session getSession(HttpRequest request, boolean create) {
- HttpServletRequest hreq =
- (HttpServletRequest) request.getRequest();
- HttpSession hses = hreq.getSession(create);
- 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);
- }
- }
+ HttpServletRequest hreq =
+ (HttpServletRequest) request.getRequest();
+ HttpSession hses = hreq.getSession(create);
+ 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);
+ }
+ }
}
@@ -892,13 +892,13 @@
*/
protected void log(String message) {
- Logger logger = context.getLogger();
- if (logger != null)
- logger.log("Authenticator[" + context.getPath() + "]: " +
- message);
- else
- System.out.println("Authenticator[" + context.getPath() +
- "]: " + message);
+ Logger logger = context.getLogger();
+ if (logger != null)
+ logger.log("Authenticator[" + context.getPath() + "]: " +
+ message);
+ else
+ System.out.println("Authenticator[" + context.getPath() +
+ "]: " + message);
}
@@ -911,15 +911,15 @@
*/
protected void log(String message, Throwable throwable) {
- Logger logger = context.getLogger();
- if (logger != null)
- logger.log("Authenticator[" + context.getPath() + "]: " +
- message, throwable);
- else {
- System.out.println("Authenticator[" + context.getPath() +
+ Logger logger = context.getLogger();
+ if (logger != null)
+ logger.log("Authenticator[" + context.getPath() + "]: " +
+ message, throwable);
+ else {
+ System.out.println("Authenticator[" + context.getPath() +
"]: " + message);
- throwable.printStackTrace(System.out);
- }
+ throwable.printStackTrace(System.out);
+ }
}
@@ -984,7 +984,7 @@
*/
public void addLifecycleListener(LifecycleListener listener) {
- lifecycle.addLifecycleListener(listener);
+ lifecycle.addLifecycleListener(listener);
}
@@ -996,7 +996,7 @@
*/
public void removeLifecycleListener(LifecycleListener listener) {
- lifecycle.removeLifecycleListener(listener);
+ lifecycle.removeLifecycleListener(listener);
}
@@ -1013,14 +1013,14 @@
*/
public void start() throws LifecycleException {
- // Validate and update our current component state
- if (started)
- throw new LifecycleException
- (sm.getString("authenticator.alreadyStarted"));
- lifecycle.fireLifecycleEvent(START_EVENT, null);
+ // Validate and update our current component state
+ if (started)
+ throw new LifecycleException
+ (sm.getString("authenticator.alreadyStarted"));
+ lifecycle.fireLifecycleEvent(START_EVENT, null);
if (context instanceof StandardContext)
setDebug(((StandardContext) context).getDebug());
- started = true;
+ started = true;
// Look up the SingleSignOn implementation in our request processing
// path, if there is one
@@ -1061,12 +1061,12 @@
*/
public void stop() throws LifecycleException {
- // Validate and update our current component state
- if (!started)
- throw new LifecycleException
- (sm.getString("authenticator.notStarted"));
- lifecycle.fireLifecycleEvent(STOP_EVENT, null);
- started = false;
+ // Validate and update our current component state
+ if (!started)
+ throw new LifecycleException
+ (sm.getString("authenticator.notStarted"));
+ lifecycle.fireLifecycleEvent(STOP_EVENT, null);
+ started = false;
sso = null;
1.8 +53 -53 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/BasicAuthenticator.java
Index: BasicAuthenticator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/BasicAuthenticator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BasicAuthenticator.java 2001/03/06 05:08:16 1.7
+++ BasicAuthenticator.java 2001/07/22 19:20:11 1.8
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/BasicAuthenticator.java,v 1.7 2001/03/06 05:08:16 remm Exp $
- * $Revision: 1.7 $
- * $Date: 2001/03/06 05:08:16 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/BasicAuthenticator.java,v 1.8 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.8 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -84,7 +84,7 @@
* and Digest Access Authentication."
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2001/03/06 05:08:16 $
+ * @version $Revision: 1.8 $ $Date: 2001/07/22 19:20:11 $
*/
public final class BasicAuthenticator
@@ -104,7 +104,7 @@
* Descriptive information about this implementation.
*/
private static final String info =
- "org.apache.catalina.authenticator.BasicAuthenticator/1.0";
+ "org.apache.catalina.authenticator.BasicAuthenticator/1.0";
// ------------------------------------------------------------- Properties
@@ -115,7 +115,7 @@
*/
public String getInfo() {
- return (this.info);
+ return (this.info);
}
@@ -137,44 +137,44 @@
* @exception IOException if an input/output error occurs
*/
public boolean authenticate(HttpRequest request,
- HttpResponse response,
- LoginConfig config)
- throws IOException {
-
- // Have we already authenticated someone?
- Principal principal =
- ((HttpServletRequest) request.getRequest()).getUserPrincipal();
- if (principal != null) {
+ HttpResponse response,
+ LoginConfig config)
+ throws IOException {
+
+ // Have we already authenticated someone?
+ Principal principal =
+ ((HttpServletRequest) request.getRequest()).getUserPrincipal();
+ if (principal != null) {
if (debug >= 1)
log("Already authenticated '" + principal.getName() + "'");
- return (true);
+ return (true);
}
- // Validate any credentials already included with this request
- HttpServletRequest hreq =
- (HttpServletRequest) request.getRequest();
- HttpServletResponse hres =
- (HttpServletResponse) response.getResponse();
- String authorization = request.getAuthorization();
- if (authorization != null) {
- principal = findPrincipal(authorization, context.getRealm());
- if (principal != null) {
+ // Validate any credentials already included with this request
+ HttpServletRequest hreq =
+ (HttpServletRequest) request.getRequest();
+ HttpServletResponse hres =
+ (HttpServletResponse) response.getResponse();
+ String authorization = request.getAuthorization();
+ if (authorization != null) {
+ principal = findPrincipal(authorization, context.getRealm());
+ if (principal != null) {
register(request, response, principal, Constants.BASIC_METHOD);
- return (true);
- }
- }
-
- // Send an "unauthorized" response and an appropriate challenge
- String realmName = config.getRealmName();
- if (realmName == null)
- realmName = hreq.getServerName() + ":" + hreq.getServerPort();
+ return (true);
+ }
+ }
+
+ // Send an "unauthorized" response and an appropriate challenge
+ String realmName = config.getRealmName();
+ if (realmName == null)
+ realmName = hreq.getServerName() + ":" + hreq.getServerPort();
// if (debug >= 1)
// log("Challenging for realm '" + realmName + "'");
- hres.setHeader("WWW-Authenticate",
+ hres.setHeader("WWW-Authenticate",
"Basic realm=\"" + realmName + "\"");
- hres.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
- // hres.flushBuffer();
- return (false);
+ hres.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ // hres.flushBuffer();
+ return (false);
}
@@ -193,24 +193,24 @@
*/
private static Principal findPrincipal(String authorization, Realm realm) {
- // Validate the authorization credentials format
- if (authorization == null)
- return (null);
- if (!authorization.startsWith("Basic "))
- return (null);
- authorization = authorization.substring(6).trim();
-
- // Decode and parse the authorization credentials
- String unencoded =
- new String(base64Helper.decode(authorization.getBytes()));
- int colon = unencoded.indexOf(':');
- if (colon < 0)
- return (null);
- String username = unencoded.substring(0, colon).trim();
- String password = unencoded.substring(colon + 1).trim();
+ // Validate the authorization credentials format
+ if (authorization == null)
+ return (null);
+ if (!authorization.startsWith("Basic "))
+ return (null);
+ authorization = authorization.substring(6).trim();
+
+ // Decode and parse the authorization credentials
+ String unencoded =
+ new String(base64Helper.decode(authorization.getBytes()));
+ int colon = unencoded.indexOf(':');
+ if (colon < 0)
+ return (null);
+ String username = unencoded.substring(0, colon).trim();
+ String password = unencoded.substring(colon + 1).trim();
- // Validate these credentials in our associated realm
- return (realm.authenticate(username, password));
+ // Validate these credentials in our associated realm
+ return (realm.authenticate(username, password));
}
1.4 +10 -10 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/Constants.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Constants.java 2001/07/11 23:39:49 1.3
+++ Constants.java 2001/07/22 19:20:11 1.4
@@ -1,13 +1,13 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/Constants.java,v 1.3 2001/07/11 23:39:49 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/07/11 23:39:49 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/Constants.java,v 1.4 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -15,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -23,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -59,7 +59,7 @@
*
* [Additional notices, if required by prior licensing conditions]
*
- */
+ */
package org.apache.catalina.authenticator;
@@ -83,7 +83,7 @@
// Form based authentication constants
public static final String FORM_ACTION = "/j_security_check";
public static final String FORM_KEY =
- "org.apache.catalina.security.REQUEST";
+ "org.apache.catalina.security.REQUEST";
public static final String FORM_PASSWORD = "j_password";
public static final String FORM_PRINCIPAL =
"org.apache.catalina.security.PRINCIPAL";
1.7 +77 -77 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/DigestAuthenticator.java
Index: DigestAuthenticator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/DigestAuthenticator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DigestAuthenticator.java 2001/03/06 05:08:16 1.6
+++ DigestAuthenticator.java 2001/07/22 19:20:11 1.7
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/DigestAuthenticator.java,v 1.6 2001/03/06 05:08:16 remm Exp $
- * $Revision: 1.6 $
- * $Date: 2001/03/06 05:08:16 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/DigestAuthenticator.java,v 1.7 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.7 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -85,10 +85,10 @@
/**
* An <b>Authenticator</b> and <b>Valve</b> implementation of HTTP DIGEST
* Authentication (see RFC 2069).
- *
+ *
* @author Craig R. McClanahan
* @author Remy Maucherat
- * @version $Revision: 1.6 $ $Date: 2001/03/06 05:08:16 $
+ * @version $Revision: 1.7 $ $Date: 2001/07/22 19:20:11 $
*/
public final class DigestAuthenticator
@@ -126,7 +126,7 @@
* Descriptive information about this implementation.
*/
private static final String info =
- "org.apache.catalina.authenticator.DigestAuthenticator/1.0";
+ "org.apache.catalina.authenticator.DigestAuthenticator/1.0";
// ----------------------------------------------------------- Constructors
@@ -160,7 +160,7 @@
/**
- * No once expiration (in millisecond). A shorter amount would mean a
+ * No once expiration (in millisecond). A shorter amount would mean a
* better security level (since the token is generated more often), but at
* the expense of a bigger server overhead.
*/
@@ -189,7 +189,7 @@
*/
public String getInfo() {
- return (this.info);
+ return (this.info);
}
@@ -211,42 +211,42 @@
* @exception IOException if an input/output error occurs
*/
public boolean authenticate(HttpRequest request,
- HttpResponse response,
- LoginConfig config)
- throws IOException {
-
- // Have we already authenticated someone?
- Principal principal =
- ((HttpServletRequest) request.getRequest()).getUserPrincipal();
- if (principal != null)
- return (true);
-
- // Validate any credentials already included with this request
- HttpServletRequest hreq =
- (HttpServletRequest) request.getRequest();
- HttpServletResponse hres =
- (HttpServletResponse) response.getResponse();
- String authorization = request.getAuthorization();
- if (authorization != null) {
- principal = findPrincipal(hreq, authorization, context.getRealm());
- if (principal != null) {
+ HttpResponse response,
+ LoginConfig config)
+ throws IOException {
+
+ // Have we already authenticated someone?
+ Principal principal =
+ ((HttpServletRequest) request.getRequest()).getUserPrincipal();
+ if (principal != null)
+ return (true);
+
+ // Validate any credentials already included with this request
+ HttpServletRequest hreq =
+ (HttpServletRequest) request.getRequest();
+ HttpServletResponse hres =
+ (HttpServletResponse) response.getResponse();
+ String authorization = request.getAuthorization();
+ if (authorization != null) {
+ principal = findPrincipal(hreq, authorization, context.getRealm());
+ if (principal != null) {
register(request, response, principal,
Constants.DIGEST_METHOD);
- return (true);
- }
- }
+ return (true);
+ }
+ }
+
+ // Send an "unauthorized" response and an appropriate challenge
- // Send an "unauthorized" response and an appropriate challenge
-
// Next, generate a nOnce token (that is a token which is supposed
// to be unique).
String nOnce = generateNOnce(hreq);
-
- setAuthenticateHeader(hreq, hres, config, nOnce);
- hres.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
- // hres.flushBuffer();
- return (false);
+ setAuthenticateHeader(hreq, hres, config, nOnce);
+ hres.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ // hres.flushBuffer();
+ return (false);
+
}
@@ -265,21 +265,21 @@
* should be performed
* @param realm Realm used to authenticate Principals
*/
- private static Principal findPrincipal(HttpServletRequest request,
+ private static Principal findPrincipal(HttpServletRequest request,
String authorization, Realm realm) {
//System.out.println("Authorization token : " + authorization);
- // Validate the authorization credentials format
- if (authorization == null)
- return (null);
- if (!authorization.startsWith("Digest "))
- return (null);
- authorization = authorization.substring(7).trim();
-
-
- StringTokenizer commaTokenizer =
+ // Validate the authorization credentials format
+ if (authorization == null)
+ return (null);
+ if (!authorization.startsWith("Digest "))
+ return (null);
+ authorization = authorization.substring(7).trim();
+
+
+ StringTokenizer commaTokenizer =
new StringTokenizer(authorization, ",");
-
+
String userName = null;
String realmName = null;
String nOnce = null;
@@ -290,15 +290,15 @@
String response = null;
String opaque = null;
String method = request.getMethod();
-
+
while (commaTokenizer.hasMoreTokens()) {
String currentToken = commaTokenizer.nextToken();
int equalSign = currentToken.indexOf('=');
if (equalSign < 0)
return null;
- String currentTokenName =
+ String currentTokenName =
currentToken.substring(0, equalSign).trim();
- String currentTokenValue =
+ String currentTokenValue =
currentToken.substring(equalSign + 1).trim();
if ("username".equals(currentTokenName))
userName = removeQuotes(currentTokenValue);
@@ -317,21 +317,21 @@
if ("response".equals(currentTokenName))
response = removeQuotes(currentTokenValue);
}
-
+
if ( (userName == null) || (realmName == null) || (nOnce == null)
|| (uri == null) || (response == null) )
return null;
-
- // Second MD5 digest used to calculate the digest :
+
+ // Second MD5 digest used to calculate the digest :
// MD5(Method + ":" + uri)
String a2 = method + ":" + uri;
//System.out.println("A2:" + a2);
-
+
String md5a2 = md5Encoder.encode(md5Helper.digest(a2.getBytes()));
-
+
return (realm.authenticate(userName, response, nOnce, nc, cnonce, qop,
realmName, md5a2));
-
+
}
@@ -348,24 +348,24 @@
/**
- * Generate a unique token. The token is generated according to the
- * following pattern. NOnceToken = Base64 ( MD5 ( client-IP ":"
+ * Generate a unique token. The token is generated according to the
+ * following pattern. NOnceToken = Base64 ( MD5 ( client-IP ":"
* time-stamp ":" private-key ) ).
- *
+ *
* @param request HTTP Servlet request
*/
private String generateNOnce(HttpServletRequest request) {
long currentTime = System.currentTimeMillis();
-
- String nOnceValue = request.getRemoteAddr() + ":" +
+
+ String nOnceValue = request.getRemoteAddr() + ":" +
currentTime + ":" + key;
-
+
byte[] buffer = md5Helper.digest(nOnceValue.getBytes());
nOnceValue = md5Encoder.encode(buffer);
-
+
// Updating the value in the no once hashtable
nOnceTokens.put(nOnceValue, new Long(currentTime + nOnceTimeout));
-
+
return nOnceValue;
}
@@ -377,10 +377,10 @@
* <pre>
* WWW-Authenticate = "WWW-Authenticate" ":" "Digest"
* digest-challenge
- *
+ *
* digest-challenge = 1#( realm | [ domain ] | nOnce |
* [ digest-opaque ] |[ stale ] | [ algorithm ] )
- *
+ *
* realm = "realm" "=" realm-value
* realm-value = quoted-string
* domain = "domain" "=" <"> 1#URI <">
@@ -390,7 +390,7 @@
* stale = "stale" "=" ( "true" | "false" )
* algorithm = "algorithm" "=" ( "MD5" | token )
* </pre>
- *
+ *
* @param request HTTP Servlet request
* @param resonse HTTP Servlet response
* @param login Login configuration describing how authentication
@@ -401,22 +401,22 @@
HttpServletResponse response,
LoginConfig config,
String nOnce) {
-
+
// Get the realm name
- String realmName = config.getRealmName();
- if (realmName == null)
- realmName = request.getServerName() + ":"
+ String realmName = config.getRealmName();
+ if (realmName == null)
+ realmName = request.getServerName() + ":"
+ request.getServerPort();
-
+
byte[] buffer = md5Helper.digest(nOnce.getBytes());
-
+
String authenticateHeader = "Digest realm=\"" + realmName + "\", "
- + "qop=\"auth\", nonce=\"" + nOnce + "\", " + "opaque=\""
+ + "qop=\"auth\", nonce=\"" + nOnce + "\", " + "opaque=\""
+ md5Encoder.encode(buffer) + "\"";
- // System.out.println("Authenticate header value : "
+ // System.out.println("Authenticate header value : "
// + authenticateHeader);
response.setHeader("WWW-Authenticate", authenticateHeader);
-
+
}
1.10 +122 -122 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/FormAuthenticator.java
Index: FormAuthenticator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/FormAuthenticator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FormAuthenticator.java 2001/07/12 00:00:16 1.9
+++ FormAuthenticator.java 2001/07/22 19:20:11 1.10
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/FormAuthenticator.java,v 1.9 2001/07/12 00:00:16 craigmcc Exp $
- * $Revision: 1.9 $
- * $Date: 2001/07/12 00:00:16 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/FormAuthenticator.java,v 1.10 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.10 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -88,7 +88,7 @@
* Authentication, as described in the Servlet API Specification, Version 2.2.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2001/07/12 00:00:16 $
+ * @version $Revision: 1.10 $ $Date: 2001/07/22 19:20:11 $
*/
public final class FormAuthenticator
@@ -102,7 +102,7 @@
* Descriptive information about this implementation.
*/
private static final String info =
- "org.apache.catalina.authenticator.FormAuthenticator/1.0";
+ "org.apache.catalina.authenticator.FormAuthenticator/1.0";
// ------------------------------------------------------------- Properties
@@ -113,7 +113,7 @@
*/
public String getInfo() {
- return (this.info);
+ return (this.info);
}
@@ -135,9 +135,9 @@
* @exception IOException if an input/output error occurs
*/
public boolean authenticate(HttpRequest request,
- HttpResponse response,
- LoginConfig config)
- throws IOException {
+ HttpResponse response,
+ LoginConfig config)
+ throws IOException {
// References to objects we will need later
HttpServletRequest hreq =
@@ -146,13 +146,13 @@
(HttpServletResponse) response.getResponse();
Session session = null;
- // Have we already authenticated someone?
- Principal principal = hreq.getUserPrincipal();
- if (principal != null) {
+ // Have we already authenticated someone?
+ Principal principal = hreq.getUserPrincipal();
+ if (principal != null) {
if (debug >= 1)
log("Already authenticated '" +
principal.getName() + "'");
- return (true);
+ return (true);
}
// Is this the re-submit of the original request URI after successful
@@ -176,52 +176,52 @@
}
}
- // Acquire references to objects we will need to evaluate
- String contextPath = hreq.getContextPath();
- String requestURI = hreq.getRequestURI();
- response.setContext(request.getContext());
-
- // Is this a request for the login page itself? Test here to avoid
- // displaying it twice (from the user's perspective) -- once because
- // of the "save and redirect" and once because of the "restore and
- // redirect" performed below.
+ // Acquire references to objects we will need to evaluate
+ String contextPath = hreq.getContextPath();
+ String requestURI = hreq.getRequestURI();
+ response.setContext(request.getContext());
+
+ // Is this a request for the login page itself? Test here to avoid
+ // displaying it twice (from the user's perspective) -- once because
+ // of the "save and redirect" and once because of the "restore and
+ // redirect" performed below.
String loginURI = contextPath + config.getLoginPage();
- if (requestURI.equals(loginURI)) {
+ if (requestURI.equals(loginURI)) {
if (debug >= 1)
log("Requesting login page normally");
- return (true); // Display the login page in the usual manner
+ return (true); // Display the login page in the usual manner
}
- // Is this the action request from the login page?
- boolean loginAction =
- requestURI.startsWith(contextPath) &&
- requestURI.endsWith(Constants.FORM_ACTION);
-
- // No -- Save this request and redirect to the form login page
- if (!loginAction) {
- session = getSession(request, true);
+ // Is this the action request from the login page?
+ boolean loginAction =
+ requestURI.startsWith(contextPath) &&
+ requestURI.endsWith(Constants.FORM_ACTION);
+
+ // No -- Save this request and redirect to the form login page
+ if (!loginAction) {
+ session = getSession(request, true);
if (debug >= 1)
log("Save request in session '" + session.getId() + "'");
- saveRequest(request, session);
+ saveRequest(request, session);
if (debug >= 1)
log("Redirect to login page '" + loginURI + "'");
hres.sendRedirect(hres.encodeRedirectURL(loginURI));
return (false);
- }
+ }
- // Yes -- Validate the specified credentials and redirect
- // to the error page if they are not correct
- Realm realm = context.getRealm();
- String username = hreq.getParameter(Constants.FORM_USERNAME);
- String password = hreq.getParameter(Constants.FORM_PASSWORD);
- principal = realm.authenticate(username, password);
- if (principal == null) {
+ // Yes -- Validate the specified credentials and redirect
+ // to the error page if they are not correct
+ Realm realm = context.getRealm();
+ String username = hreq.getParameter(Constants.FORM_USERNAME);
+ String password = hreq.getParameter(Constants.FORM_PASSWORD);
+ principal = realm.authenticate(username, password);
+ if (principal == null) {
String errorURI = contextPath + config.getErrorPage();
if (debug >= 1)
log("Redirect to error page '" + errorURI + "'");
hres.sendRedirect(hres.encodeRedirectURL(errorURI));
return (false);
- }
+ }
// Save the authenticated Principal in our session
if (session == null)
@@ -236,23 +236,23 @@
hres.sendRedirect(hres.encodeRedirectURL(requestURI));
return (false);
- // Restore this request and redirect to the original request URI
+ // Restore this request and redirect to the original request URI
/*
session = getSession(request, true);
if (debug >= 1)
log("restore request from session '" + session.getId() + "'");
register(request, response, principal, Constants.FORM_METHOD);
- if (restoreRequest(request, session)) {
+ if (restoreRequest(request, session)) {
if (debug >= 1)
log("Proceed to restored request");
- return (true); // Perform the original request
- } else {
+ return (true); // Perform the original request
+ } else {
if (debug >= 1)
log("Restore of original request failed");
- hres.sendError(HttpServletResponse.SC_BAD_REQUEST);
- // hres.flushBuffer();
- return (false);
- }
+ hres.sendError(HttpServletResponse.SC_BAD_REQUEST);
+ // hres.flushBuffer();
+ return (false);
+ }
*/
}
@@ -305,46 +305,46 @@
*/
private boolean restoreRequest(HttpRequest request, Session session) {
- // Retrieve and remove the SavedRequest object from our session
- SavedRequest saved = (SavedRequest)
- session.getSession().getAttribute(Constants.FORM_KEY);
- session.getSession().removeAttribute(Constants.FORM_KEY);
+ // Retrieve and remove the SavedRequest object from our session
+ SavedRequest saved = (SavedRequest)
+ session.getSession().getAttribute(Constants.FORM_KEY);
+ session.getSession().removeAttribute(Constants.FORM_KEY);
session.getSession().removeAttribute(Constants.FORM_PRINCIPAL);
- if (saved == null)
- return (false);
+ if (saved == null)
+ return (false);
- // Modify our current request to reflect the original one
- request.clearCookies();
- Iterator cookies = saved.getCookies();
- while (cookies.hasNext()) {
- request.addCookie((Cookie) cookies.next());
- }
- request.clearHeaders();
- Iterator names = saved.getHeaderNames();
- while (names.hasNext()) {
- String name = (String) names.next();
- Iterator values = saved.getHeaderValues(name);
- while (values.hasNext()) {
- request.addHeader(name, (String) values.next());
- }
- }
- request.clearLocales();
- Iterator locales = saved.getLocales();
- while (locales.hasNext()) {
- request.addLocale((Locale) locales.next());
- }
- request.clearParameters();
- Iterator paramNames = saved.getParameterNames();
- while (paramNames.hasNext()) {
- String paramName = (String) paramNames.next();
- String paramValues[] =
- (String[]) saved.getParameterValues(paramName);
- request.addParameter(paramName, paramValues);
- }
- request.setMethod(saved.getMethod());
- request.setQueryString(saved.getQueryString());
- request.setRequestURI(saved.getRequestURI());
- return (true);
+ // Modify our current request to reflect the original one
+ request.clearCookies();
+ Iterator cookies = saved.getCookies();
+ while (cookies.hasNext()) {
+ request.addCookie((Cookie) cookies.next());
+ }
+ request.clearHeaders();
+ Iterator names = saved.getHeaderNames();
+ while (names.hasNext()) {
+ String name = (String) names.next();
+ Iterator values = saved.getHeaderValues(name);
+ while (values.hasNext()) {
+ request.addHeader(name, (String) values.next());
+ }
+ }
+ request.clearLocales();
+ Iterator locales = saved.getLocales();
+ while (locales.hasNext()) {
+ request.addLocale((Locale) locales.next());
+ }
+ request.clearParameters();
+ Iterator paramNames = saved.getParameterNames();
+ while (paramNames.hasNext()) {
+ String paramName = (String) paramNames.next();
+ String paramValues[] =
+ (String[]) saved.getParameterValues(paramName);
+ request.addParameter(paramName, paramValues);
+ }
+ request.setMethod(saved.getMethod());
+ request.setQueryString(saved.getQueryString());
+ request.setRequestURI(saved.getRequestURI());
+ return (true);
}
@@ -357,41 +357,41 @@
*/
private void saveRequest(HttpRequest request, Session session) {
- // Create and populate a SavedRequest object for this request
- HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
- SavedRequest saved = new SavedRequest();
- Cookie cookies[] = hreq.getCookies();
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++)
- saved.addCookie(cookies[i]);
- }
- Enumeration names = hreq.getHeaderNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- Enumeration values = hreq.getHeaders(name);
- while (values.hasMoreElements()) {
- String value = (String) values.nextElement();
- saved.addHeader(name, value);
- }
- }
- Enumeration locales = hreq.getLocales();
- while (locales.hasMoreElements()) {
- Locale locale = (Locale) locales.nextElement();
- saved.addLocale(locale);
- }
- Map parameters = hreq.getParameterMap();
- Iterator paramNames = parameters.keySet().iterator();
- while (paramNames.hasNext()) {
- String paramName = (String) paramNames.next();
- String paramValues[] = (String[]) parameters.get(paramName);
- saved.addParameter(paramName, paramValues);
- }
- saved.setMethod(hreq.getMethod());
- saved.setQueryString(hreq.getQueryString());
- saved.setRequestURI(hreq.getRequestURI());
+ // Create and populate a SavedRequest object for this request
+ HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
+ SavedRequest saved = new SavedRequest();
+ Cookie cookies[] = hreq.getCookies();
+ if (cookies != null) {
+ for (int i = 0; i < cookies.length; i++)
+ saved.addCookie(cookies[i]);
+ }
+ Enumeration names = hreq.getHeaderNames();
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+ Enumeration values = hreq.getHeaders(name);
+ while (values.hasMoreElements()) {
+ String value = (String) values.nextElement();
+ saved.addHeader(name, value);
+ }
+ }
+ Enumeration locales = hreq.getLocales();
+ while (locales.hasMoreElements()) {
+ Locale locale = (Locale) locales.nextElement();
+ saved.addLocale(locale);
+ }
+ Map parameters = hreq.getParameterMap();
+ Iterator paramNames = parameters.keySet().iterator();
+ while (paramNames.hasNext()) {
+ String paramName = (String) paramNames.next();
+ String paramValues[] = (String[]) parameters.get(paramName);
+ saved.addParameter(paramName, paramValues);
+ }
+ saved.setMethod(hreq.getMethod());
+ saved.setQueryString(hreq.getQueryString());
+ saved.setRequestURI(hreq.getRequestURI());
- // Stash the SavedRequest in our session for later use
- session.getSession().setAttribute(Constants.FORM_KEY, saved);
+ // Stash the SavedRequest in our session for later use
+ session.getSession().setAttribute(Constants.FORM_KEY, saved);
}
1.2 +9 -9 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/NonLoginAuthenticator.java
Index: NonLoginAuthenticator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/NonLoginAuthenticator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NonLoginAuthenticator.java 2001/05/08 21:22:29 1.1
+++ NonLoginAuthenticator.java 2001/07/22 19:20:11 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/NonLoginAuthenticator.java,v 1.1 2001/05/08 21:22:29 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/05/08 21:22:29 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/NonLoginAuthenticator.java,v 1.2 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -82,7 +82,7 @@
* only security constraints not involving user authentication.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/05/08 21:22:29 $
+ * @version $Revision: 1.2 $ $Date: 2001/07/22 19:20:11 $
*/
public final class NonLoginAuthenticator
@@ -96,7 +96,7 @@
* Descriptive information about this implementation.
*/
private static final String info =
- "org.apache.catalina.authenticator.NonLoginAuthenticator/1.0";
+ "org.apache.catalina.authenticator.NonLoginAuthenticator/1.0";
// ------------------------------------------------------------- Properties
@@ -107,7 +107,7 @@
*/
public String getInfo() {
- return (this.info);
+ return (this.info);
}
@@ -129,9 +129,9 @@
* @exception IOException if an input/output error occurs
*/
public boolean authenticate(HttpRequest request,
- HttpResponse response,
- LoginConfig config)
- throws IOException {
+ HttpResponse response,
+ LoginConfig config)
+ throws IOException {
if (debug >= 1)
log("User authentication is not required");
1.6 +15 -15 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SSLAuthenticator.java
Index: SSLAuthenticator.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SSLAuthenticator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SSLAuthenticator.java 2000/12/16 01:42:47 1.5
+++ SSLAuthenticator.java 2001/07/22 19:20:11 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SSLAuthenticator.java,v 1.5 2000/12/16 01:42:47 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2000/12/16 01:42:47 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SSLAuthenticator.java,v 1.6 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -86,7 +86,7 @@
* that utilizes SSL certificates to identify client users.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2000/12/16 01:42:47 $
+ * @version $Revision: 1.6 $ $Date: 2001/07/22 19:20:11 $
*/
public final class SSLAuthenticator
@@ -100,7 +100,7 @@
* Descriptive information about this implementation.
*/
private static final String info =
- "org.apache.catalina.authenticator.SSLAuthenticator/1.0";
+ "org.apache.catalina.authenticator.SSLAuthenticator/1.0";
/**
@@ -108,7 +108,7 @@
*/
public String getInfo() {
- return (this.info);
+ return (this.info);
}
@@ -130,15 +130,15 @@
* @exception IOException if an input/output error occurs
*/
public boolean authenticate(HttpRequest request,
- HttpResponse response,
- LoginConfig config)
- throws IOException {
-
- // Have we already authenticated someone?
- Principal principal =
- ((HttpServletRequest) request.getRequest()).getUserPrincipal();
- if (principal != null)
- return (true);
+ HttpResponse response,
+ LoginConfig config)
+ throws IOException {
+
+ // Have we already authenticated someone?
+ Principal principal =
+ ((HttpServletRequest) request.getRequest()).getUserPrincipal();
+ if (principal != null)
+ return (true);
// Retrieve the certificate chain for this client
if (debug >= 1)
1.3 +23 -23 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SavedRequest.java
Index: SavedRequest.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SavedRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SavedRequest.java 2000/09/25 21:46:31 1.2
+++ SavedRequest.java 2001/07/22 19:20:11 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SavedRequest.java,v 1.2 2000/09/25 21:46:31 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/09/25 21:46:31 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SavedRequest.java,v 1.3 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -89,7 +89,7 @@
* duplicated.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/09/25 21:46:31 $
+ * @version $Revision: 1.3 $ $Date: 2001/07/22 19:20:11 $
*/
public final class SavedRequest {
@@ -101,7 +101,7 @@
private ArrayList cookies = new ArrayList();
public void addCookie(Cookie cookie) {
- cookies.add(cookie);
+ cookies.add(cookie);
}
public Iterator getCookies() {
@@ -118,24 +118,24 @@
private HashMap headers = new HashMap();
public void addHeader(String name, String value) {
- ArrayList values = (ArrayList) headers.get(name);
- if (values == null) {
- values = new ArrayList();
- headers.put(name, values);
- }
- values.add(value);
+ ArrayList values = (ArrayList) headers.get(name);
+ if (values == null) {
+ values = new ArrayList();
+ headers.put(name, values);
}
+ values.add(value);
+ }
public Iterator getHeaderNames() {
return (headers.keySet().iterator());
}
public Iterator getHeaderValues(String name) {
- ArrayList values = (ArrayList) headers.get(name);
- if (values == null)
- return ((new ArrayList()).iterator());
- else
- return (values.iterator());
+ ArrayList values = (ArrayList) headers.get(name);
+ if (values == null)
+ return ((new ArrayList()).iterator());
+ else
+ return (values.iterator());
}
@@ -145,7 +145,7 @@
private ArrayList locales = new ArrayList();
public void addLocale(Locale locale) {
- locales.add(locale);
+ locales.add(locale);
}
public Iterator getLocales() {
@@ -159,11 +159,11 @@
private String method = null;
public String getMethod() {
- return (this.method);
+ return (this.method);
}
public void setMethod(String method) {
- this.method = method;
+ this.method = method;
}
@@ -194,11 +194,11 @@
private String queryString = null;
public String getQueryString() {
- return (this.queryString);
+ return (this.queryString);
}
public void setQueryString(String queryString) {
- this.queryString = queryString;
+ this.queryString = queryString;
}
@@ -208,11 +208,11 @@
private String requestURI = null;
public String getRequestURI() {
- return (this.requestURI);
+ return (this.requestURI);
}
public void setRequestURI(String requestURI) {
- this.requestURI = requestURI;
+ this.requestURI = requestURI;
}
1.5 +18 -18 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SingleSignOn.java
Index: SingleSignOn.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SingleSignOn.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SingleSignOn.java 2001/01/23 02:53:03 1.4
+++ SingleSignOn.java 2001/07/22 19:20:11 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SingleSignOn.java,v 1.4 2001/01/23 02:53:03 craigmcc Exp $
- * $Revision: 1.4 $
- * $Date: 2001/01/23 02:53:03 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/authenticator/SingleSignOn.java,v 1.5 2001/07/22 19:20:11 pier Exp $
+ * $Revision: 1.5 $
+ * $Date: 2001/07/22 19:20:11 $
*
* ====================================================================
*
@@ -100,7 +100,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2001/01/23 02:53:03 $
+ * @version $Revision: 1.5 $ $Date: 2001/07/22 19:20:11 $
*/
public class SingleSignOn
@@ -134,7 +134,7 @@
* The string manager for this package.
*/
protected final static StringManager sm =
- StringManager.getManager(Constants.Package);
+ StringManager.getManager(Constants.Package);
// ------------------------------------------------------------- Properties
@@ -170,7 +170,7 @@
*/
public String getInfo() {
- return (info);
+ return (info);
}
@@ -316,11 +316,11 @@
*/
protected void log(String message) {
- Logger logger = container.getLogger();
- if (logger != null)
- logger.log(this.toString() + ": " + message);
- else
- System.out.println(this.toString() + ": " + message);
+ Logger logger = container.getLogger();
+ if (logger != null)
+ logger.log(this.toString() + ": " + message);
+ else
+ System.out.println(this.toString() + ": " + message);
}
@@ -333,13 +333,13 @@
*/
protected void log(String message, Throwable throwable) {
- Logger logger = container.getLogger();
- if (logger != null)
- logger.log(this.toString() + ": " + message, throwable);
- else {
- System.out.println(this.toString() + ": " + message);
- throwable.printStackTrace(System.out);
- }
+ Logger logger = container.getLogger();
+ if (logger != null)
+ logger.log(this.toString() + ": " + message, throwable);
+ else {
+ System.out.println(this.toString() + ": " + message);
+ throwable.printStackTrace(System.out);
+ }
}