mirror of
https://github.com/i2p/i2p.i2p.git
synced 2026-06-08 21:41:42 +00:00
Conversion to Jetty 12 / Java 17
- Basic console (tested) - SSL console (tested) - Auth (tested) - Debug logging (tested) - Console request log (tested) - I2PControl separate port (untested) - Eepsite request log (untested) TODO: - Eepsites + migration - Debian with or without Jetty 12 - Snark standalone - Tomcat upgrade - Checkin jetty jars - Cleanups
This commit is contained in:
@@ -4,10 +4,6 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.Addresses;
|
||||
@@ -15,7 +11,9 @@ import net.i2p.util.Log;
|
||||
import net.i2p.util.PortMapper;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
||||
/**
|
||||
* Block certain Host headers to prevent DNS rebinding attacks.
|
||||
@@ -75,14 +73,13 @@ public class HostCheckHandler extends GzipHandler
|
||||
* redirect HTTP to HTTPS,
|
||||
* pass everything else to the delegate.
|
||||
*/
|
||||
public void handle(String pathInContext,
|
||||
Request baseRequest,
|
||||
HttpServletRequest httpRequest,
|
||||
HttpServletResponse httpResponse)
|
||||
throws IOException, ServletException
|
||||
@Override
|
||||
public boolean handle(Request request,
|
||||
Response response,
|
||||
Callback callback)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
String host = httpRequest.getHeader("Host");
|
||||
String host = request.getHeaders().get("Host");
|
||||
if (!allowHost(host)) {
|
||||
Log log = _context.logManager().getLog(HostCheckHandler.class);
|
||||
host = DataHelper.stripHTML(getHost(host));
|
||||
@@ -91,29 +88,28 @@ public class HostCheckHandler extends GzipHandler
|
||||
" add the line \"" + RouterConsoleRunner.PROP_ALLOWED_HOSTS + '=' + host + "\"\n" +
|
||||
" to advanced configuration and restart.";
|
||||
log.logAlways(Log.WARN, s);
|
||||
httpResponse.sendError(403, s);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
Response.writeError(request, response, callback, 403, s);
|
||||
return true;
|
||||
}
|
||||
|
||||
// redirect HTTP to HTTPS if available, AND:
|
||||
// either 1) PROP_REDIRECT is set to true;
|
||||
// or 2) PROP_REDIRECT is unset and the Upgrade-Insecure-Requests request header is set
|
||||
// https://w3c.github.io/webappsec-upgrade-insecure-requests/
|
||||
if (!httpRequest.isSecure()) {
|
||||
if (!request.isSecure()) {
|
||||
int httpsPort = _portMapper.getPort(PortMapper.SVC_HTTPS_CONSOLE);
|
||||
if (httpsPort > 0 && httpRequest.getLocalPort() != httpsPort) {
|
||||
if (httpsPort > 0 && Request.getLocalPort(request) != httpsPort) {
|
||||
String redir = _context.getProperty(PROP_REDIRECT);
|
||||
if (Boolean.parseBoolean(redir) ||
|
||||
(redir == null && "1".equals(httpRequest.getHeader("Upgrade-Insecure-Requests")))) {
|
||||
sendRedirect(httpsPort, httpRequest, httpResponse);
|
||||
baseRequest.setHandled(true);
|
||||
return;
|
||||
(redir == null && "1".equals(request.getHeaders().get("Upgrade-Insecure-Requests")))) {
|
||||
sendRedirect(httpsPort, request, response);
|
||||
callback.succeeded();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.handle(pathInContext, baseRequest, httpRequest, httpResponse);
|
||||
return super.handle(request, response, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,11 +168,11 @@ public class HostCheckHandler extends GzipHandler
|
||||
*
|
||||
* @since 0.9.34
|
||||
*/
|
||||
private static void sendRedirect(int httpsPort, HttpServletRequest httpRequest,
|
||||
HttpServletResponse httpResponse) throws IOException {
|
||||
private static void sendRedirect(int httpsPort, Request request,
|
||||
Response response) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(64);
|
||||
buf.append("https://");
|
||||
String name = httpRequest.getServerName();
|
||||
String name = Request.getServerName(request);
|
||||
boolean ipv6 = name.indexOf(':') >= 0 && !name.startsWith("[");
|
||||
if (ipv6)
|
||||
buf.append('[');
|
||||
@@ -184,14 +180,13 @@ public class HostCheckHandler extends GzipHandler
|
||||
if (ipv6)
|
||||
buf.append(']');
|
||||
buf.append(':').append(httpsPort)
|
||||
.append(httpRequest.getRequestURI());
|
||||
String q = httpRequest.getQueryString();
|
||||
.append(request.getHttpURI().getPath());
|
||||
String q = request.getHttpURI().getQuery();
|
||||
if (q != null)
|
||||
buf.append('?').append(q);
|
||||
httpResponse.setHeader("Location", buf.toString());
|
||||
response.getHeaders().put("Location", buf.toString());
|
||||
// https://w3c.github.io/webappsec-upgrade-insecure-requests/
|
||||
httpResponse.setHeader("Vary", "Upgrade-Insecure-Requests");
|
||||
httpResponse.setStatus(307);
|
||||
httpResponse.getOutputStream().close();
|
||||
response.getHeaders().put("Vary", "Upgrade-Insecure-Requests");
|
||||
response.setStatus(307);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,14 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
|
||||
import org.eclipse.jetty.ee8.nested.SessionHandler;
|
||||
import org.eclipse.jetty.ee8.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.ee8.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.http.pathmap.MatchedResource;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
||||
/**
|
||||
* Convert foo.jsp to foo_xx.jsp for language xx.
|
||||
@@ -26,7 +29,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
||||
*
|
||||
* @author zzz
|
||||
*/
|
||||
public class LocaleWebAppHandler extends HandlerWrapper
|
||||
public class LocaleWebAppHandler extends Handler.Wrapper
|
||||
{
|
||||
private final I2PAppContext _context;
|
||||
private final WebAppContext _wac;
|
||||
@@ -43,24 +46,24 @@ public class LocaleWebAppHandler extends HandlerWrapper
|
||||
_wac.setServletHandler(servletHandler);
|
||||
setHandler(_wac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle foo.jsp by converting to foo_xx.jsp
|
||||
* for language xx, where xx is the language for the default locale,
|
||||
* or as specified in the routerconsole.lang property.
|
||||
* Unless language == "en".
|
||||
*/
|
||||
public void handle(String pathInContext,
|
||||
Request baseRequest,
|
||||
HttpServletRequest httpRequest,
|
||||
HttpServletResponse httpResponse)
|
||||
throws IOException, ServletException
|
||||
public boolean handle(Request request,
|
||||
Response response,
|
||||
Callback callback)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
String pathInContext = Request.getPathInContext(request);
|
||||
String newPath = pathInContext;
|
||||
// transparent rewriting
|
||||
if (pathInContext.equals("/") || pathInContext.equals("/index.html")) {
|
||||
// home page
|
||||
pathInContext = "/index.jsp";
|
||||
newPath = "/index.jsp";
|
||||
} else if (pathInContext.equals("/favicon.ico")) {
|
||||
// pass thru unchanged
|
||||
} else if (pathInContext.indexOf('/', 1) < 0 &&
|
||||
@@ -68,11 +71,10 @@ public class LocaleWebAppHandler extends HandlerWrapper
|
||||
(!pathInContext.endsWith(".log")) &&
|
||||
(!pathInContext.endsWith(".txt"))) {
|
||||
// add .jsp to pages at top level
|
||||
pathInContext += ".jsp";
|
||||
newPath += ".jsp";
|
||||
}
|
||||
|
||||
//System.err.println("Path: " + pathInContext);
|
||||
String newPath = pathInContext;
|
||||
//if (pathInContext.endsWith(".jsp")) {
|
||||
// We only ended up doing this for help.jsp, so save some effort
|
||||
// unless we translate more pages like this
|
||||
@@ -87,9 +89,9 @@ public class LocaleWebAppHandler extends HandlerWrapper
|
||||
String testPath = pathInContext.substring(0, len - 4) + '_' + lang + ".jsp";
|
||||
// Do we have a servlet for the new path that isn't the catchall *.jsp?
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map.Entry servlet = _wac.getServletHandler().getHolderEntry(testPath);
|
||||
MatchedResource<ServletHandler.MappedServlet> servlet = _wac.getServletHandler().getMatchedServlet(testPath);
|
||||
if (servlet != null) {
|
||||
String servletPath = (String) servlet.getKey();
|
||||
String servletPath = servlet.getPathSpec().getDeclaration();
|
||||
if (servletPath != null && !servletPath.startsWith("*")) {
|
||||
// success!!
|
||||
//System.err.println("Servlet is: " + servletPath);
|
||||
@@ -99,14 +101,20 @@ public class LocaleWebAppHandler extends HandlerWrapper
|
||||
}
|
||||
}
|
||||
} else if (pathInContext.startsWith("/js/")) {
|
||||
// https://stackoverflow.com/questions/78878330/how-to-set-encoding-for-httpservletrequest-and-httpservletresponse-in-jetty12-t
|
||||
// war internal
|
||||
httpResponse.setCharacterEncoding("ISO-8859-1");
|
||||
//response.setCharacterEncoding("ISO-8859-1");
|
||||
// probably not doing anything
|
||||
response.getHeaders().put("Content-Type", "text/javascript;charset=iso-8859-1");
|
||||
} else if (pathInContext.endsWith(".css")) {
|
||||
// war internal
|
||||
httpResponse.setCharacterEncoding("UTF-8");
|
||||
//response.setCharacterEncoding("UTF-8");
|
||||
response.getHeaders().put("Content-Type", "text/css;charset=utf-8");
|
||||
}
|
||||
//System.err.println("New path: " + newPath);
|
||||
super.handle(newPath, baseRequest, httpRequest, httpResponse);
|
||||
if (!newPath.equals(pathInContext))
|
||||
request = Request.serveAs(request, Request.newHttpURIFrom(request, newPath));
|
||||
return super.handle(request, response, callback);
|
||||
//System.err.println("Was handled? " + httpRequest.isHandled());
|
||||
}
|
||||
|
||||
@@ -152,4 +160,11 @@ public class LocaleWebAppHandler extends HandlerWrapper
|
||||
context.setInitParameter((String)e.getKey(), (String)e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since Jetty 12
|
||||
*/
|
||||
public WebAppContext getWebAppContext() {
|
||||
return _wac;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.app.ClientApp;
|
||||
@@ -46,34 +46,38 @@ import net.i2p.util.SecureDirectory;
|
||||
import net.i2p.util.I2PSSLSocketFactory;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
import org.eclipse.jetty.ee8.nested.ServletConstraint;
|
||||
import org.eclipse.jetty.ee8.security.ConstraintMapping;
|
||||
import org.eclipse.jetty.ee8.security.ConstraintSecurityHandler;
|
||||
import org.eclipse.jetty.ee8.security.SecurityHandler;
|
||||
import org.eclipse.jetty.ee8.security.authentication.BasicAuthenticator;
|
||||
import org.eclipse.jetty.ee8.security.authentication.DigestAuthenticator;
|
||||
import org.eclipse.jetty.ee8.security.authentication.LoginAuthenticator;
|
||||
import org.eclipse.jetty.ee8.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.ee8.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.ee8.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.security.Constraint;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.security.ConstraintMapping;
|
||||
import org.eclipse.jetty.security.ConstraintSecurityHandler;
|
||||
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
|
||||
import org.eclipse.jetty.security.authentication.DigestAuthenticator;
|
||||
import org.eclipse.jetty.security.authentication.LoginAuthenticator;
|
||||
import org.eclipse.jetty.security.UserIdentity;
|
||||
import org.eclipse.jetty.security.UserStore;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
import org.eclipse.jetty.server.ConnectionFactory;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.CustomRequestLog;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.NCSARequestLog;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.SecureRequestCustomizer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.UserIdentity;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.Session;
|
||||
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
import org.eclipse.jetty.server.handler.RequestLogHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.security.Constraint;
|
||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||
import org.eclipse.jetty.util.resource.URLResourceFactory;
|
||||
import org.eclipse.jetty.util.security.Credential;
|
||||
import org.eclipse.jetty.util.security.Credential.MD5;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
@@ -91,15 +95,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
|
||||
static {
|
||||
// To take effect, must be set before any Jetty classes are loaded
|
||||
try {
|
||||
Log.setLog(new I2PLogger());
|
||||
} catch (Throwable t) {
|
||||
System.err.println("INFO: I2P Jetty logging class not found, logging to wrapper log");
|
||||
}
|
||||
// This way it doesn't try to load Slf4jLog first
|
||||
// This causes an NPE in AbstractLifeCycle
|
||||
// http://dev.eclipse.org/mhonarc/lists/jetty-users/msg02587.html
|
||||
//System.setProperty("org.eclipse.jetty.util.log.class", "net.i2p.jetty.I2PLogger");
|
||||
// https://slf4j.org/faq.html
|
||||
System.setProperty("slf4j.provider", "net.i2p.jetty.I2PLoggingServiceProvider");
|
||||
}
|
||||
|
||||
private final RouterContext _context;
|
||||
@@ -501,12 +498,10 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
_server = new Server(qtp);
|
||||
//}
|
||||
|
||||
HandlerCollection hColl = new HandlerCollection();
|
||||
Handler.Sequence hColl = new Handler.Sequence();
|
||||
ContextHandlerCollection chColl = new ContextHandlerCollection();
|
||||
HostCheckHandler chCollWrapper = new HostCheckHandler(_context);
|
||||
chCollWrapper.setHandler(chColl);
|
||||
// gone in Jetty 7
|
||||
//_server.addHandler(hColl);
|
||||
_server.setHandler(hColl);
|
||||
hColl.addHandler(chCollWrapper);
|
||||
hColl.addHandler(new DefaultHandler());
|
||||
@@ -517,9 +512,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
if (!logFile.isAbsolute())
|
||||
logFile = new File(_context.getLogDir(), "logs/" + log);
|
||||
try {
|
||||
RequestLogHandler rhl = new RequestLogHandler();
|
||||
rhl.setRequestLog(new NCSARequestLog(logFile.getAbsolutePath()));
|
||||
hColl.addHandler(rhl);
|
||||
_server.setRequestLog(new CustomRequestLog(logFile.toString(), CustomRequestLog.NCSA_FORMAT));
|
||||
} catch (Exception ioe) {
|
||||
System.err.println("ERROR: Unable to create Jetty log: " + ioe);
|
||||
}
|
||||
@@ -544,7 +537,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
_webAppsDir += '/';
|
||||
|
||||
Set<String> listenHosts = new HashSet<String>(8);
|
||||
HandlerWrapper rootWebApp = null;
|
||||
LocaleWebAppHandler rootWebApp = null;
|
||||
ServletHandler rootServletHandler = null;
|
||||
List<Connector> connectors = new ArrayList<Connector>(4);
|
||||
try {
|
||||
@@ -644,7 +637,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
}
|
||||
if (verifyKeyStore(keyStore, altNames)) {
|
||||
// the keystore path and password
|
||||
SslContextFactory sslFactory = new SslContextFactory(keyStore.getAbsolutePath());
|
||||
SslContextFactory.Server sslFactory = new SslContextFactory.Server();
|
||||
sslFactory.setKeyStorePath(keyStore.getAbsolutePath());
|
||||
sslFactory.setKeyStorePassword(_context.getProperty(PROP_KEYSTORE_PASSWORD, KeyStoreUtil.DEFAULT_KEYSTORE_PASSWORD));
|
||||
// the X.509 cert password (if not present, verifyKeyStore() returned false)
|
||||
sslFactory.setKeyManagerPassword(_context.getProperty(PROP_KEY_PASSWORD, "thisWontWork"));
|
||||
@@ -735,11 +729,11 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
// Got a clue from this ancient post for Tomcat 6:
|
||||
// https://bz.apache.org/bugzilla/show_bug.cgi?id=39804
|
||||
// see also apps/jetty/build.xml
|
||||
Class.forName("org.eclipse.jetty.apache.jsp.JettyJasperInitializer");
|
||||
Class.forName("org.eclipse.jetty.ee8.apache.jsp.JettyJasperInitializer");
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
System.err.println("Warning: JettyJasperInitializer not found");
|
||||
}
|
||||
WebAppContext wac = (WebAppContext)(rootWebApp.getHandler());
|
||||
WebAppContext wac = rootWebApp.getWebAppContext();
|
||||
initialize(_context, wac);
|
||||
WebAppStarter.setWebAppConfiguration(wac, false);
|
||||
chColl.addHandler(rootWebApp);
|
||||
@@ -772,7 +766,10 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=364936
|
||||
// WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/,jar:file:/.../webapps/routerconsole.war!/},/.../webapps/routerconsole.war
|
||||
// java.lang.IllegalStateException: zip file closed
|
||||
Resource.setDefaultUseCaches(false);
|
||||
// FIXME
|
||||
//URLResourceFactory urlrf = new URLResourceFactory();
|
||||
//urlrf.setUseCaches(false);
|
||||
//ResourceFactory.registerResourceFactory("jar", urlrf);
|
||||
try {
|
||||
// start does a mapContexts()
|
||||
_server.start();
|
||||
@@ -994,6 +991,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
String rlm = isBasic ? PROMETHEUS_REALM : JETTY_REALM;
|
||||
HashLoginService realm = new CustomHashLoginService(rlm, context.getContextPath(),
|
||||
ctx.logManager().getLog(RouterConsoleRunner.class));
|
||||
UserStore userStore = new UserStore();
|
||||
realm.setUserStore(userStore);
|
||||
sec.setLoginService(realm);
|
||||
LoginAuthenticator auth = isBasic ? basicAuthenticator : authenticator;
|
||||
sec.setAuthenticator(auth);
|
||||
@@ -1003,8 +1002,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
String pw = e.getValue();
|
||||
// for basic, the password will be the md5 hash itself
|
||||
Credential cred = Credential.getCredential(isBasic ? pw : MD5_CREDENTIAL_TYPE + pw);
|
||||
realm.putUser(user, cred, role);
|
||||
Constraint constraint = new Constraint(user, JETTY_ROLE);
|
||||
userStore.addUser(user, cred, role);
|
||||
ServletConstraint constraint = new ServletConstraint(user, JETTY_ROLE);
|
||||
constraint.setAuthenticate(true);
|
||||
ConstraintMapping cm = new ConstraintMapping();
|
||||
cm.setConstraint(constraint);
|
||||
@@ -1023,8 +1022,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
try {
|
||||
// each char truncated to 8 bytes
|
||||
String user2 = new String(b2, "ISO-8859-1");
|
||||
realm.putUser(user2, cred, role);
|
||||
constraint = new Constraint(user2, JETTY_ROLE);
|
||||
userStore.addUser(user2, cred, role);
|
||||
constraint = new ServletConstraint(user2, JETTY_ROLE);
|
||||
constraint.setAuthenticate(true);
|
||||
cm = new ConstraintMapping();
|
||||
cm.setConstraint(constraint);
|
||||
@@ -1034,8 +1033,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
// each UTF-8 byte as a char
|
||||
// this is what chrome does
|
||||
String user3 = new String(b1, "ISO-8859-1");
|
||||
realm.putUser(user3, cred, role);
|
||||
constraint = new Constraint(user3, JETTY_ROLE);
|
||||
userStore.addUser(user3, cred, role);
|
||||
constraint = new ServletConstraint(user2, JETTY_ROLE);
|
||||
constraint.setAuthenticate(true);
|
||||
cm = new ConstraintMapping();
|
||||
cm.setConstraint(constraint);
|
||||
@@ -1057,7 +1056,7 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
// See also:
|
||||
// http://old.nabble.com/Disable-HTTP-TRACE-in-Jetty-5.x-td12412607.html
|
||||
|
||||
Constraint sc = new Constraint();
|
||||
ServletConstraint sc = new ServletConstraint();
|
||||
sc.setName("No trace");
|
||||
ConstraintMapping cm = new ConstraintMapping();
|
||||
cm.setMethod("TRACE");
|
||||
@@ -1065,8 +1064,6 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
cm.setPathSpec("/");
|
||||
constraints.add(cm);
|
||||
|
||||
sc = new Constraint();
|
||||
sc.setName("No options");
|
||||
cm = new ConstraintMapping();
|
||||
cm.setMethod("OPTIONS");
|
||||
cm.setConstraint(sc);
|
||||
@@ -1109,11 +1106,11 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserIdentity login(String username, Object credentials, ServletRequest request) {
|
||||
UserIdentity rv = super.login(username, credentials, request);
|
||||
public UserIdentity login(String username, Object credentials, Request request, Function<Boolean, Session> getOrCreateSession) {
|
||||
UserIdentity rv = super.login(username, credentials, request, getOrCreateSession);
|
||||
if (rv == null)
|
||||
//_log.logAlways(net.i2p.util.Log.WARN, "Console authentication failed, webapp: " + _webapp + ", user: " + username);
|
||||
_log.logAlways(net.i2p.util.Log.WARN, "Console authentication failed, user: " + username + " IP: " + request.getRemoteAddr());
|
||||
_log.logAlways(net.i2p.util.Log.WARN, "Console authentication failed, user: " + username + " IP: " + Request.getRemoteAddr(request));
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
|
||||
import org.apache.tomcat.SimpleInstanceManager;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.ee8.webapp.Configuration;
|
||||
import org.eclipse.jetty.ee8.webapp.WebAppClassLoader;
|
||||
import org.eclipse.jetty.ee8.webapp.WebAppContext;
|
||||
|
||||
|
||||
/**
|
||||
@@ -223,4 +223,14 @@ public class WebAppConfiguration implements Configuration {
|
||||
|
||||
/** @since Jetty 7 */
|
||||
public void postConfigure(WebAppContext context) {}
|
||||
|
||||
/**
|
||||
* @since Jetty 12
|
||||
*/
|
||||
public boolean abort(WebAppContext context) { return false; }
|
||||
|
||||
/**
|
||||
* @since Jetty 12
|
||||
*/
|
||||
public boolean isEnabledByDefault() { return true; }
|
||||
}
|
||||
|
||||
@@ -17,11 +17,12 @@ import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.PortMapper;
|
||||
import net.i2p.util.SecureDirectory;
|
||||
|
||||
import org.eclipse.jetty.ee.WebAppClassLoading;
|
||||
import org.eclipse.jetty.ee8.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,7 +58,7 @@ public class WebAppStarter {
|
||||
// javax-annotations-api.jar
|
||||
private static final String CLASS_ANNOT4 = "javax.annotation.security.RunAs";
|
||||
|
||||
private static final String CLASS_CONFIG = "org.eclipse.jetty.webapp.JettyWebXmlConfiguration";
|
||||
private static final String CLASS_CONFIG = "org.eclipse.jetty.ee8.webapp.JettyWebXmlConfiguration";
|
||||
|
||||
private static final boolean HAS_ANNOTATION_CLASSES;
|
||||
private static final Set<String> BUILTINS = new HashSet<String>(8);
|
||||
@@ -202,12 +203,15 @@ public class WebAppStarter {
|
||||
// Without the default configuration, the web.xml isn't read, and the webapp
|
||||
// won't respond to any requests, even though it appears to be running.
|
||||
// See WebAppContext.loadConfigurations() in source
|
||||
if (classNames.length == 0)
|
||||
classNames = wac.getDefaultConfigurationClasses();
|
||||
if (classNames.length == 0) {
|
||||
//classNames = wac.getDefaultConfigurationClasses();
|
||||
// These are the defaults as documented in WebAppContext
|
||||
classNames = new String[] { "org.eclipse.jetty.ee8.webapp.WebXMLConfiguration", "org.eclipse.jetty.ee8.webapp.JettyWebXMLConfiguration" };
|
||||
}
|
||||
List<String> newClassNames = new ArrayList<String>(Arrays.asList(classNames));
|
||||
for (String name : newClassNames) {
|
||||
// fix for Jetty 9.4 ticket #2385
|
||||
wac.prependServerClass("-" + name);
|
||||
WebAppClassLoading.addHiddenClasses(wac, name);
|
||||
}
|
||||
// https://www.eclipse.org/jetty/documentation/current/using-annotations.html
|
||||
// https://www.eclipse.org/jetty/documentation/9.4.x/using-annotations-embedded.html
|
||||
@@ -327,14 +331,14 @@ public class WebAppStarter {
|
||||
* @since 0.9.41
|
||||
*/
|
||||
private static ContextHandler getWebApp(ContextHandlerCollection server, String appName) {
|
||||
Handler handlers[] = server.getHandlers();
|
||||
if (handlers == null)
|
||||
List<Handler> handlers = server.getHandlers();
|
||||
if (handlers == null || handlers.isEmpty())
|
||||
return null;
|
||||
String path = '/'+ appName;
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (!(handlers[i] instanceof ContextHandler))
|
||||
for (Handler h : handlers) {
|
||||
if (!(h instanceof ContextHandler))
|
||||
continue;
|
||||
ContextHandler ch = (ContextHandler) handlers[i];
|
||||
ContextHandler ch = (ContextHandler) h;
|
||||
if (path.equals(ch.getContextPath()))
|
||||
return ch;
|
||||
}
|
||||
@@ -360,9 +364,7 @@ public class WebAppStarter {
|
||||
* @since 0.9.41
|
||||
*/
|
||||
private static ContextHandlerCollection getConsoleServer(Server s) {
|
||||
Handler h = s.getChildHandlerByClass(ContextHandlerCollection.class);
|
||||
if (h == null)
|
||||
return null;
|
||||
return (ContextHandlerCollection) h;
|
||||
ContextHandlerCollection h = s.getDescendant(ContextHandlerCollection.class);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user