From 6e5ea8196f792f5ffc1334c8fab31c17755d0771 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 18 Aug 2023 11:55:36 +1000 Subject: [PATCH] cleanups and changes from review Signed-off-by: Lachlan Roberts --- .../jetty/security/AuthenticationState.java | 5 ++++ .../org/eclipse/jetty/security/ServeAs.java | 21 --------------- .../authentication/FormAuthenticator.java | 19 +++----------- .../jetty/ee10/servlet/ServletChannel.java | 26 ------------------- .../ee10/servlet/ServletContextRequest.java | 4 +-- 5 files changed, 11 insertions(+), 64 deletions(-) delete mode 100644 jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/ServeAs.java diff --git a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AuthenticationState.java b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AuthenticationState.java index c96a8785850..c148ae0b247 100644 --- a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AuthenticationState.java +++ b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/AuthenticationState.java @@ -294,6 +294,11 @@ public interface AuthenticationState extends Request.AuthenticationState } }; } + + public interface Path + { + Request serveAs(Request request, String path); + } } static Deferred defer(LoginAuthenticator loginAuthenticator) diff --git a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/ServeAs.java b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/ServeAs.java deleted file mode 100644 index 2e2b000b8af..00000000000 --- a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/ServeAs.java +++ /dev/null @@ -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); -} diff --git a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java index e4bfa3cffb2..e71a6d1f0c8 100644 --- a/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java +++ b/jetty-core/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java @@ -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); diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java index 5715e5f6efb..6984269709f 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java @@ -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(); diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java index be72c65c64c..e09ecc3c55b 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextRequest.java @@ -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. *

*/ -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;