@@ -110,7 +112,7 @@
org.wildfly.bom
wildfly-ee-with-tools
- ${version.server.bom}
+ ${version.bom.ee}
pom
import
@@ -144,44 +146,108 @@
jakarta.ejb-api
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+ provided
+
+
+
+
+ junit
+ junit
+ test
+
${project.artifactId}
-
-
-
- org.apache.maven.plugins
- maven-ejb-plugin
-
- 3.2
- true
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
-
- java
- ${project.build.directory}/exec-working-directory
-
-
- -classpath
-
- org.jboss.as.quickstarts.ejb_security_context_propagation.RemoteClient
-
-
-
-
-
- exec
-
-
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-ejb-plugin
+
+ 3.2
+ true
+
+
+
+ org.wildfly.plugins
+ wildfly-maven-plugin
+ ${version.plugin.wildfly}
+
+
+
+
+
+ provisioned-server
+
+
+
+ org.wildfly.plugins
+ wildfly-maven-plugin
+
+
+
+ org.wildfly:wildfly-galleon-pack:${version.server}
+
+
+
+
+ cloud-server
+ ejb
+
+
+
+
+
+
+
+
+ false
+
+
+
+ ROOT.war
+
+
+
+
+ package
+
+
+
+
+
+
+
+
+ integration-testing
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+ **/*IT
+
+
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+
+
+
diff --git a/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/EJBServlet.java b/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/EJBServlet.java
new file mode 100644
index 0000000000..b7d4104c11
--- /dev/null
+++ b/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/EJBServlet.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2023 JBoss by Red Hat.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.as.quickstarts.ejb_security_context_propagation;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+/**
+ *
+ * A simple servlet which indicates successful deployment of the quickstart.
+ *
+ *
+ *
+ * The servlet is registered and mapped to /ejb-security-context-propagation using the {@linkplain WebServlet
+ * @HttpServlet}.
+ *
+ *
+ * @author Prarthona Paul
+ *
+ */
+
+@WebServlet("/ejb-security-context-propagation")
+public class EJBServlet extends HttpServlet {
+
+ static String PAGE_HEADER = "ejb-security-context-propagation";
+
+ static String PAGE_FOOTER = "";
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.println(PAGE_HEADER);
+ writer.println("ejb-security-context-propagation quickstart deployed successfully. You can find the available operations in the included README file.");
+ writer.println(PAGE_FOOTER);
+ writer.close();
+ }
+}
\ No newline at end of file
diff --git a/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/IntermediateEJB.java b/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/IntermediateEJB.java
index e1dce496be..966b02e738 100644
--- a/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/IntermediateEJB.java
+++ b/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/IntermediateEJB.java
@@ -36,7 +36,7 @@
@PermitAll
public class IntermediateEJB implements IntermediateEJBRemote {
- @EJB(lookup="ejb:/ejb-security-context-propagation/SecuredEJB!org.jboss.as.quickstarts.ejb_security_context_propagation.SecuredEJBRemote")
+ @EJB
private SecuredEJBRemote remote;
@Resource
diff --git a/ejb-security-context-propagation/src/main/webapp/WEB-INF/beans.xml b/ejb-security-context-propagation/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000000..f418aba2f0
--- /dev/null
+++ b/ejb-security-context-propagation/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
diff --git a/ejb-security-context-propagation/src/main/webapp/index.html b/ejb-security-context-propagation/src/main/webapp/index.html
new file mode 100644
index 0000000000..09fa6ed02b
--- /dev/null
+++ b/ejb-security-context-propagation/src/main/webapp/index.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
diff --git a/ejb-security-context-propagation/src/test/java/org/jboss/as/quickstarts/ejb_security_context_propagation/BasicRuntimeIT.java b/ejb-security-context-propagation/src/test/java/org/jboss/as/quickstarts/ejb_security_context_propagation/BasicRuntimeIT.java
new file mode 100644
index 0000000000..1f87cdac82
--- /dev/null
+++ b/ejb-security-context-propagation/src/test/java/org/jboss/as/quickstarts/ejb_security_context_propagation/BasicRuntimeIT.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2023 JBoss by Red Hat.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.as.quickstarts.ejb_security_context_propagation;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.time.Duration;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * The very basic runtime integration testing.
+ * @author Prarthona Paul
+ * @author emartins
+ */
+public class BasicRuntimeIT {
+ private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/ejb-security-context-propagation";
+
+ @Test
+ public void testHTTPEndpointIsAvailable() throws IOException, InterruptedException, URISyntaxException {
+ String serverHost = System.getenv("SERVER_HOST");
+ if (serverHost == null) {
+ serverHost = System.getProperty("server.host");
+ }
+ if (serverHost == null) {
+ serverHost = DEFAULT_SERVER_HOST;
+ }
+ final HttpRequest request = HttpRequest.newBuilder()
+ .uri(new URI(serverHost+"/"))
+ .GET()
+ .build();
+ final HttpClient client = HttpClient.newBuilder()
+ .followRedirects(HttpClient.Redirect.ALWAYS)
+ .connectTimeout(Duration.ofMinutes(1))
+ .build();
+ final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ assertEquals(200, response.statusCode());
+ }
+}
diff --git a/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/RemoteClient.java b/ejb-security-context-propagation/src/test/java/org/jboss/as/quickstarts/ejb_security_context_propagation/SecurityContextPropagationIT.java
similarity index 71%
rename from ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/RemoteClient.java
rename to ejb-security-context-propagation/src/test/java/org/jboss/as/quickstarts/ejb_security_context_propagation/SecurityContextPropagationIT.java
index 58a1bb0b6c..8e6ca12bd2 100644
--- a/ejb-security-context-propagation/src/main/java/org/jboss/as/quickstarts/ejb_security_context_propagation/RemoteClient.java
+++ b/ejb-security-context-propagation/src/test/java/org/jboss/as/quickstarts/ejb_security_context_propagation/SecurityContextPropagationIT.java
@@ -1,13 +1,12 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2017, Red Hat, Inc. and/or its affiliates, and individual
- * contributors by the @authors tag. See the copyright.txt in the
- * distribution for a full listing of individual contributors.
+ * Copyright 2023 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,43 +15,47 @@
*/
package org.jboss.as.quickstarts.ejb_security_context_propagation;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
+import org.junit.Test;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
import org.wildfly.security.sasl.SaslMechanismSelector;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
/**
- * The remote client responsible for making invoking the intermediate bean to demonstrate security context propagation
- * in EJB to remote EJB calls.
- *
+ * The functional integration testing.
+ * @author emartins
* @author Stefan Guilhen
+ *
*/
-public class RemoteClient {
+public class SecurityContextPropagationIT {
- public static void main(String[] args) throws Exception {
+ @Test
+ public void testSecurityContextPropagation() throws NamingException {
+ // we assume standard dist, where EJBs are at ejb:/ejb-security-context-propagation/, if no SERVER_HOST or server.host in env/system props
+ final boolean standardDist = System.getenv("SERVER_HOST") == null && System.getProperty("server.host") == null;
+ System.out.println("standardDist: "+standardDist);
// invoke the intermediate bean using the identity configured in wildfly-config.xml
- invokeIntermediateBean();
-
+ invokeIntermediateBean(standardDist);
// now lets programmatically setup an authentication context to switch users before invoking the intermediate bean
AuthenticationConfiguration superUser = AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("PLAIN")).
useName("quickstartAdmin").usePassword("adminPwd1!");
final AuthenticationContext authCtx = AuthenticationContext.empty().with(MatchRule.ALL, superUser);
AuthenticationContext.getContextManager().setThreadDefault(authCtx);
- invokeIntermediateBean();
+ invokeIntermediateBean(standardDist);
}
- private static void invokeIntermediateBean() throws Exception {
+ private static void invokeIntermediateBean(boolean standardDist) throws NamingException {
final Hashtable jndiProperties = new Hashtable<>();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "remote+http://localhost:8080");
final Context context = new InitialContext(jndiProperties);
- IntermediateEJBRemote intermediate = (IntermediateEJBRemote) context.lookup("ejb:/ejb-security-context-propagation/IntermediateEJB!"
+ IntermediateEJBRemote intermediate = (IntermediateEJBRemote) context.lookup("ejb:/"+(standardDist?"ejb-security-context-propagation":"ROOT")+"/IntermediateEJB!"
+ IntermediateEJBRemote.class.getName());
System.out.println("\n\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
System.out.println(intermediate.makeRemoteCalls());
diff --git a/shared-doc/add-application-and-management-users.adoc b/shared-doc/add-application-and-management-users.adoc
index e99c11d6f0..cf911acf79 100644
--- a/shared-doc/add-application-and-management-users.adoc
+++ b/shared-doc/add-application-and-management-users.adoc
@@ -27,6 +27,11 @@ ifndef::admin-user-groups[]
:admin-group-list:
:admin-group-command:
endif::admin-user-groups[]
+
+// attr which other sections may check (ifdef) to know if users needs to be added
+:addQuickstartUser: true
+:addQuickstartAdmin: true
+
This quickstart uses secured management interfaces and requires that you create the following application user to access the running application.
[cols="20%,20%,20%,40%",options="headers"]
diff --git a/shared-doc/add-application-user.adoc b/shared-doc/add-application-user.adoc
index 87988ab46f..406fc7e1d8 100644
--- a/shared-doc/add-application-user.adoc
+++ b/shared-doc/add-application-user.adoc
@@ -17,6 +17,9 @@ ifndef::app-user-groups[]
:app-group-command:
endif::app-user-groups[]
+// attr which other sections may check (ifdef) to know if users needs to be added
+:addQuickstartUser: true
+
This quickstart uses secured application interfaces and requires that you create the following application user to access the running application.
[cols="20%,20%,20%,40%",options="headers"]
diff --git a/shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc b/shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc
index ffa7f03a1f..82119b6dbf 100644
--- a/shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc
+++ b/shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc
@@ -23,6 +23,30 @@ $ mvn {mavenServerProvisioningCommand} -Pprovisioned-server
The provisioned {productName} server, with the quickstart deployed, can then be found in the `target/server` directory, and its usage is similar to a standard server distribution, with the simplification that there is never the need to specify the server configuration to be started.
+ifdef::addQuickstartUser[]
+The quickstart user should be added before running the provisioned server:
+[source,subs="+quotes,attributes+",options="nowrap"]
+----
+$ target/server/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' {app-group-command}
+----
+[NOTE]
+====
+For Windows, use the `__{jbossHomeName}__\bin\add-user.bat` script.
+====
+endif::[]
+
+ifdef::addQuickstartAdmin[]
+The quickstart admin should be added before running the provisioned server:
+[source,subs="+quotes,attributes+",options="nowrap"]
+----
+$ target/server/bin/add-user.sh -a -u 'quickstartAdmin' -p 'adminPwd1!' {admin-group-command}
+----
+[NOTE]
+====
+For Windows, use the `__{jbossHomeName}__\bin\add-user.bat` script.
+====
+endif::[]
+
The server provisioning functionality is provided by the WildFly Maven Plugin, and you may find its configuration in the quickstart `pom.xml`:
[source,xml,subs="attributes+"]
diff --git a/shared-doc/run-integration-tests-with-provisioned-server.adoc b/shared-doc/run-integration-tests-with-provisioned-server.adoc
index 574eae2319..2aaa9082b3 100644
--- a/shared-doc/run-integration-tests-with-provisioned-server.adoc
+++ b/shared-doc/run-integration-tests-with-provisioned-server.adoc
@@ -14,7 +14,28 @@ Follow these steps to run the integration tests.
$ mvn clean package -Pprovisioned-server
----
-. Start the {productName} provisioned server, this time using the {productName} Maven Plugin, which is recommend for testing due to simpler automation. The path to the provisioned server should be specified using the `server.host` system property.
+ifdef::addQuickstartUser[]
+Add the quickstart user:
+[source,subs="+quotes,attributes+",options="nowrap"]
+----
+$ target/server/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' {app-group-command}
+----
+endif::[]
+
+ifdef::addQuickstartAdmin[]
+Add the quickstart admin:
+[source,subs="+quotes,attributes+",options="nowrap"]
+----
+$ target/server/bin/add-user.sh -a -u 'quickstartAdmin' -p 'adminPwd1!' {admin-group-command}
+----
+[NOTE]
+====
+For Windows, use the `__{jbossHomeName}__\bin\add-user.bat` script.
+====
+endif::[]
+
+
+. Start the {productName} provisioned server, this time using the {productName} Maven Plugin, which is recommended for testing due to simpler automation. The path to the provisioned server should be specified using the `server.host` system property.
+
[source,subs="attributes+",options="nowrap"]
----