diff --git a/jetty-documentation/src/main/asciidoc/reference/troubleshooting/troubleshooting-locked-files.adoc b/jetty-documentation/src/main/asciidoc/reference/troubleshooting/troubleshooting-locked-files.adoc index 14b8fadbcb1..f23b78d8d22 100644 --- a/jetty-documentation/src/main/asciidoc/reference/troubleshooting/troubleshooting-locked-files.adoc +++ b/jetty-documentation/src/main/asciidoc/reference/troubleshooting/troubleshooting-locked-files.adoc @@ -88,7 +88,7 @@ Instead, you could redefine the DefaultServlet in your web.xml file, making sure ... - Default + default org.eclipse.jetty.servlet.DefaultServlet useFileMappedBuffer @@ -97,9 +97,7 @@ Instead, you could redefine the DefaultServlet in your web.xml file, making sure 0 ... - - - + ---- ==== Alternate Remedy @@ -117,7 +115,6 @@ Configure this in an xml file like so: . . - ---- ____ diff --git a/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java b/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java index e9d1b48d96d..5a664d7e05b 100644 --- a/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java +++ b/jetty-http-spi/src/main/java/org/eclipse/jetty/http/spi/DelegatingThreadPool.java @@ -25,19 +25,18 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.LifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.ThreadPool; +import org.eclipse.jetty.util.thread.TryExecutor; -public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPool -{ - private static final Logger LOG = Log.getLogger(DelegatingThreadPool.class); - +public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPool, TryExecutor +{ private Executor _executor; // memory barrier provided by start/stop semantics + private TryExecutor _tryExecutor; public DelegatingThreadPool(Executor executor) { _executor=executor; + _tryExecutor=TryExecutor.asTryExecutor(executor); addBean(_executor); } @@ -54,6 +53,7 @@ public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPo throw new IllegalStateException(getState()); updateBean(_executor,executor); _executor=executor; + _tryExecutor=TryExecutor.asTryExecutor(executor); } /* ------------------------------------------------------------ */ @@ -63,6 +63,13 @@ public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPo _executor.execute(job); } + /* ------------------------------------------------------------ */ + @Override + public boolean tryExecute(Runnable task) + { + return _tryExecutor.tryExecute(task); + } + /* ------------------------------------------------------------ */ @Override public int getIdleThreads() diff --git a/jetty-http-spi/src/test/java/org/eclipse/jetty/http/spi/TestEndpointMultiplePublishProblem.java b/jetty-http-spi/src/test/java/org/eclipse/jetty/http/spi/TestEndpointMultiplePublishProblem.java index 539a549a04d..aca8ddb5ad9 100644 --- a/jetty-http-spi/src/test/java/org/eclipse/jetty/http/spi/TestEndpointMultiplePublishProblem.java +++ b/jetty-http-spi/src/test/java/org/eclipse/jetty/http/spi/TestEndpointMultiplePublishProblem.java @@ -22,9 +22,9 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.util.thread.QueuedThreadPool; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import javax.jws.WebMethod; import javax.jws.WebService; @@ -35,13 +35,13 @@ public class TestEndpointMultiplePublishProblem private static String default_impl = System.getProperty("com.sun.net.httpserver.HttpServerProvider"); - @BeforeClass + @BeforeAll public static void change_Impl() { System.setProperty("com.sun.net.httpserver.HttpServerProvider", JettyHttpServerProvider.class.getName()); } - @AfterClass + @AfterAll public static void restore_Impl() { if(default_impl != null) diff --git a/jetty-maven-plugin/src/it/it-parent-pom/pom.xml b/jetty-maven-plugin/src/it/it-parent-pom/pom.xml index 3998159ba14..c8737562cc3 100644 --- a/jetty-maven-plugin/src/it/it-parent-pom/pom.xml +++ b/jetty-maven-plugin/src/it/it-parent-pom/pom.xml @@ -10,6 +10,7 @@ @project.version@ + UTF-8 diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml new file mode 100755 index 00000000000..3bd331ee290 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/pom.xml @@ -0,0 +1,12 @@ + + 4.0.0 + + + test.jetty-maven-plugin-provided-module-dep + parent + 1.0-SNAPSHOT + + api + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java new file mode 100755 index 00000000000..fc5ad794a23 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/api/src/main/java/test/Api.java @@ -0,0 +1,28 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package test; + +public class Api +{ + + public void noOp() + { + } +} \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties new file mode 100644 index 00000000000..816c3f38def --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = verify -V -e +#test-compile failsafe:integration-test \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml new file mode 100755 index 00000000000..6546cb87f21 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + + org.eclipse.jetty.its + it-parent-pom + 0.0.1-SNAPSHOT + + + test.jetty-maven-plugin-provided-module-dep + parent + 1.0-SNAPSHOT + pom + + + + api + web + + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy new file mode 100644 index 00000000000..4c12de49d83 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/postbuild.groovy @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Started Jetty Server' ) +assert buildLog.text.contains( 'ClassNotFoundException') \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml new file mode 100755 index 00000000000..22b6754fa9e --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + + + test.jetty-maven-plugin-provided-module-dep + parent + 1.0-SNAPSHOT + + web + war + + + + ${project.groupId} + api + ${project.version} + provided + + + javax.servlet + javax.servlet-api + provided + + + + + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + + + + org.eclipse.jetty + jetty-maven-plugin + + + start-jetty + test-compile + + start + + + true + ${basedir}/src/config/jetty.xml + + + + + + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml new file mode 100644 index 00000000000..2a17fe49cd7 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -0,0 +1,48 @@ + + + + + + https + + + + 32768 + 8192 + 8192 + 4096 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + 30000 + + + + diff --git a/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java new file mode 100755 index 00000000000..8d22ee0a6e3 --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/main/java/test/ClassLoadingTestingServletContextListener.java @@ -0,0 +1,49 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package test; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +@WebListener +public class ClassLoadingTestingServletContextListener + implements ServletContextListener +{ + + @Override + public void contextInitialized( ServletContextEvent sce ) + { + try + { + Api api = new Api(); + } + catch ( java.lang.Exception exception ) + { + exception.printStackTrace(); + } + //System.out.println("Class " + api.getClass().getName() + " is available and loaded by classloader " + api.getClass().getClassLoader().toString() + ". Expected ClassNotFoundException."); + } + + @Override + public void contextDestroyed( ServletContextEvent sce ) + { + } +} \ No newline at end of file diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java index c3c2f5c0eef..00bf2a2f146 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java @@ -532,9 +532,14 @@ public class JettyRunMojo extends AbstractJettyMojo { // Include runtime and compile time libraries, and possibly test libs too if(artifact.getType().equals("war")) - { continue; - } + + if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) + continue; //never add dependencies of scope=provided to the webapp's classpath (see also param) + + if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !useTestScope) + continue; //only add dependencies of scope=test if explicitly required + MavenProject mavenProject = getProjectReference( artifact, project ); if (mavenProject != null) { @@ -544,12 +549,6 @@ public class JettyRunMojo extends AbstractJettyMojo continue; } - if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) - continue; //never add dependencies of scope=provided to the webapp's classpath (see also param) - - if (Artifact.SCOPE_TEST.equals(artifact.getScope()) && !useTestScope) - continue; //only add dependencies of scope=test if explicitly required - dependencyFiles.add(artifact.getFile()); getLog().debug( "Adding artifact " + artifact.getFile().getName() + " with scope "+artifact.getScope()+" for WEB-INF/lib " ); } diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java index f1d52a4d49f..f07760ab045 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java @@ -26,7 +26,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; @@ -44,33 +43,33 @@ import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.security.Credential; /** - * PropertyUserStore - *

- * This class monitors a property file of the format mentioned below and notifies registered listeners of the changes to the the given file. + *

This class monitors a property file of the format mentioned below + * and notifies registered listeners of the changes to the the given file.

* *
  *  username: password [,rolename ...]
  * 
* - * Passwords may be clear text, obfuscated or checksummed. The class com.eclipse.Util.Password should be used to generate obfuscated passwords or password - * checksums. + *

Passwords may be clear text, obfuscated or checksummed. + * The class {@link org.eclipse.jetty.util.security.Password} should be used + * to generate obfuscated passwords or password checksums.

* - * If DIGEST Authentication is used, the password must be in a recoverable format, either plain text or OBF:. + *

If DIGEST Authentication is used, the password must be in a recoverable + * format, either plain text or obfuscated.

*/ public class PropertyUserStore extends UserStore implements PathWatcher.Listener { private static final Logger LOG = Log.getLogger(PropertyUserStore.class); protected Path _configPath; - protected PathWatcher _pathWatcher; protected boolean _hotReload = false; // default is not to reload - protected boolean _firstLoad = true; // true if first load, false from that point on protected List _listeners; /** * Get the config (as a string) + * * @return the config path as a string */ public String getConfig() @@ -82,6 +81,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * Set the Config Path from a String reference to a file + * * @param config the config file */ public void setConfig(String config) @@ -91,11 +91,11 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener _configPath = null; return; } - + try { Resource configResource = Resource.newResource(config); - + if (configResource instanceof JarFileResource) _configPath = extractPackedFile((JarFileResource)configResource); else if (configResource instanceof PathResource) @@ -110,11 +110,11 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener _configPath = null; throw new IllegalStateException(e); } - } - + /** * Get the Config {@link Path} reference. + * * @return the config path */ public Path getConfigPath() @@ -124,7 +124,8 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * Set the Config Path from a String reference to a file - * @param configFile the config file can a be a file path or a reference to a file within a jar file jar:file: + * + * @param configFile the config file can a be a file path or a reference to a file within a jar file {@code jar:file:} */ @Deprecated public void setConfigPath(String configFile) @@ -132,25 +133,24 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener setConfig(configFile); } - private Path extractPackedFile( JarFileResource configResource ) - throws IOException + private Path extractPackedFile(JarFileResource configResource) throws IOException { String uri = configResource.getURI().toASCIIString(); int colon = uri.lastIndexOf(":"); int bang_slash = uri.indexOf("!/"); - if (colon<0 || bang_slash<0 || colon>bang_slash) - throw new IllegalArgumentException("Not resolved JarFile resource: "+uri); - String entry_path = uri.substring(colon+2).replace("!/","__").replace('/','_').replace('.','_'); + if (colon < 0 || bang_slash < 0 || colon > bang_slash) + throw new IllegalArgumentException("Not resolved JarFile resource: " + uri); + String entry_path = uri.substring(colon + 2).replace("!/", "__").replace('/', '_').replace('.', '_'); - Path tmpDirectory = Files.createTempDirectory( "users_store" ); + Path tmpDirectory = Files.createTempDirectory("users_store"); tmpDirectory.toFile().deleteOnExit(); Path extractedPath = Paths.get(tmpDirectory.toString(), entry_path); - Files.deleteIfExists( extractedPath ); + Files.deleteIfExists(extractedPath); extractedPath.toFile().deleteOnExit(); - IO.copy(configResource.getInputStream(),new FileOutputStream(extractedPath.toFile())); + IO.copy(configResource.getInputStream(), new FileOutputStream(extractedPath.toFile())); if (isHotReload()) { - LOG.warn("Cannot hot reload from packed configuration: {}",configResource); + LOG.warn("Cannot hot reload from packed configuration: {}", configResource); setHotReload(false); } return extractedPath; @@ -158,6 +158,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * Set the Config Path from a {@link File} reference + * * @param configFile the config file */ @Deprecated @@ -165,24 +166,23 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener { setConfigFile(configFile); } - + /** * Set the Config Path from a {@link File} reference + * * @param configFile the config file */ public void setConfigFile(File configFile) { - if(configFile == null) - { + if (configFile == null) _configPath = null; - return; - } - - _configPath = configFile.toPath(); + else + _configPath = configFile.toPath(); } /** * Set the Config Path + * * @param configPath the config path */ public void setConfigPath(Path configPath) @@ -192,18 +192,17 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * @return the resource associated with the configured properties file, creating it if necessary - * @throws IOException if unable to get the resource */ - public Resource getConfigResource() throws IOException + public Resource getConfigResource() { - if (_configPath==null) + if (_configPath == null) return null; return new PathResource(_configPath); } - + /** * Is hot reload enabled on this user store - * + * * @return true if hot reload was enabled before startup */ public boolean isHotReload() @@ -213,7 +212,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * Enable Hot Reload of the Property File - * + * * @param enable true to enable, false to disable */ public void setHotReload(boolean enable) @@ -225,33 +224,27 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener this._hotReload = enable; } - - + @Override public String toString() { - StringBuilder s = new StringBuilder(); - s.append(this.getClass().getName()); - s.append("["); - s.append("users.count=").append(this.getKnownUserIdentities().size()); - s.append("identityService=").append(this.getIdentityService()); - s.append("]"); - return s.toString(); + return String.format("%s@%x[users.count=%d,identityService=%s]", getClass().getSimpleName(), hashCode(), getKnownUserIdentities().size(), getIdentityService()); } /* ------------------------------------------------------------ */ protected void loadUsers() throws IOException { if (_configPath == null) - throw new IllegalStateException ("No config path set"); + throw new IllegalStateException("No config path set"); + + if (LOG.isDebugEnabled()) + LOG.debug("Loading {} from {}", this, _configPath); - if (LOG.isDebugEnabled()) LOG.debug("Loading {} from {}",this, _configPath); - Resource config = getConfigResource(); - + if (!config.exists()) - throw new IllegalStateException ("Config does not exist: "+ config); - + throw new IllegalStateException("Config does not exist: " + config); + Properties properties = new Properties(); properties.load(config.getInputStream()); @@ -263,63 +256,50 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener String credentials = ((String)entry.getValue()).trim(); String roles = null; int c = credentials.indexOf(','); - if (c > 0) + if (c >= 0) { roles = credentials.substring(c + 1).trim(); - credentials = credentials.substring(0,c).trim(); + credentials = credentials.substring(0, c).trim(); } - if (username != null && username.length() > 0 && credentials != null && credentials.length() > 0) + if (username.length() > 0) { String[] roleArray = IdentityService.NO_ROLES; if (roles != null && roles.length() > 0) - { roleArray = StringUtil.csvSplit(roles); - } known.add(username); Credential credential = Credential.getCredential(credentials); - addUser( username, credential, roleArray ); - notifyUpdate(username,credential,roleArray); + addUser(username, credential, roleArray); + notifyUpdate(username, credential, roleArray); } } - final List currentlyKnownUsers = new ArrayList(getKnownUserIdentities().keySet()); - /* - * - * if its not the initial load then we want to process removed users - */ + List currentlyKnownUsers = new ArrayList<>(getKnownUserIdentities().keySet()); + // if its not the initial load then we want to process removed users if (!_firstLoad) { - Iterator users = currentlyKnownUsers.iterator(); - while (users.hasNext()) + for (String user : currentlyKnownUsers) { - String user = users.next(); if (!known.contains(user)) { - removeUser( user ); + removeUser(user); notifyRemove(user); } } } - /* - * set initial load to false as there should be no more initial loads - */ + // set initial load to false as there should be no more initial loads _firstLoad = false; if (LOG.isDebugEnabled()) - { LOG.debug("Loaded " + this + " from " + _configPath); - } } - - /* ------------------------------------------------------------ */ + /** - * Depending on the value of the refresh interval, this method will either start up a scanner thread that will monitor the properties file for changes after - * it has initially loaded it. Otherwise the users will be loaded and there will be no active monitoring thread so changes will not be detected. - * - * - * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() + * Depending on the value of the refresh interval, this method will either start + * up a scanner thread that will monitor the properties file for changes after + * it has initially loaded it. Otherwise the users will be loaded and there will + * be no active monitoring thread so changes will not be detected. */ @Override protected void doStart() throws Exception @@ -327,7 +307,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener super.doStart(); loadUsers(); - if ( isHotReload() && (_configPath != null) ) + if (isHotReload() && (_configPath != null)) { this._pathWatcher = new PathWatcher(); this._pathWatcher.watch(_configPath); @@ -335,18 +315,15 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener this._pathWatcher.setNotifyExistingOnStart(false); this._pathWatcher.start(); } - } - + @Override public void onPathWatchEvent(PathWatchEvent event) { try { if (LOG.isDebugEnabled()) - { - LOG.debug( "PATH WATCH EVENT: {}", event.getType() ); - } + LOG.debug("Path watch event: {}", event.getType()); loadUsers(); } catch (IOException e) @@ -355,10 +332,6 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener } } - /* ------------------------------------------------------------ */ - /** - * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop() - */ @Override protected void doStop() throws Exception { @@ -371,53 +344,45 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener /** * Notifies the registered listeners of potential updates to a user * - * @param username - * @param credential - * @param roleArray + * @param username the user that was updated + * @param credential the updated credentials + * @param roleArray the updated roles */ private void notifyUpdate(String username, Credential credential, String[] roleArray) { if (_listeners != null) { - for (Iterator i = _listeners.iterator(); i.hasNext();) - { - i.next().update(username,credential,roleArray); - } + for (UserListener _listener : _listeners) + _listener.update(username, credential, roleArray); } } /** - * notifies the registered listeners that a user has been removed. + * Notifies the registered listeners that a user has been removed. * - * @param username + * @param username the user that was removed */ private void notifyRemove(String username) { if (_listeners != null) { - for (Iterator i = _listeners.iterator(); i.hasNext();) - { - i.next().remove(username); - } + for (UserListener _listener : _listeners) + _listener.remove(username); } } /** - * registers a listener to be notified of the contents of the property file + * Registers a listener to be notified of the contents of the property file + * * @param listener the user listener */ public void registerUserListener(UserListener listener) { if (_listeners == null) - { - _listeners = new ArrayList(); - } + _listeners = new ArrayList<>(); _listeners.add(listener); } - /** - * UserListener - */ public interface UserListener { public void update(String username, Credential credential, String[] roleArray); diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/LoginAuthenticator.java b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/LoginAuthenticator.java index 6a2bfd6997a..17413a5d430 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/LoginAuthenticator.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/LoginAuthenticator.java @@ -40,62 +40,55 @@ public abstract class LoginAuthenticator implements Authenticator protected LoginService _loginService; protected IdentityService _identityService; private boolean _renewSession; - - - /* ------------------------------------------------------------ */ + protected LoginAuthenticator() { } - /* ------------------------------------------------------------ */ @Override public void prepareRequest(ServletRequest request) { //empty implementation as the default } - - /* ------------------------------------------------------------ */ - public UserIdentity login(String username, Object password, ServletRequest request) + public UserIdentity login(String username, Object password, ServletRequest servletRequest) { - UserIdentity user = _loginService.login(username,password, request); - if (user!=null) + UserIdentity user = _loginService.login(username, password, servletRequest); + if (user != null) { - renewSession((HttpServletRequest)request, (request instanceof Request? ((Request)request).getResponse() : null)); + Request request = Request.getBaseRequest(servletRequest); + renewSession(request, request == null ? null : request.getResponse()); return user; } return null; } - /* ------------------------------------------------------------ */ @Override public void setConfiguration(AuthConfiguration configuration) { - _loginService=configuration.getLoginService(); - if (_loginService==null) - throw new IllegalStateException("No LoginService for "+this+" in "+configuration); - _identityService=configuration.getIdentityService(); - if (_identityService==null) - throw new IllegalStateException("No IdentityService for "+this+" in "+configuration); - _renewSession=configuration.isSessionRenewedOnAuthentication(); + _loginService = configuration.getLoginService(); + if (_loginService == null) + throw new IllegalStateException("No LoginService for " + this + " in " + configuration); + _identityService = configuration.getIdentityService(); + if (_identityService == null) + throw new IllegalStateException("No IdentityService for " + this + " in " + configuration); + _renewSession = configuration.isSessionRenewedOnAuthentication(); } - - - /* ------------------------------------------------------------ */ + public LoginService getLoginService() { return _loginService; } - - - /* ------------------------------------------------------------ */ - /** Change the session id. + + /** + * Change the session id. * The session is changed to a new instance with a new ID if and only if:
    *
  • A session exists. *
  • The {@link org.eclipse.jetty.security.Authenticator.AuthConfiguration#isSessionRenewedOnAuthentication()} returns true. *
  • The session ID has been given to unauthenticated responses *
- * @param request the request + * + * @param request the request * @param response the response * @return The new session. */ @@ -103,13 +96,13 @@ public abstract class LoginAuthenticator implements Authenticator { HttpSession httpSession = request.getSession(false); - if (_renewSession && httpSession!=null) + if (_renewSession && httpSession != null) { synchronized (httpSession) { //if we should renew sessions, and there is an existing session that may have been seen by non-authenticated users //(indicated by SESSION_SECURED not being set on the session) then we should change id - if (httpSession.getAttribute(Session.SESSION_CREATED_SECURE)!=Boolean.TRUE) + if (httpSession.getAttribute(Session.SESSION_CREATED_SECURE) != Boolean.TRUE) { if (httpSession instanceof Session) { @@ -117,13 +110,15 @@ public abstract class LoginAuthenticator implements Authenticator String oldId = s.getId(); s.renewId(request); s.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE); - if (s.isIdChanged() && response != null && (response instanceof Response)) + if (s.isIdChanged() && (response instanceof Response)) ((Response)response).addCookie(s.getSessionHandler().getSessionCookie(s, request.getContextPath(), request.isSecure())); - LOG.debug("renew {}->{}",oldId,s.getId()); + if (LOG.isDebugEnabled()) + LOG.debug("renew {}->{}", oldId, s.getId()); } else - LOG.warn("Unable to renew session "+httpSession); - + { + LOG.warn("Unable to renew session " + httpSession); + } return httpSession; } } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherDemo.java b/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherDemo.java index e7008b1f996..36729d411e5 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherDemo.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/PathWatcherDemo.java @@ -62,22 +62,21 @@ public class PathWatcherDemo implements PathWatcher.Listener { PathWatcher watcher = new PathWatcher(); //watcher.addListener(new PathWatcherDemo()); - watcher.addListener (new PathWatcher.EventListListener(){ - - @Override - public void onPathWatchEvents(List events) - { - if (events == null) - LOG.warn("Null events received"); - if (events.isEmpty()) - LOG.warn("Empty events received"); - + watcher.addListener ((PathWatcher.EventListListener) events -> { + if (events == null) + { + LOG.warn("Null events received"); + } + else if (events.isEmpty()) + { + LOG.warn("Empty events received"); + } + else + { LOG.info("Bulk notification received"); - for (PathWatchEvent e:events) + for (PathWatchEvent e : events) onPathWatchEvent(e); - - } - + } }); watcher.setNotifyExistingOnStart(false); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java index 03ba85e50b1..36fe528fb50 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java @@ -18,29 +18,27 @@ package org.eclipse.jetty.util.thread; -import static org.hamcrest.MatcherAssert.assertThat; - import org.eclipse.jetty.util.ProcessorUtils; -import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool; -import org.hamcrest.Matcher; import org.hamcrest.Matchers; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public abstract class AbstractThreadPoolTest { private static int originalCoreCount; - @BeforeClass + @BeforeAll public static void saveState() { originalCoreCount = ProcessorUtils.availableProcessors(); } - @AfterClass + @AfterAll public static void restoreState() { ProcessorUtils.setAvailableProcessors(originalCoreCount); @@ -58,11 +56,11 @@ public abstract class AbstractThreadPoolTest try { pool.getThreadPoolBudget().leaseTo(this,3); - Assert.fail(); + fail(); } catch(IllegalStateException e) { - Assert.assertThat(e.getMessage(),Matchers.containsString("Insufficient configured threads")); + assertThat(e.getMessage(),Matchers.containsString("Insufficient configured threads")); } pool.getThreadPoolBudget().leaseTo(this,1); @@ -80,14 +78,14 @@ public abstract class AbstractThreadPoolTest try { pool.setMaxThreads(1); - Assert.fail(); + fail(); } catch(IllegalStateException e) { - Assert.assertThat(e.getMessage(),Matchers.containsString("Insufficient configured threads")); + assertThat(e.getMessage(),Matchers.containsString("Insufficient configured threads")); } - Assert.assertThat(pool.getMaxThreads(),Matchers.is(3)); + assertThat(pool.getMaxThreads(),Matchers.is(3)); } diff --git a/pom.xml b/pom.xml index be2a13a11dc..57979a63558 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ benchmarks 1.2.0 1.1.5 - 5.3.0 + 5.3.1 3.5.0 2.4.5.Final 1.0.5