Skip to content

Commit a693ff6

Browse files
authored
Receive session change notification test (#50)
1 parent 8974e12 commit a693ff6

11 files changed

Lines changed: 156 additions & 20 deletions

File tree

jee-agents-distribution/jee-agents-destribution-integration-tests/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>org.testcontainers</groupId>
6666
<artifactId>testcontainers</artifactId>
67-
<version>1.21.3</version>
67+
<version>2.0.5</version>
6868
<scope>test</scope>
6969
</dependency>
7070
<dependency>
@@ -96,6 +96,10 @@
9696
<artifactId>testng</artifactId>
9797
<scope>test</scope>
9898
</dependency>
99+
<dependency>
100+
<groupId>com.fasterxml.jackson.core</groupId>
101+
<artifactId>jackson-databind</artifactId>
102+
</dependency>
99103
<dependency>
100104
<groupId>org.assertj</groupId>
101105
<artifactId>assertj-core</artifactId>

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/AbstractIntegrationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
@@ -21,6 +21,7 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.testcontainers.DockerClientFactory;
24+
import org.testcontainers.Testcontainers;
2425
import org.testng.SkipException;
2526
import org.testng.annotations.BeforeClass;
2627

@@ -42,6 +43,8 @@ public abstract class AbstractIntegrationTest {
4243
} else {
4344
openamContainer = new OpenAmContainer();
4445
openamContainer.start();
46+
47+
Testcontainers.exposeHostPorts(8081);
4548
}
4649
}
4750

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/EmbeddedContainer_IT.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
@@ -25,13 +25,13 @@
2525
import org.eclipse.jetty.servlet.FilterHolder;
2626
import org.eclipse.jetty.servlet.ServletContextHandler;
2727
import org.eclipse.jetty.servlet.ServletHolder;
28-
import org.testcontainers.utility.MountableFile;
29-
import org.testng.annotations.BeforeClass;
28+
import org.openidentityplatform.identity.agents.filters.NotificationTestFilter;
3029
import org.testng.annotations.Test;
3130

3231
import java.io.IOException;
3332
import java.net.HttpURLConnection;
34-
import java.net.URL;
33+
import java.net.URI;
34+
import java.net.http.HttpRequest;
3535
import java.net.http.HttpResponse;
3636
import java.util.EnumSet;
3737

