Skip to content

Commit 1bfa686

Browse files
committed
[WFLY-17649] Adds integration tests and github action workflow for ejb-security-jwt quickstart
1 parent a94a457 commit 1bfa686

File tree

7 files changed

+211
-0
lines changed

7 files changed

+211
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: WildFly EJB Security JWT Quickstart CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths:
7+
- 'ejb-security-jwt/**'
8+
- '.github/workflows/quickstart_ci.yml'
9+
10+
jobs:
11+
call-quickstart_ci:
12+
uses: ./.github/workflows/quickstart_ci.yml
13+
with:
14+
QUICKSTART_PATH: ejb-security-jwt
15+
TEST_PROVISIONED_SERVER: true
16+
TEST_OPENSHIFT: false
17+
MATRIX_OS: '"ubuntu-latest"'
18+
DEPLOYMENT_DIR: app-one/ear
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -x
3+
4+
# Start keycloak with required configuration
5+
docker run -d --rm --name "keycloak" \
6+
-p 8180:8080 \
7+
-e KEYCLOAK_ADMIN=admin \
8+
-e KEYCLOAK_ADMIN_PASSWORD=admin \
9+
-v ${GITHUB_WORKSPACE}/quickstarts/ejb-security-jwt/keycloak/realm:/opt/keycloak/data/import \
10+
quay.io/keycloak/keycloak:21.0.0 start-dev --import-realm

ejb-security-jwt/README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ We can see that the user `quickstartUser` has the `user` role, but does not have
312312

313313
We can also see that the invocation from EJBA to EJBB uses the same authentication context as what is used in remote client calls EJBA.
314314

315+
// Server Distribution Testing
316+
include::../shared-doc/run-integration-tests-with-server-distribution.adoc[leveloffset=+2]
317+
315318
== Undeploy the Archives
316319

317320
To undeploy the components from the {productName} servers:

ejb-security-jwt/app-one/ear/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<groupId>org.wildfly.quickstarts</groupId>
2323
<artifactId>ejb-security-jwt-app-one</artifactId>
2424
<version>31.0.0.Beta1-SNAPSHOT</version>
25+
<relativePath>../pom.xml</relativePath>
2526
</parent>
2627
<artifactId>ejb-security-jwt-app-one-ear</artifactId>
2728
<packaging>ear</packaging>
@@ -77,4 +78,47 @@
7778
</plugins>
7879
</build>
7980

81+
<profiles>
82+
<profile>
83+
<id>provisioned-server</id>
84+
<build>
85+
<plugins>
86+
<plugin>
87+
<groupId>org.wildfly.plugins</groupId>
88+
<artifactId>wildfly-maven-plugin</artifactId>
89+
<configuration>
90+
<feature-packs>
91+
<feature-pack>
92+
<location>org.wildfly:wildfly-galleon-pack:${version.server}</location>
93+
</feature-pack>
94+
</feature-packs>
95+
<layers>
96+
<layer>cloud-server</layer>
97+
<layer>ejb</layer>
98+
</layers>
99+
<name>${project.parent.artifactId}.ear</name>
100+
<packaging-scripts>
101+
<packaging-script>
102+
<java-opts>-Dejb-outbound-port=${ejb-outbound-port}</java-opts>
103+
<scripts>
104+
<script>${basedir}/../../configure-elytron.cli</script>
105+
<script>${basedir}/../../configure-ejb-outbound-connection.cli</script>
106+
</scripts>
107+
<resolve-expressions>true</resolve-expressions>
108+
</packaging-script>
109+
</packaging-scripts>
110+
</configuration>
111+
<executions>
112+
<execution>
113+
<goals>
114+
<goal>package</goal>
115+
</goals>
116+
</execution>
117+
</executions>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
</profile>
122+
</profiles>
123+
80124
</project>

ejb-security-jwt/client/pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
<artifactId>ejb-security-jwt-app-one-ejb</artifactId>
5454
<type>ejb-client</type>
5555
</dependency>
56+
57+
<!-- Test dependencies -->
58+
<dependency>
59+
<groupId>junit</groupId>
60+
<artifactId>junit</artifactId>
61+
<scope>test</scope>
62+
</dependency>
5663
</dependencies>
5764

5865
<build>
@@ -74,4 +81,31 @@
7481
</plugins>
7582
</build>
7683

