Merge branch 'jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
WalkerWatch 2018-09-18 10:54:36 -04:00
commit defa9e42f2
18 changed files with 396 additions and 195 deletions

View File

@ -88,7 +88,7 @@ Instead, you could redefine the DefaultServlet in your web.xml file, making sure
<web-app ...>
...
<servlet>
<servlet-name>Default</servlet-name>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>useFileMappedBuffer</param-name>
@ -97,9 +97,7 @@ Instead, you could redefine the DefaultServlet in your web.xml file, making sure
<load-on-startup>0</load-on-startup>
</servlet>
...
</web-app>
</web-app>
----
==== Alternate Remedy
@ -117,7 +115,6 @@ Configure this in an xml file like so:
.
.
</New>
----
____

View File

@ -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()

View File

@ -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)

View File

@ -10,6 +10,7 @@
<properties>
<jetty.version>@project.version@</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>

View File

@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test.jetty-maven-plugin-provided-module-dep</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
</project>

View File

@ -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()
{
}
}

View File

@ -0,0 +1,2 @@
invoker.goals = verify -V -e
#test-compile failsafe:integration-test

View File

@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.its</groupId>
<artifactId>it-parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>test.jetty-maven-plugin-provided-module-dep</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>api</module>
<module>web</module>
</modules>
</project>

View File

@ -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')

View File

@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test.jetty-maven-plugin-provided-module-dep</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>test-compile</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<nonBlocking>true</nonBlocking>
<jettyXml>${basedir}/src/config/jetty.xml</jettyXml>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,48 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme">https</Set>
<Set name="securePort">
<Property name="jetty.secure.port" default="8443"/>
</Set>
<Set name="outputBufferSize">32768</Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="responseHeaderSize">8192</Set>
<Set name="headerCacheSize">4096</Set>
</New>
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server">
<Ref refid="Server"/>
</Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config">
<Ref refid="httpConfig"/>
</Arg>
</New>
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
</New>
</Arg>
</Call>
<Set name="host">
<Property name="jetty.host"/>
</Set>
<Set name="port"><Property name="jetty.port" default="0"/>0
</Set>
<Set name="idleTimeout">30000</Set>
</New>
</Arg>
</Call>
</Configure>

View File

@ -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 )
{
}
}

View File

@ -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 <useProvidedScope> 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 <useProvidedScope> 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 " );
}

View File

@ -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
* <p>
* This class monitors a property file of the format mentioned below and notifies registered listeners of the changes to the the given file.
* <p>This class monitors a property file of the format mentioned below
* and notifies registered listeners of the changes to the the given file.</p>
*
* <pre>
* username: password [,rolename ...]
* </pre>
*
* Passwords may be clear text, obfuscated or checksummed. The class com.eclipse.Util.Password should be used to generate obfuscated passwords or password
* checksums.
* <p>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.</p>
*
* If DIGEST Authentication is used, the password must be in a recoverable format, either plain text or OBF:.
* <p>If DIGEST Authentication is used, the password must be in a recoverable
* format, either plain text or obfuscated.</p>
*/
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<UserListener> _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 <code>jar:file:</code>
*
* @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<String> currentlyKnownUsers = new ArrayList<String>(getKnownUserIdentities().keySet());
/*
*
* if its not the initial load then we want to process removed users
*/
List<String> currentlyKnownUsers = new ArrayList<>(getKnownUserIdentities().keySet());
// if its not the initial load then we want to process removed users
if (!_firstLoad)
{
Iterator<String> 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<UserListener> 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<UserListener> 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<UserListener>();
}
_listeners = new ArrayList<>();
_listeners.add(listener);
}
/**
* UserListener
*/
public interface UserListener
{
public void update(String username, Credential credential, String[] roleArray);

View File

@ -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:<ul>
* <li>A session exists.
* <li>The {@link org.eclipse.jetty.security.Authenticator.AuthConfiguration#isSessionRenewedOnAuthentication()} returns true.
* <li>The session ID has been given to unauthenticated responses
* </ul>
* @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;
}
}

View File

@ -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<PathWatchEvent> 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);

View File

@ -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));
}

View File

@ -33,7 +33,7 @@
<jmhjar.name>benchmarks</jmhjar.name>
<tycho-version>1.2.0</tycho-version>
<cbi-plugins.version>1.1.5</cbi-plugins.version>
<junit.version>5.3.0</junit.version>
<junit.version>5.3.1</junit.version>
<maven.version>3.5.0</maven.version>
<weld.version>2.4.5.Final</weld.version>
<jetty.perf-helper.version>1.0.5</jetty.perf-helper.version>