cleanups and changes from review

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2023-08-18 11:55:36 +10:00
parent a418e0db71
commit 6e5ea8196f
5 changed files with 11 additions and 64 deletions

View File

@ -294,6 +294,11 @@ public interface AuthenticationState extends Request.AuthenticationState
}
};
}
public interface Path
{
Request serveAs(Request request, String path);
}
}
static Deferred defer(LoginAuthenticator loginAuthenticator)

View File

@ -1,21 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.security;
import org.eclipse.jetty.server.Request;
public interface ServeAs
{
Request serveAs(Request request, String path);
}

View File

@ -57,7 +57,6 @@ public class FormAuthenticator extends LoginAuthenticator
public static final String __FORM_LOGIN_PAGE = "org.eclipse.jetty.security.form_login_page";
public static final String __FORM_ERROR_PAGE = "org.eclipse.jetty.security.form_error_page";
public static final String __FORM_DISPATCH = "org.eclipse.jetty.security.dispatch";
public static final String __J_URI = "org.eclipse.jetty.security.form_URI";
public static final String __J_POST = "org.eclipse.jetty.security.form_POST";
public static final String __J_METHOD = "org.eclipse.jetty.security.form_METHOD";
@ -69,8 +68,8 @@ public class FormAuthenticator extends LoginAuthenticator
private String _formErrorPath;
private String _formLoginPage;
private String _formLoginPath;
private boolean _alwaysSaveUri;
private boolean _dispatch;
private boolean _alwaysSaveUri;
public FormAuthenticator()
{
@ -78,6 +77,7 @@ public class FormAuthenticator extends LoginAuthenticator
public FormAuthenticator(String login, String error, boolean dispatch)
{
this();
if (login != null)
setLoginPage(login);
if (error != null)
@ -113,7 +113,6 @@ public class FormAuthenticator extends LoginAuthenticator
String error = configuration.getParameter(FormAuthenticator.__FORM_ERROR_PAGE);
if (error != null)
setErrorPage(error);
String dispatch = configuration.getParameter(FormAuthenticator.__FORM_DISPATCH);
_dispatch = dispatch == null ? _dispatch : Boolean.parseBoolean(dispatch);
}
@ -137,11 +136,6 @@ public class FormAuthenticator extends LoginAuthenticator
_formLoginPath = _formLoginPath.substring(0, _formLoginPath.indexOf('?'));
}
public String getLoginPage()
{
return _formLoginPage;
}
private void setErrorPage(String path)
{
if (path == null || path.trim().length() == 0)
@ -164,11 +158,6 @@ public class FormAuthenticator extends LoginAuthenticator
}
}
public String getErrorPage()
{
return _formErrorPage;
}
@Override
public UserIdentity login(String username, Object password, Request request, Response response)
{
@ -375,7 +364,7 @@ public class FormAuthenticator extends LoginAuthenticator
@Override
public Request wrap(Request request)
{
org.eclipse.jetty.security.ServeAs serveAs = Request.as(request, org.eclipse.jetty.security.ServeAs.class);
ServeAs.Path serveAs = Request.as(request, ServeAs.Path.class);
if (serveAs != null)
return serveAs.serveAs(request, path);
return super.wrap(request);
@ -393,7 +382,7 @@ public class FormAuthenticator extends LoginAuthenticator
{
if (_formErrorPage == null)
Response.writeError(request, response, callback, HttpStatus.FORBIDDEN_403);
else if (_dispatch && getErrorPage() != null)
else if (_dispatch && _formErrorPage != null)
return dispatch(_formErrorPage, request, response, callback);
else
Response.sendRedirect(request, response, callback, encodeURL(URIUtil.addPaths(request.getContext().getContextPath(), _formErrorPage), request), true);

View File

@ -21,8 +21,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.ee10.servlet.ServletChannelState.Action;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpFields;
@ -72,9 +70,6 @@ import static org.eclipse.jetty.util.thread.Invocable.InvocationType.NON_BLOCKIN
public class ServletChannel
{
private static final Logger LOG = LoggerFactory.getLogger(ServletChannel.class);
private static final String FORWARD_REQUEST = "jetty.initial.forward.request";
private static final String FORWARD_RESPONSE = "jetty.initial.forward.response";
private static final String FORWARD_PATH = "jetty.initial.forward.path";
private final ServletChannelState _state;
private final ServletContextHandler.ServletScopedContext _context;
@ -889,27 +884,6 @@ public class ServletChannel
}
}
private void initialForward() throws Exception
{
ServletContextHandler servletContextHandler = getServletContextHandler();
ServletContextRequest servletContextRequest = getServletContextRequest();
HttpServletRequest request = (HttpServletRequest)servletContextRequest.removeAttribute(FORWARD_REQUEST);
HttpServletResponse response = (HttpServletResponse)servletContextRequest.removeAttribute(FORWARD_RESPONSE);
String path = (String)servletContextRequest.removeAttribute(FORWARD_PATH);
try
{
servletContextHandler.requestInitialized(servletContextRequest, request);
RequestDispatcher requestDispatcher = request.getRequestDispatcher(path);
requestDispatcher.forward(request, response);
}
finally
{
servletContextHandler.requestDestroyed(servletContextRequest, request);
}
}
public void dispatchAsync() throws Exception
{
ServletContextHandler servletContextHandler = getServletContextHandler();

View File

@ -32,7 +32,7 @@ import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.http.pathmap.MatchedResource;
import org.eclipse.jetty.security.ServeAs;
import org.eclipse.jetty.security.AuthenticationState.ServeAs;
import org.eclipse.jetty.server.FormFields;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
@ -54,7 +54,7 @@ import org.eclipse.jetty.util.Fields;
* This class is single use only.
* </p>
*/
public class ServletContextRequest extends ContextRequest implements ServletContextHandler.ServletRequestInfo, ServeAs
public class ServletContextRequest extends ContextRequest implements ServletContextHandler.ServletRequestInfo, ServeAs.Path
{
public static final String MULTIPART_CONFIG_ELEMENT = "org.eclipse.jetty.multipartConfig";
static final int INPUT_NONE = 0;