84+
<profiles>
85+
<profile>
86+
<id>integration-testing</id>
87+
<build>
88+
<plugins>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-failsafe-plugin</artifactId>
92+
<configuration>
93+
<includes>
94+
<include>**/*IT</include>
95+
</includes>
96+
</configuration>
97+
<executions>
98+
<execution>
99+
<goals>
100+
<goal>integration-test</goal>
101+
<goal>verify</goal>
102+
</goals>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
</profile>
109+
</profiles>
110+
77111
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2023 JBoss by Red Hat.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jboss.as.quickstarts.ejb.security.jwt;
17+
18+
import org.jboss.as.quickstarts.ejb.security.jwt.appone.JWTSecurityEJBRemoteA;
19+
import org.jboss.as.quickstarts.ejb.security.jwt.client.RemoteEJBClient;
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.wildfly.security.auth.client.AuthenticationContext;
23+
24+
import javax.naming.NamingException;
25+
import java.io.IOException;
26+
27+
/**
28+
* Tests that
29+
*
30+
* @author <a href="mailto:[email protected]">Lin Gao</a>
31+
*/
32+
public class EJBSecurityJWTIT {
33+
private static final String DEFAULT_SERVER_HOST = "http://localhost:8080";
34+
35+
private String getProviderURl() {
36+
final String serverHost = System.getProperty("server.host");
37+
return "remote+" + (serverHost != null ? serverHost : DEFAULT_SERVER_HOST);
38+
}
39+
40+
@Test
41+
public void testRegular() throws NamingException {
42+
AuthenticationContext.getContextManager().setThreadDefault(null);
43+
JWTSecurityEJBRemoteA remoteA = RemoteEJBClient.lookupEJBRemoteA(true, getProviderURl());
44+
Assert.assertEquals("quickstartuser", remoteA.principal().toLowerCase());
45+
Assert.assertTrue(remoteA.inRole("user"));
46+
Assert.assertFalse(remoteA.inRole("admin"));
47+
Assert.assertTrue(remoteA.inRoleFromB("user", true));
48+
Assert.assertFalse(remoteA.inRoleFromB("admin", true));
49+
}
50+
51+
@Test
52+
public void testAdmin() throws IOException, NamingException {
53+
RemoteEJBClient.switchToAdmin();
54+
JWTSecurityEJBRemoteA remoteA = RemoteEJBClient.lookupEJBRemoteA(true, getProviderURl());
55+
Assert.assertEquals("admin", remoteA.principal().toLowerCase());
56+
Assert.assertTrue(remoteA.inRole("user"));
57+
Assert.assertTrue(remoteA.inRole("admin"));
58+
Assert.assertTrue(remoteA.inRoleFromB("user", true));
59+
Assert.assertTrue(remoteA.inRoleFromB("admin", true));
60+
}
61+
62+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ JBoss, Home of Professional Open Source.
5+
~ Copyright 2023 Red Hat, Inc., and individual contributors
6+
~ as indicated by the @author tags.
7+
~
8+
~ Licensed under the Apache License, Version 2.0 (the "License");
9+
~ you may not use this file except in compliance with the License.
10+
~ You may obtain a copy of the License at
11+
~
12+
~ http://www.apache.org/licenses/LICENSE-2.0
13+
~
14+
~ Unless required by applicable law or agreed to in writing, software
15+
~ distributed under the License is distributed on an "AS IS" BASIS,
16+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
~ See the License for the specific language governing permissions and
18+
~ limitations under the License.
19+
-->
20+
21+
<configuration>
22+
<authentication-client xmlns="urn:elytron:client:1.7">
23+
<authentication-rules>
24+
<rule use-configuration="default" />
25+
</authentication-rules>
26+
<authentication-configurations>
27+
<configuration name="default">
28+
<sasl-mechanism-selector selector="OAUTHBEARER" />
29+
<credentials>
30+
<oauth2-bearer-token token-endpoint-uri="http://localhost:8180/realms/jwt-realm/protocol/openid-connect/token">
31+
<resource-owner-credentials name="quickstartUser">
32+
<credential-store-reference clear-text="quickstartPwd1!" />
33+
</resource-owner-credentials>
34+
<client-credentials client-id="app" client-secret="secret"/>
35+
</oauth2-bearer-token>
36+
</credentials>
37+
</configuration>
38+
</authentication-configurations>
39+
</authentication-client>
40+
</configuration>

0 commit comments

Comments
 (0)