Skip to content

Commit 47af6d9

Browse files
committed
Added Tomcat remote profile and added condition to JASPIC tests for it.
Condition tests for skipping EJB, JSF, CDI and JACC integrations, and can thus be used to only test JASPIC (and Servlet) itself.
1 parent afe0405 commit 47af6d9

File tree

26 files changed

+485
-27
lines changed

26 files changed

+485
-27
lines changed

README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A brief instruction how to clone, build, import and run the samples on your loca
1212

1313
Only one container profile and one profile for browser can be active at a given time otherwise there will be dependency conflicts.
1414

15-
There are 10 available container profiles, for 5 different servers:
15+
There are 11 available container profiles, for 6 different servers:
1616

1717
* ``wildfly-managed-arquillian``
1818

@@ -115,8 +115,7 @@ There are 10 available container profiles, for 5 different servers:
115115
* ``weblogic-remote-arquillian``
116116

117117
This profile requires you to start up a WebLogic server outside of the build. Each sample will then
118-
reuse this instance to run the tests. NOTE: this has been tested on WebLogic 12.1.3, which is a Java EE 6 implementation,
119-
but it has some Java EE 7 features which can be optionally activated.
118+
reuse this instance to run the tests.
120119

121120
This profile requires you to set the location where WebLogic is installed via the ``weblogicRemoteArquillian_wlHome``
122121
system property. E.g.
@@ -129,15 +128,37 @@ There are 10 available container profiles, for 5 different servers:
129128
``-DweblogicRemoteArquillian_adminUserName=myuser``
130129
``-DweblogicRemoteArquillian_adminPassword=mypassword``
131130

132-
Some of the containers allow you to override the version used
131+
* ``tomcat-remote``
132+
133+
This profile requires you to start up a plain Tomcat (8.5 or 9) server outside of the build. Each sample will then
134+
reuse this instance to run the tests.
135+
136+
Tomcat supports samples that make use of Servlet, JSP, Expression Language (EL), WebSocket and JASPIC.
137+
138+
This profile requires you to enable JMX in Tomcat. This can be done by adding the following to ``[tomcat home]/bin/catalina.sh``:
139+
140+
```
141+
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8089 -Dcom.sun.management.jmxremote=true "
142+
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false "
143+
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
144+
JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=localhost "
145+
```
146+
147+
Be aware that this should *only* be done for a Tomcat instance that's used exclusively for testing, as the above will make
148+
the Tomcat installation **totally insecure!**
149+
150+
151+
152+
153+
The containers that download and install a server allow you to override the version used, e.g.:
133154

134-
* `-Dorg.wildfly=8.1.0.Final`
155+
* `-wildfly.version=8.1.0.Final`
135156

136-
This will change the version from 8.0.0 to 8.1.0.Final for WildFly.
157+
This will change the version from the current one (e.g. 10.1.0.Final) to 8.1.0.Final for WildFly.
137158

138159
* `-Dglassfish.version=4.1`
139160

140-
This will change the version from 4.1.1 to 4.1 for GlassFish testing purposes.
161+
This will change the version from the current one (e.g 4.1.1) to 4.1 for GlassFish testing purposes.
141162

142163
Similarly, there are 6 profiles to choose a browser to test on:
143164

@@ -191,9 +212,8 @@ There is just a bunch of things you should keep in mind before sending a pull re
191212

192213
Standard tests are jUnit based - for example [this commit](servlet/servlet-filters/src/test/java/org/javaee7/servlet/filters/FilterServletTest.java). Test classes naming must comply with surefire naming standards `**/*Test.java`, `**/*Test*.java` or `**/*TestCase.java`.
193214

194-
However, if you fancy something new, hip and fashionable it is perfectly legal to write Spock specifications as standard JavaEE integration test. For the sake of clarity and consistency, to minimize the upfront complexity, in this project we prefare standard jUnit test. However, some Spock example are provided in the `extra/spock-tests` folder - [like here](extra/spock-tests/src/test/java/org/javaee7/servlet/filters/FilterServletSpecification.groovy). The `spock-tests` project also showcases the Maven configuration. In this particular case the Groovy Specification files are included in the maven test phase if and only if you follow Spock naming convention and give your `Specification` suffix the magic will happen.
215+
For the sake of clarity and consistency, and to minimize the upfront complexity, we prefer standard jUnit tests using Java, with as additional helpers HtmlUnit, Hamcrest and of course Arquillian. Please don't use alternatives for these technologies. If any new dependency has to be introduced into this project it should provide something that's not covered by these existing dependencies.
195216

