Skip to content

Commit

Permalink
Fix jaas demos (#8689)
Browse files Browse the repository at this point in the history
* Fix jaas demos add distro test
  • Loading branch information
janbartel authored Oct 11, 2022
1 parent 3e78f82 commit 756cf21
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 48 deletions.
14 changes: 6 additions & 8 deletions jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-jaas-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,30 @@
<bundle-symbolic-name>${project.groupId}.jaas</bundle-symbolic-name>
</properties>
<build>
<pluginManagement>
<!--
<plugins>
<plugin>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<artifactId>jetty-ee10-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<scan>10</scan>
<systemProperties>
<!-- This is for convenience so that the src/etc/login.conf file can stay unmodified when copied to $jetty.home/etc directory -->
<jetty.base>${basedir}/src/main/config/modules/demo.d</jetty.base>
<!-- Mandatory. This system property tells JAAS where to find the login module configuration file -->
<java.security.auth.login.config>${basedir}/src/main/config/modules/demo.d/demo-login.conf</java.security.auth.login.config>
<java.security.auth.login.config>${basedir}/src/main/etc/ee10-demo-login.conf</java.security.auth.login.config>
</systemProperties>
<webApp>
<contextPath>/test-jaas</contextPath>
<contextPath>/ee10-test-jaas</contextPath>
<securityHandler implementation="org.eclipse.jetty.ee10.security.ConstraintSecurityHandler">
<loginService implementation="org.eclipse.jetty.ee10.jaas.JAASLoginService">
<name>Test JAAS Realm</name>
<loginModuleName>xyz</loginModuleName>
<loginModuleName>ee10-xyz</loginModuleName>
</loginService>
</securityHandler>
</webApp>
</configuration>
</plugin>
</plugins>
</pluginManagement>
-->
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Set name="loginService">
<New class="org.eclipse.jetty.ee10.jaas.JAASLoginService">
<Set name="name">Demo JAAS Realm</Set>
<Set name="loginModuleName">xyz</Set>
<Set name="loginModuleName">ee10-xyz</Set>
</New>
</Set>
</New>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ demo
webapp

[depends]
demo-jaas
ee10-deploy
ee10-jaas
jdbc
Expand All @@ -20,7 +21,6 @@ ext

[files]
basehome:modules/demo.d/ee10-demo-jaas.xml|webapps/ee10-demo-jaas.xml
basehome:modules/demo.d/ee10-demo-login.conf|etc/ee10-demo-login.conf
basehome:modules/demo.d/ee10-demo-login.properties|etc/ee10-demo-login.properties
maven://org.eclipse.jetty.ee10.demos/jetty-ee10-demo-jaas-webapp/${jetty.version}/war|webapps/ee10-demo-jaas.war

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xyz {
ee10-xyz {
org.eclipse.jetty.ee10.jaas.spi.PropertyFileLoginModule required
debug="true"
file="${jetty.base}/etc/ee10-demo-login.properties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ <h1>JAAS Demo</h1>
It uses a simple login module that stores its configuration in a properties file.
</p>

<h2>Preparation</h2>
<p>To use JAAS in a base jetty instance enable the <code>jaas</code> module:
<pre>
$ cd $JETTY_BASE
$ java -jar $JETTY_HOME/start.jar --add-module=jaas
</pre>

<h2>Using the Demo</h2>
<p>
Click on the link below to test JAAS <i>authentication</i> and role-based web security constraint <i>authorization</i>. Use
Expand Down
16 changes: 7 additions & 9 deletions jetty-ee8/jetty-ee8-demos/jetty-ee8-demo-jaas-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,30 @@
<bundle-symbolic-name>${project.groupId}.jaas</bundle-symbolic-name>
</properties>
<build>
<pluginManagement>
<!-- pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<groupId>org.eclipse.jetty.ee8</groupId>
<artifactId>jetty-ee8-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<scan>10</scan>
<systemProperties>
<!-- This is for convenience so that the src/etc/login.conf file can stay unmodified when copied to $jetty.home/etc directory -->
<jetty.base>${basedir}/src/main/config/modules/demo.d</jetty.base>
<!-- Mandatory. This system property tells JAAS where to find the login module configuration file -->
<java.security.auth.login.config>${basedir}/src/main/config/modules/demo.d/ee8-demo-login.conf</java.security.auth.login.config>
<java.security.auth.login.config>${basedir}/src/main/etc/ee8-demo-login.conf</java.security.auth.login.config>
</systemProperties>
<webApp>
<contextPath>/test-jaas</contextPath>
<securityHandler implementation="org.eclipse.jetty.security.ConstraintSecurityHandler">
<loginService implementation="org.eclipse.jetty.jaas.JAASLoginService">
<loginService implementation="org.eclipse.jetty.ee8.jaas.JAASLoginService">
<name>Test JAAS Realm</name>
<loginModuleName>xyz</loginModuleName>
<loginModuleName>ee8-xyz</loginModuleName>
</loginService>
</securityHandler>
</webApp>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</pluginManagement -->
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Set name="loginService">
<New class="org.eclipse.jetty.ee8.jaas.JAASLoginService">
<Set name="name">Demo JAAS Realm</Set>
<Set name="loginModuleName">xyz</Set>
<Set name="loginModuleName">ee8-xyz</Set>
</New>
</Set>
</New>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ demo
webapp

[depends]
demo-jaas
ee8-deploy
ee8-jaas
jdbc
Expand All @@ -21,7 +22,6 @@ ext
[files]
basehome:modules/demo.d/ee8-demo-jaas.xml|webapps/ee8-demo-jaas.xml
basehome:modules/demo.d/ee8-demo-jaas.properties|webapps/ee8-demo-jaas.properties
basehome:modules/demo.d/ee8-demo-login.conf|etc/ee8-demo-login.conf
basehome:modules/demo.d/ee8-demo-login.properties|etc/ee8-demo-login.properties
maven://org.eclipse.jetty.ee8.demos/jetty-ee8-demo-jaas-webapp/${jetty.version}/war|webapps/ee8-demo-jaas.war

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xyz {
ee8-xyz {
org.eclipse.jetty.ee8.jaas.spi.PropertyFileLoginModule required
debug="true"
file="${jetty.base}/etc/ee8-demo-login.properties";
Expand Down
14 changes: 6 additions & 8 deletions jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jaas-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,30 @@
<bundle-symbolic-name>${project.groupId}.jaas</bundle-symbolic-name>
</properties>
<build>
<pluginManagement>
<!-- pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<groupId>org.eclipse.jetty.ee9</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<scan>10</scan>
<systemProperties>
<!-- This is for convenience so that the src/etc/login.conf file can stay unmodified when copied to $jetty.home/etc directory -->
<jetty.base>${basedir}/src/main/config/modules/demo.d</jetty.base>
<!-- Mandatory. This system property tells JAAS where to find the login module configuration file -->
<java.security.auth.login.config>${basedir}/src/main/config/modules/demo.d/ee9-demo-login.conf</java.security.auth.login.config>
<java.security.auth.login.config>${basedir}/src/main/etc/ee9-demo-login.conf</java.security.auth.login.config>
</systemProperties>
<webApp>
<contextPath>/test-jaas</contextPath>
<securityHandler implementation="org.eclipse.jetty.security.ConstraintSecurityHandler">
<loginService implementation="org.eclipse.jetty.jaas.JAASLoginService">
<loginService implementation="org.eclipse.jetty.ee9.jaas.JAASLoginService">
<name>Test JAAS Realm</name>
<loginModuleName>xyz</loginModuleName>
<loginModuleName>ee9-xyz</loginModuleName>
</loginService>
</securityHandler>
</webApp>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</pluginManagement -->
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Set name="loginService">
<New class="org.eclipse.jetty.ee9.jaas.JAASLoginService">
<Set name="name">Demo JAAS Realm</Set>
<Set name="loginModuleName">xyz</Set>
<Set name="loginModuleName">ee9-xyz</Set>
</New>
</Set>
</New>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ demo
webapp

[depends]
demo-jaas
ee9-deploy
ee9-jaas
jdbc
Expand All @@ -21,7 +22,6 @@ ext
[files]
basehome:modules/demo.d/ee9-demo-jaas.xml|webapps/ee9-demo-jaas.xml
basehome:modules/demo.d/ee9-demo-jaas.properties|webapps/ee9-demo-jaas.properties
basehome:modules/demo.d/ee9-demo-login.conf|etc/ee9-demo-login.conf
basehome:modules/demo.d/ee9-demo-login.properties|etc/ee9-demo-login.properties
maven://org.eclipse.jetty.ee9.demos/jetty-ee9-demo-jaas-webapp/${jetty.version}/war|webapps/ee9-demo-jaas.war

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xyz {
ee9-xyz {
org.eclipse.jetty.ee9.jaas.spi.PropertyFileLoginModule required
debug="true"
file="${jetty.base}/etc/ee9-demo-login.properties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ <h1>JAAS Demo</h1>

It uses a simple login module that stores its configuration in a properties file.
</p>

<h2>Preparation</h2>
<p>To use JAAS in a base jetty instance enable the <code>jaas</code> module:
<pre>
$ cd $JETTY_BASE
$ java -jar $JETTY_HOME/start.jar --add-module=jaas
</pre>

<h2>Using the Demo</h2>
<p>
Expand Down
13 changes: 13 additions & 0 deletions jetty-home/src/main/resources/modules/demo-jaas.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html

[description]
Setup for jaas demos.

[environment]
core

[tags]
demo

[files]
basehome:modules/demo.d/demo-login.conf|etc/demo-login.conf
17 changes: 17 additions & 0 deletions jetty-home/src/main/resources/modules/demo.d/demo-login.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ee10-xyz {
org.eclipse.jetty.ee10.jaas.spi.PropertyFileLoginModule required
debug="true"
file="${jetty.base}/etc/ee10-demo-login.properties";
};

ee9-xyz {
org.eclipse.jetty.ee9.jaas.spi.PropertyFileLoginModule required
debug="true"
file="${jetty.base}/etc/ee9-demo-login.properties";
};

ee8-xyz {
org.eclipse.jetty.ee8.jaas.spi.PropertyFileLoginModule required
debug="true"
file="${jetty.base}/etc/ee8-demo-login.properties";
};
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,56 @@ public void testJspDump(String env) throws Exception
}
}
}

@ParameterizedTest
@MethodSource("provideEnvironmentsToTest")
public void testJaasDemo(String env) throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();

int httpPort = distribution.freePort();
int httpsPort = distribution.freePort();
assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort)));

String[] argsConfig = {
"--add-modules=http," + toEnvironment("demos", env)
};

String baseURI = "http://localhost:%d/%s-test-jaas".formatted(httpPort, env);

try (JettyHomeTester.Run runConfig = distribution.start(argsConfig))
{
assertTrue(runConfig.awaitFor(START_TIMEOUT, TimeUnit.SECONDS));
assertEquals(0, runConfig.getExitValue());

String[] argsStart =
{
"jetty.http.port=" + httpPort,
"jetty.httpConfig.port=" + httpsPort,
"jetty.ssl.port=" + httpsPort
};

try (JettyHomeTester.Run runStart = distribution.start(argsStart))
{
assertTrue(runStart.awaitConsoleLogsFor("Started oejs.Server@", START_TIMEOUT, TimeUnit.SECONDS));

startHttpClient();
ContentResponse response = client.GET(baseURI + "/auth.html");
Fields fields = new Fields();
fields.put("j_username", "me");
fields.put("j_password", "me");
response = client.FORM(baseURI + "/j_security_check", fields);
assertEquals(HttpStatus.OK_200, response.getStatus(), new ResponseDetails(response));;
assertThat(response.getContentAsString(), containsString("SUCCESS!"));
}
}
}

@ParameterizedTest
@MethodSource("provideEnvironmentsToTest")
Expand Down

0 comments on commit 756cf21

Please sign in to comment.