Skip to content

Commit e768eff

Browse files
committed
Initial commit for remote EJB SSL test
1 parent d86c786 commit e768eff

File tree

8 files changed

+191
-6
lines changed

8 files changed

+191
-6
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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"> <modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>org.javaee7</groupId>
6+
<artifactId>ejb-remote</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>ejb-remote-roles-allowed-ssl</artifactId>
11+
<packaging>war</packaging>
12+
13+
<name>Java EE 7 Sample: ejb - remote - Roles Allowed</name>
14+
15+
<profiles>
16+
<profile>
17+
<id>payara-ci-managed</id>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.javaee7.ejb.remote.vendor</groupId>
21+
<artifactId>ejb.remote.vendor.payara-glassfish</artifactId>
22+
<version>1.0-SNAPSHOT</version>
23+
</dependency>
24+
</dependencies>
25+
</profile>
26+
27+
<profile>
28+
<id>payara-remote</id>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.javaee7.ejb.remote.vendor</groupId>
32+
<artifactId>ejb.remote.vendor.payara-glassfish</artifactId>
33+
<version>1.0-SNAPSHOT</version>
34+
</dependency>
35+
</dependencies>
36+
</profile>
37+
38+
<profile>
39+
<id>glassfish-remote</id>
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.javaee7.ejb.remote.vendor</groupId>
43+
<artifactId>ejb.remote.vendor.payara-glassfish</artifactId>
44+
<version>1.0-SNAPSHOT</version>
45+
</dependency>
46+
</dependencies>
47+
</profile>
48+
</profiles>
49+
50+
51+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee7.ejb.remote.ssl;
3+
4+
import java.io.Serializable;
5+
6+
import javax.annotation.security.RolesAllowed;
7+
import javax.ejb.Stateless;
8+
9+
@Stateless
10+
public class Bean implements BeanRemote, Serializable {
11+
12+
private static final long serialVersionUID = 1L;
13+
14+
@Override
15+
@RolesAllowed("g1")
16+
public String method() {
17+
return "method";
18+
}
19+
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee7.ejb.remote.ssl;
3+
4+
import javax.ejb.Remote;
5+
6+
@Remote
7+
public interface BeanRemote {
8+
String method();
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE glassfish-ejb-jar PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN" "http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd">
3+
<glassfish-ejb-jar>
4+
<enterprise-beans>
5+
<ejb>
6+
<ejb-name>Bean</ejb-name>
7+
<ior-security-config>
8+
<transport-config>
9+
<integrity>REQUIRED</integrity>
10+
<confidentiality>REQUIRED</confidentiality>
11+
<establish-trust-in-target>SUPPORTED</establish-trust-in-target>
12+
<establish-trust-in-client>SUPPORTED</establish-trust-in-client>
13+
</transport-config>
14+
<as-context>
15+
<auth-method>USERNAME_PASSWORD</auth-method>
16+
<realm>default</realm>
17+
<required>true</required>
18+
</as-context>
19+
<sas-context>
20+
<caller-propagation>REQUIRED</caller-propagation>
21+
</sas-context>
22+
</ior-security-config>
23+
</ejb>
24+
</enterprise-beans>
25+
</glassfish-ejb-jar>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee7.ejb.remote.ssl;
3+
4+
import static org.javaee7.ServerOperations.addUsersToContainerIdentityStore;
5+
import static org.jboss.shrinkwrap.api.asset.EmptyAsset.INSTANCE;
6+
import static org.junit.Assert.assertEquals;
7+
import static org.junit.Assume.assumeTrue;
8+
9+
import javax.naming.Context;
10+
import javax.naming.NamingException;
11+
12+
import org.javaee7.RemoteEJBContextFactory;
13+
import org.javaee7.RemoteEJBContextProvider;
14+
import org.javaee7.ejb.remote.ssl.Bean;
15+
import org.javaee7.ejb.remote.ssl.BeanRemote;
16+
import org.jboss.arquillian.container.test.api.Deployment;
17+
import org.jboss.arquillian.container.test.api.RunAsClient;
18+
import org.jboss.arquillian.junit.Arquillian;
19+
import org.jboss.shrinkwrap.api.Archive;
20+
import org.jboss.shrinkwrap.api.ShrinkWrap;
21+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
22+
import org.junit.After;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
/**
28+
* This class demonstrates and tests how to request an EJB bean from a remote server.
29+
*
30+
* <p>
31+
* {@link RemoteEJBContextProvider} is used, which is a test artifact abstracting the different
32+
* ways this is done for different servers.
33+
*
34+
* @author Arjan Tijms
35+
*
36+
*/
37+
@RunWith(Arquillian.class)
38+
public class RemoteBeanTest {
39+
40+
private RemoteEJBContextProvider remoteEJBContextProvider;
41+
42+
@Deployment
43+
public static Archive<?> deployment() {
44+
45+
// Add user u1 with password p1 and group g1 to the container's native identity store
46+
addUsersToContainerIdentityStore();
47+
48+
return ShrinkWrap.create(JavaArchive.class)
49+
.addClasses(Bean.class, BeanRemote.class)
50+
.addAsManifestResource(INSTANCE, "beans.xml");
51+
}
52+
53+
@Before
54+
public void before() {
55+
remoteEJBContextProvider = RemoteEJBContextFactory.getProvider();
56+
assumeTrue(
57+
"No RemoteEJBContextProvider available in current profile",
58+
remoteEJBContextProvider != null);
59+
}
60+
61+
@After
62+
public void after() {
63+
remoteEJBContextProvider.releaseContext();
64+
}
65+
66+
@Test
67+
@RunAsClient
68+
public void callProtectedRemoteBean() throws NamingException {
69+
70+
// Obtain the JNDI naming context in a vendor specific way.
71+
Context ejbRemoteContext = remoteEJBContextProvider.getContextWithCredentialsSet("u1", "p1");
72+
73+
BeanRemote beanRemote = (BeanRemote) ejbRemoteContext.lookup("java:global/test/Bean");
74+
75+
assertEquals("method", beanRemote.method());
76+
}
77+
78+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create-file-user --groups g1 --passwordfile ${project.build.directory}/test-classes/password.txt u1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AS_ADMIN_USERPASSWORD=p1

ejb/remote/vendor/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
<!-- Copyright Payara Services Limited -->
44

55
<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"> <modelVersion>4.0.0</modelVersion>
6-
7-
<parent>
8-
<groupId>org.javaee7</groupId>
9-
<artifactId>ejb-remote</artifactId>
10-
<version>1.0-SNAPSHOT</version>
11-
</parent>
126

7+
<groupId>org.javaee7</groupId>
138
<artifactId>ejb-remote-vendor</artifactId>
9+
<version>1.0-SNAPSHOT</version>
1410
<packaging>pom</packaging>
1511

12+
<properties>
13+
<glassfish.client.version>5.0</glassfish.client.version>
14+
</properties>
15+
1616
<name>Java EE 7 Sample: ejb - remote - vendor</name>
1717

1818
<profiles>

0 commit comments

Comments
 (0)