196-
The extras folder is not included by default, to limit Groovy dependency. If you want to import the extra samples in an Eclipse workspace (including the Spock tests), please install the [Groovy plugins for your Eclipse version](http://groovy.codehaus.org/Eclipse+Plugin) first, then import the sample projects you want using File>Import>Existing Maven Projects.
197217

198218
### Some coding principles ###
199219

@@ -209,9 +229,7 @@ That's it! Welcome in the community!
209229

210230
## CI Job ##
211231

212-
* [WildFly](https://javaee-support.ci.cloudbees.com/job/javaee7-samples-wildfly-8.1/)
213-
* [GlassFish](https://javaee-support.ci.cloudbees.com/job/javaee7-samples-glassfish-4.1/)
214-
* [TomEE](https://javaee-support.ci.cloudbees.com/job/javaee7-samples-tomee-2.0/)
232+
CI jobs are executed by [Travis](https://travis-ci.org/javaee-samples/javaee7-samples). Note that by the very nature of the samples provided here it's perfectly normal that not all tests pass. This normally would indicate a bug in the server on which the samples are executed. If you think it's really the test that's faulty, then please submit an issue or provide a PR with a fix.
215233

216234
## Run each sample in Docker
217235

jaspic/async-authentication/pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
<groupId>org.javaee7</groupId>
77
<artifactId>jaspic</artifactId>
88
<version>1.0-SNAPSHOT</version>
9-
<relativePath>../pom.xml</relativePath>
109
</parent>
11-
<groupId>org.javaee7</groupId>
10+
1211
<artifactId>jaspic-async-authentication</artifactId>
13-
<version>1.0-SNAPSHOT</version>
1412
<packaging>war</packaging>
1513
<name>Java EE 7 Sample: jaspic - async-authentication</name>
1614

@@ -21,4 +19,17 @@
2119
<version>1.0-SNAPSHOT</version>
2220
</dependency>
2321
</dependencies>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-surefire-plugin</artifactId>
28+
<configuration>
29+
<skipTests>${skipEJB}</skipTests>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
2435
</project>

jaspic/dispatching-jsf-cdi/pom.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
<groupId>org.javaee7</groupId>
77
<artifactId>jaspic</artifactId>
88
<version>1.0-SNAPSHOT</version>
9-
<relativePath>../pom.xml</relativePath>
109
</parent>
1110

12-
<groupId>org.javaee7</groupId>
1311
<artifactId>jaspic-dispatching-jsf-cdi</artifactId>
14-
<version>1.0-SNAPSHOT</version>
1512
<packaging>war</packaging>
1613
<name>Java EE 7 Sample: jaspic - dispatching JSF CDI</name>
1714

@@ -22,4 +19,17 @@
2219
<version>1.0-SNAPSHOT</version>
2320
</dependency>
2421
</dependencies>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-surefire-plugin</artifactId>
28+
<configuration>
29+
<skipTests>${skipJSF}</skipTests>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
2535
</project>

jaspic/ejb-propagation/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<groupId>org.javaee7</groupId>
77
<artifactId>jaspic</artifactId>
88
<version>1.0-SNAPSHOT</version>
9-
<relativePath>../pom.xml</relativePath>
109
</parent>
1110

1211
<artifactId>jaspic-ejb-propagation</artifactId>
@@ -20,4 +19,17 @@
2019
<version>1.0-SNAPSHOT</version>
2120
</dependency>
2221
</dependencies>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-surefire-plugin</artifactId>
28+
<configuration>
29+
<skipTests>${skipEJB}</skipTests>
30+
</configuration>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
2335
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.javaee7</groupId>
7+
<artifactId>jaspic</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>jaspic-ejb-register-session</artifactId>
12+
<packaging>war</packaging>
13+
14+
<name>Java EE 7 Sample: jaspic - ejb-register-session</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.javaee7</groupId>
19+
<artifactId>jaspic-common</artifactId>
20+
<version>1.0-SNAPSHOT</version>
21+
</dependency>
22+
</dependencies>
23+
24+
<build>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-surefire-plugin</artifactId>
29+
<configuration>
30+
<skipTests>${skipEJB}</skipTests>
31+
</configuration>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
36+
</project>

jaspic/register-session/src/main/java/org/javaee7/jaspic/registersession/ejb/ProtectedEJB.java renamed to jaspic/ejb-register-session/src/main/java/org/javaee7/jaspic/registersession/ejb/ProtectedEJB.java

File renamed without changes.

jaspic/register-session/src/main/java/org/javaee7/jaspic/registersession/ejb/PublicEJB.java renamed to jaspic/ejb-register-session/src/main/java/org/javaee7/jaspic/registersession/ejb/PublicEJB.java

File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.javaee7.jaspic.registersession.sam;
2+
3+
import java.security.Principal;
4+
5+
/**
6+
*
7+
* @author Arjan Tijms
8+
*
9+
*/
10+
public class MyPrincipal implements Principal {
11+
12+
private final String name;
13+
14+
public MyPrincipal(String name) {
15+
this.name = name;
16+
}
17+
18+
@Override
19+
public String getName() {
20+
return name;
21+
}
22+
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.javaee7.jaspic.registersession.sam;
2+
3+
import javax.servlet.ServletContextEvent;
4+
import javax.servlet.annotation.WebListener;
5+
6+
import org.javaee7.jaspic.common.BaseServletContextListener;
7+
import org.javaee7.jaspic.common.JaspicUtils;
8+
9+
/**
10+
*
11+
* @author Arjan Tijms
12+
*
13+
*/
14+
@WebListener
15+
public class SamAutoRegistrationListener extends BaseServletContextListener {
16+
17+
@Override
18+
public void contextInitialized(ServletContextEvent sce) {
19+
JaspicUtils.registerSAM(sce.getServletContext(), new TestServerAuthModule());
20+
}
21+
22+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package org.javaee7.jaspic.registersession.sam;
2+
3+
import static java.lang.Boolean.TRUE;
4+
import static javax.security.auth.message.AuthStatus.SUCCESS;
5+
6+
import java.io.IOException;
7+
import java.security.Principal;
8+
import java.util.Map;
9+
10+
import javax.security.auth.Subject;
11+
import javax.security.auth.callback.Callback;
12+
import javax.security.auth.callback.CallbackHandler;
13+
import javax.security.auth.callback.UnsupportedCallbackException;
14+
import javax.security.auth.message.AuthException;
15+
import javax.security.auth.message.AuthStatus;
16+
import javax.security.auth.message.MessageInfo;
17+
import javax.security.auth.message.MessagePolicy;
18+
import javax.security.auth.message.callback.CallerPrincipalCallback;
19+
import javax.security.auth.message.callback.GroupPrincipalCallback;
20+
import javax.security.auth.message.module.ServerAuthModule;
21+
import javax.servlet.http.HttpServletRequest;
22+
import javax.servlet.http.HttpServletResponse;
23+
24+
25+
/**
26+
*
27+
* @author Arjan Tijms
28+
*
29+
*/
30+
public class TestServerAuthModule implements ServerAuthModule {
31+
32+
private CallbackHandler handler;
33+
private Class<?>[] supportedMessageTypes = new Class[] { HttpServletRequest.class, HttpServletResponse.class };
34+
35+
@Override
36+
public void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler,
37+
@SuppressWarnings("rawtypes") Map options) throws AuthException {
38+
this.handler = handler;
39+
}
40+
41+
@SuppressWarnings("unchecked")
42+
@Override
43+
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
44+
throws AuthException {
45+
46+
HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
47+
Callback[] callbacks;
48+
49+
Principal userPrincipal = request.getUserPrincipal();
50+
if (userPrincipal != null && request.getParameter("continueSession") != null) {
51+
52+
// ### If already authenticated before, continue this session
53+
54+
// Execute protocol to signal container registered authentication session be used.
55+
callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, userPrincipal) };
56+
57+
} else if (request.getParameter("doLogin") != null) {
58+
59+
// ### If not authenticated before, do a new login if so requested
60+
61+
// For the test perform a login by directly "returning" the details of the authenticated user.
62+
// Normally credentials would be checked and the details fetched from some repository
63+
64+
callbacks = new Callback[] {
65+
// The name of the authenticated user
66+
67+
request.getParameter("customPrincipal") == null?
68+
// Name based Callback
69+
new CallerPrincipalCallback(clientSubject, "test") :
70+
71+
// Custom principal based Callback
72+
new CallerPrincipalCallback(clientSubject, new MyPrincipal("test")),
73+
74+
75+
// the roles of the authenticated user
76+
new GroupPrincipalCallback(clientSubject, new String[] { "architect" }) };
77+
78+
// Tell container to register an authentication session.
79+
messageInfo.getMap().put("javax.servlet.http.registerSession", TRUE.toString());
80+
} else {
81+
82+
// ### If no registered session and no login request "do nothing"
83+
84+
// The JASPIC protocol for "do nothing"
85+
callbacks = new Callback[] { new CallerPrincipalCallback(clientSubject, (Principal) null) };
86+
}
87+
88+
try {
89+
90+
// Communicate the details of the authenticated user to the container. In many
91+
// cases the handler will just store the details and the container will actually handle
92+
// the login after we return from this method.
93+
handler.handle(callbacks);
94+
95+
} catch (IOException | UnsupportedCallbackException e) {
96+
throw (AuthException) new AuthException().initCause(e);
97+
}
98+
99+
return SUCCESS;
100+
}
101+
102+
@Override
103+
public Class<?>[] getSupportedMessageTypes() {
104+
return supportedMessageTypes;
105+
}
106+
107+
@Override
108+
public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException {
109+
return AuthStatus.SEND_SUCCESS;
110+
}
111+
112+
@Override
113+
public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException {
114+
115+
}
116+
}

0 commit comments

Comments
 (0)