Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jaas demos #8689

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

All the config files necessary were in the demo.d directory and copied to relevant places.
Why is now ee10-demo-login.conf an exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the ee10-demo-login-conf file still references module xyz but should be ee10-xyz.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I made the problem clean in the opening comment of the PR? The problem is that you cannot have more than one jaas config file, so all of the eeX-demo-login.conf files were being ignored. All of the jaas configuration must go into a single file.

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand ee8 demos are derived from ee9 demos with some Maven magic.
As such we should just change the ee9 files, not the ee8 ones?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demos cannot be derived from ee9 demos.
they are including some very differents jars etc...
so I couldn;t do it for demos.

<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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was removed from the eeX versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. As there can only be a single config file.

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";
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a core demo having eeX configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at jetty-home/src/main/resources/modules/demo.d/ you will see lots of other eeX related config files.

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