@@ -47,15 +47,18 @@ public void testJetty() throws Exception {
4747

4848
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
4949
context.setContextPath("/");
50+
context.addFilter(new FilterHolder(NotificationTestFilter.class), "/UpdateAgentCacheServlet", EnumSet.of(DispatcherType.REQUEST));
5051

5152
FilterHolder amFilterHolder = new FilterHolder(AmAgentFilter.class);
5253
amFilterHolder.setInitParameter("com.iplanet.am.naming.url", "http://openam.example.org:8080/openam/namingservice");
5354
amFilterHolder.setInitParameter("com.sun.identity.agents.app.username", "amadmin");
5455
amFilterHolder.setInitParameter("com.iplanet.am.service.secret", "passw0rd");
5556
amFilterHolder.setInitParameter("com.sun.identity.agents.config.profilename", "myAgent");
57+
amFilterHolder.setInitParameter("com.iplanet.am.cookie.name", "iPlanetDirectoryPro");
5658

5759
context.addFilter(amFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
5860

61+
5962
jetty.setHandler(context);
6063

6164
// Add your custom servlet
@@ -69,9 +72,27 @@ public void testJetty() throws Exception {
6972

7073
String token = getAuthenticationToken();
7174

75+
7276
HttpResponse<String> authResponse = callDemoServlet(token);
7377
assertThat(authResponse.statusCode()).isEqualTo(HttpURLConnection.HTTP_OK);
7478

79+
HttpRequest request = HttpRequest.newBuilder()
80+
.uri(URI.create("http://localhost:8080/openam/json/sessions/?_action=logout"))
81+
.header("Host", "openam.example.org:8080")
82+
.header("iPlanetDirectoryPro", token)
83+
.POST(HttpRequest.BodyPublishers.noBody())
84+
.build();
85+
86+
//logout
87+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
88+
assertThat(response.statusCode()).isEqualTo(HttpURLConnection.HTTP_OK);
89+
90+
HttpResponse<String> loggedOutTokenResponse = callDemoServlet(token);
91+
assertThat(loggedOutTokenResponse.statusCode()).isEqualTo(HttpURLConnection.HTTP_MOVED_TEMP);
92+
93+
//test received notifications
94+
assertThat(NotificationTestFilter.getReceivedRequests().size()).isNotZero();
95+
7596
jetty.stop();
7697

7798
}

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/Jetty11Container.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
1818

1919
import org.testcontainers.containers.FixedHostPortGenericContainer;
20-
import org.testcontainers.containers.Network;
2120
import org.testcontainers.containers.output.Slf4jLogConsumer;
2221
import org.testcontainers.containers.wait.strategy.Wait;
2322
import org.testcontainers.images.builder.Transferable;

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/Jetty12Container.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
1818

1919
import org.testcontainers.containers.FixedHostPortGenericContainer;
20-
import org.testcontainers.containers.Network;
2120
import org.testcontainers.containers.output.Slf4jLogConsumer;
2221
import org.testcontainers.containers.wait.strategy.Wait;
2322
import org.testcontainers.images.builder.Transferable;

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/OpenAmContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
@@ -96,6 +96,7 @@ public OpenAmContainer() {
9696
container = new FixedHostPortGenericContainer<>(TEST_IMAGE_NAME_WITH_TAG)
9797
.withFixedExposedPort(8080, 8080)
9898
.withExposedPorts(8080)
99+
.withAccessToHost(true)
99100
.withNetwork(Network.SHARED)
100101
.withImagePullPolicy(new NeverPullPolicy())
101102
.withLogConsumer(new Slf4jLogConsumer(logger))

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/Tomcat10Container.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
1818

1919
import org.testcontainers.containers.FixedHostPortGenericContainer;
20-
import org.testcontainers.containers.Network;
2120
import org.testcontainers.containers.output.Slf4jLogConsumer;
2221
import org.testcontainers.containers.wait.strategy.Wait;
2322
import org.testcontainers.images.builder.Transferable;
@@ -42,7 +41,7 @@ public Tomcat10Container() {
4241
.withCopyToContainer(
4342
MountableFile.forClasspathResource("docker/tomcat/10/web.xml"),
4443
"/usr/local/tomcat/conf/web.xml")
45-
.waitingFor(Wait.forHttp("/demo/").forPort(8080));;
44+
.waitingFor(Wait.forHttp("/demo/").forPort(8080));
4645
}
4746

4847
@Override

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/Tomcat11Container.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
1818

1919
import org.testcontainers.containers.FixedHostPortGenericContainer;
20-
import org.testcontainers.containers.Network;
2120
import org.testcontainers.containers.output.Slf4jLogConsumer;
2221
import org.testcontainers.containers.wait.strategy.Wait;
2322
import org.testcontainers.images.builder.Transferable;

jee-agents-distribution/jee-agents-destribution-integration-tests/src/test/java/org/openidentityplatform/identity/agents/WebContainer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
* Header, with the fields enclosed by brackets [] replaced by your own identifying
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
14-
* Copyright 2025 3A Systems LLC.
14+
* Copyright 2025-2026 3A Systems LLC.
1515
*/
1616

1717
package org.openidentityplatform.identity.agents;
1818

19-
import org.junit.runner.Description;
20-
import org.junit.runners.model.Statement;
2119
import org.slf4j.Logger;
2220
import org.slf4j.LoggerFactory;
2321
import org.testcontainers.containers.GenericContainer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* The contents of this file are subject to the terms of the Common Development and
3+
* Distribution License (the License). You may not use this file except in compliance with the
4+
* License.
5+
*
6+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+
* specific language governing permission and limitations under the License.
8+
*
9+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
10+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
12+
* information: "Portions copyright [year] [name of copyright owner]".
13+
*
14+
* Copyright 2026 3A Systems LLC.
15+
*/
16+
17+
package org.openidentityplatform.identity.agents.filters;
18+
19+
import jakarta.servlet.Filter;
20+
import jakarta.servlet.FilterChain;
21+
import jakarta.servlet.FilterConfig;
22+
import jakarta.servlet.ReadListener;
23+
import jakarta.servlet.ServletException;
24+
import jakarta.servlet.ServletInputStream;
25+
import jakarta.servlet.ServletRequest;
26+
import jakarta.servlet.ServletResponse;
27+
import jakarta.servlet.http.HttpServletRequest;
28+
import jakarta.servlet.http.HttpServletRequestWrapper;
29+
import org.apache.commons.lang.StringUtils;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
33+
import java.io.BufferedReader;
34+
import java.io.ByteArrayInputStream;
35+
import java.io.IOException;
36+
import java.io.InputStreamReader;
37+
import java.nio.charset.StandardCharsets;
38+
import java.util.ArrayList;
39+
import java.util.Collections;
40+
import java.util.List;
41+
42+
public class NotificationTestFilter implements Filter {
43+
private static final Logger log = LoggerFactory.getLogger(NotificationTestFilter.class);
44+
45+
private static final List<String> receivedRequests = Collections.synchronizedList(new ArrayList<>());
46+
47+
public static List<String> getReceivedRequests() {
48+
return new ArrayList<>(receivedRequests);
49+
}
50+
@Override
51+
public void init(FilterConfig filterConfig) {}
52+
53+
@Override
54+
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
55+
throws IOException, ServletException {
56+
57+
if (request instanceof HttpServletRequest) {
58+
CachedBodyHttpServletRequest wrappedRequest =
59+
new CachedBodyHttpServletRequest((HttpServletRequest) request);
60+
61+
String body = new String(wrappedRequest.getCachedBody(), StandardCharsets.UTF_8);
62+
log.info("Incoming request: method={}, uri={}, body={}",
63+
wrappedRequest.getMethod(),
64+
wrappedRequest.getRequestURI(),
65+
body.isEmpty() ? "<empty>" : body);
66+
if(StringUtils.isNotBlank(body)) {
67+
receivedRequests.add(body);
68+
}
69+
chain.doFilter(wrappedRequest, response);
70+
} else {
71+
chain.doFilter(request, response);
72+
}
73+
}
74+
75+
@Override
76+
public void destroy() {}
77+
78+
/**
79+
* Wraps the request so the body can be read multiple times.
80+
*/
81+
static class CachedBodyHttpServletRequest extends HttpServletRequestWrapper {
82+
83+
private final byte[] cachedBody;
84+
85+
CachedBodyHttpServletRequest(HttpServletRequest request) throws IOException {
86+
super(request);
87+
this.cachedBody = request.getInputStream().readAllBytes();
88+
}
89+
90+
byte[] getCachedBody() {
91+
return cachedBody;
92+
}
93+
94+
@Override
95+
public ServletInputStream getInputStream() {
96+
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(cachedBody);
97+
return new ServletInputStream() {
98+
@Override public int read() { return byteArrayInputStream.read(); }
99+
@Override public boolean isFinished() { return byteArrayInputStream.available() == 0; }
100+
@Override public boolean isReady() { return true; }
101+
@Override public void setReadListener(ReadListener listener) {}
102+
};
103+
}
104+
105+
@Override
106+
public BufferedReader getReader() {
107+
return new BufferedReader(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8));
108+
}
109+
}
110+
111+
112+
}
113+

0 commit comments

Comments
 (0)