More tweaks for testing

+ Moved realm.properties to src/main/resources/etc/
+ Ensured that surefire's useManifestOnlyJar=false
  to enable taglibs to be found, and jstl to work.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-09-10 10:36:08 -05:00
parent e69ee7b147
commit 627ca1bb70
6 changed files with 51 additions and 17 deletions

View File

@ -155,6 +155,18 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useManifestOnlyJar>false</useManifestOnlyJar>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk9</id>

View File

@ -89,9 +89,11 @@ public class OneWebAppWithJsp
// its own we register it as a bean with the Jetty server object so it
// can be started and stopped according to the lifecycle of the server
// itself.
URL realmProps = OneWebAppWithJsp.class.getClassLoader().getResource("realm.properties");
String realmResourceName = "etc/realm.properties";
ClassLoader classLoader = OneWebAppWithJsp.class.getClassLoader();
URL realmProps = classLoader.getResource(realmResourceName);
if (realmProps == null)
throw new FileNotFoundException("Unable to find realm.properties");
throw new FileNotFoundException("Unable to find " + realmResourceName);
HashLoginService loginService = new HashLoginService();
loginService.setName("Test Realm");

View File

@ -48,10 +48,11 @@ public class SecuredHelloHandler
// started and stopped according to the lifecycle of the server itself.
// In this example the name can be whatever you like since we are not
// dealing with webapp realms.
String realmResourceName = "etc/realm.properties";
ClassLoader classLoader = SecuredHelloHandler.class.getClassLoader();
URL realmProps = classLoader.getResource("realm.properties");
URL realmProps = classLoader.getResource(realmResourceName);
if (realmProps == null)
throw new FileNotFoundException("Unable to find realm.properties");
throw new FileNotFoundException("Unable to find " + realmResourceName);
LoginService loginService = new HashLoginService("MyRealm",
realmProps.toExternalForm());

View File

@ -76,10 +76,11 @@ public class ServerWithAnnotations
server.addBean(new NamingDump());
// Configure a LoginService
String realmResourceName = "etc/realm.properties";
ClassLoader classLoader = ServerWithAnnotations.class.getClassLoader();
URL realmProps = classLoader.getResource("realm.properties");
URL realmProps = classLoader.getResource(realmResourceName);
if (realmProps == null)
throw new FileNotFoundException("Unable to find realm.properties");
throw new FileNotFoundException("Unable to find " + realmResourceName);
HashLoginService loginService = new HashLoginService();
loginService.setName("Test Realm");

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.embedded;
import javax.servlet.ServletException;
import javax.websocket.DeploymentException;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ -28,7 +26,6 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
/**
@ -49,23 +46,24 @@ public class WebSocketJsrServer
}
}
public static Server createServer(int port) throws DeploymentException, ServletException
public static Server createServer(int port)
{
Server server = new Server(port);
HandlerList handlers = new HandlerList();
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
handlers.addHandler(context);
// Enable javax.websocket configuration for the context
ServerContainer wsContainer = WebSocketServerContainerInitializer
.configureContext(context);
// Add your websockets to the container
wsContainer.addEndpoint(EchoJsrSocket.class);
WebSocketServerContainerInitializer.configure(context,
(servletContext, serverContainer) ->
{
// Add your websocket to the javax.websocket.server.ServerContainer
serverContainer.addEndpoint(EchoJsrSocket.class);
}
);
handlers.addHandler(new DefaultHandler());

View File

@ -0,0 +1,20 @@
#
# This file defines users passwords and roles for a HashUserRealm
#
# The format is
# <username>: <password>[,<rolename> ...]
#
# Passwords may be clear text, obfuscated or checksummed. The class
# 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:.
#
jetty:MD5:164c88b302622e17050af52c89945d44,user
admin:CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin,user
other:OBF:1xmk1w261u9r1w1c1xmq,user
plain:plain,user
user:password,user
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
digest:MD5:6e120743ad67abfbc385bc2bb754e297,user