Skip to content

Commit bdd1710

Browse files
committed
Merge branch '42crosssec' into 'release/4.2'
Cross domain distributed transaction using CrossDomainSecurity inside k8s See merge request weblogic-cloud/weblogic-kubernetes-operator!4806
2 parents 54e3ffd + 7740b40 commit bdd1710

File tree

12 files changed

+903
-0
lines changed

12 files changed

+903
-0
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItCrossDomainTransactionSecurity.java

Lines changed: 528 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Created-By: 1.8.0_201 (Oracle Corporation)
3+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2024, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
7+
<description>JSP 2.0 Expression Language Example</description>
8+
<display-name>JSP 2.0 Expression Language Example</display-name>
9+
<module>
10+
<web>
11+
<web-uri>sample_war</web-uri>
12+
<context-root>sample_war</context-root>
13+
</web>
14+
</module>
15+
</application>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2024, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90">
7+
</weblogic-application>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2024, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
7+
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">
8+
9+
</web-app>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<!--
3+
Copyright (c) 2024, Oracle and/or its affiliates.
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
-->
6+
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
7+
<session-descriptor>
8+
<timeout-secs>15</timeout-secs>
9+
<invalidation-interval-secs>60</invalidation-interval-secs>
10+
</session-descriptor>
11+
<jsp-descriptor>
12+
<page-check-seconds>1</page-check-seconds>
13+
<verbose>true</verbose>
14+
</jsp-descriptor>
15+
</weblogic-web-app>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!--
2+
Copyright (c) 2024, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
-->
5+
<%@ page import="java.io.IOException" %>
6+
<%@ page import="java.util.Hashtable" %>
7+
<%@ page import="javax.naming.Context" %>
8+
<%@ page import="javax.naming.InitialContext" %>
9+
<%@ page import="javax.naming.NamingException" %>
10+
<%@ page import="javax.servlet.ServletException" %>
11+
<%@ page import="javax.servlet.annotation.WebServlet" %>
12+
<%@ page import="javax.servlet.http.HttpServlet" %>
13+
<%@ page import="javax.servlet.http.HttpServletRequest" %>
14+
<%@ page import="javax.servlet.http.HttpServletResponse" %>
15+
<%@ page import="javax.servlet.http.HttpServletResponse" %>
16+
<%@ page import="javax.jms.Destination" %>
17+
<%@ page import="javax.jms.ConnectionFactory" %>
18+
<%@ page import="javax.jms.JMSContext" %>
19+
<%@ page import="javax.jms.Message" %>
20+
<%@ page import="javax.jms.JMSConsumer" %>
21+
<%@ page import="javax.jms.QueueBrowser" %>
22+
<%@ page import="weblogic.transaction.TransactionHelper" %>
23+
<%@ page import="weblogic.transaction.TransactionManager" %>
24+
<%@ page import="javax.transaction.UserTransaction" %>
25+
26+
<%
27+
try {
28+
Context lctx = null;
29+
Context rctx = null;
30+
String remoteurl = request.getParameter("remoteurl");
31+
out.println("#### Remote URL is ["+remoteurl+"]");
32+
String action = request.getParameter("action");
33+
out.println("#### Transcation action ["+action+"]");
34+
35+
lctx = new InitialContext();
36+
out.println("(Local) Got JNDI Context successfully ["+lctx+"]");
37+
TransactionHelper tranhelp =TransactionHelper.getTransactionHelper();
38+
UserTransaction ut = tranhelp.getUserTransaction();
39+
40+
ConnectionFactory qcf=
41+
(ConnectionFactory)lctx.lookup("weblogic.jms.XAConnectionFactory");
42+
out.println("(Local) JMS ConnectionFactory lookup successful ...");
43+
JMSContext context = qcf.createContext();
44+
out.println("(Local) JMS Context created successfully ...");
45+
Destination queue = (Destination)lctx.lookup("jms.admin.adminQueue");
46+
out.println("(Local) JMS Destination (jms.admin.adminQueue) lookup successful ...");
47+
48+
if ( ! action.equals("notx") ) {
49+
out.println("Started a user transaction");
50+
ut.begin();
51+
}
52+
53+
// Send message to local Destination
54+
context.createProducer().send(queue, "Message to a Local Destination");
55+
lctx.close();
56+
57+
Hashtable env = new Hashtable();
58+
env.put(Context.INITIAL_CONTEXT_FACTORY,
59+
"weblogic.jndi.WLInitialContextFactory");
60+
env.put(Context.PROVIDER_URL, remoteurl);
61+
// Remote anonymous RMI access via T3 not allowed
62+
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
63+
env.put(Context.SECURITY_CREDENTIALS, "welcome1");
64+
rctx = new InitialContext(env);
65+
out.println("(Remote) Got JNDI Context successfully ["+rctx+"]");
66+
67+
// lookup JMS XAConnectionFactory
68+
ConnectionFactory qcf2=
69+
(ConnectionFactory)rctx.lookup("jms/ClusterConnectionFactory");
70+
out.println("(Remote) JMS ConnectionFactory lookup successful");
71+
72+
JMSContext context2 = qcf2.createContext();
73+
out.println("(Remote) JMS Context created successfully");
74+
Destination queue2 = (Destination)rctx.lookup("jms.testUniformQueue");
75+
out.println("(Remote) JMS Destination (jms.testUniformQueue) lookup successful ");
76+
77+
for (int i=0; i<10; i++)
78+
context2.createProducer().send(queue2, "Message to a Remote Destination");
79+
rctx.close();
80+
81+
// Get the live context from Tx Coordinator before closing transaction
82+
// Context ctx = new InitialContext(env);
83+
84+
if ( action.equals("commit") ) {
85+
out.println(ut);
86+
ut.commit();
87+
out.println("#### Message sent in a commit User Transation");
88+
} else if ( action.equals("rollback")) {
89+
out.println(ut);
90+
ut.rollback();
91+
out.println("#### Message sent in a rolled-back User Transation");
92+
} else {
93+
out.println("#### Message sent w/o Transaction");
94+
}
95+
} catch(Exception e) {
96+
out.println("#### Got an Exception [" +e+"]");
97+
}
98+
%>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!--
2+
Copyright (c) 2024, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
-->
5+
<%@ page import="java.io.IOException" %>
6+
<%@ page import="java.util.Hashtable" %>
7+
<%@ page import="javax.naming.Context" %>
8+
<%@ page import="javax.naming.InitialContext" %>
9+
<%@ page import="javax.naming.NamingException" %>
10+
<%@ page import="javax.servlet.ServletException" %>
11+
<%@ page import="javax.servlet.annotation.WebServlet" %>
12+
<%@ page import="javax.servlet.http.HttpServlet" %>
13+
<%@ page import="javax.servlet.http.HttpServletRequest" %>
14+
<%@ page import="javax.servlet.http.HttpServletResponse" %>
15+
<%@ page import="javax.servlet.http.HttpServletResponse" %>
16+
<%@ page import="javax.jms.Destination" %>
17+
<%@ page import="javax.jms.ConnectionFactory" %>
18+
<%@ page import="javax.jms.JMSContext" %>
19+
<%@ page import="javax.jms.Message" %>
20+
<%@ page import="javax.jms.JMSConsumer" %>
21+
<%@ page import="javax.jms.QueueBrowser" %>
22+
23+
<%
24+
try {
25+
Context ctx = null;
26+
27+
String remoteurl = request.getParameter("remoteurl");
28+
out.println("Remote URL is [" + remoteurl + "]");
29+
30+
String action = request.getParameter("action");
31+
out.println("action [" + action + "]");
32+
33+
String dest = request.getParameter("dest");
34+
out.println("Destination [" + dest + "]");
35+
36+
Hashtable env = new Hashtable();
37+
env.put(Context.INITIAL_CONTEXT_FACTORY,
38+
"weblogic.jndi.WLInitialContextFactory");
39+
env.put(Context.PROVIDER_URL, remoteurl);
40+
// Remote anonymous RMI access via T3 not allowed
41+
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
42+
env.put(Context.SECURITY_CREDENTIALS, "welcome1");
43+
ctx = new InitialContext(env);
44+
out.println("Got Remote Context successfully");
45+
46+
// lookup JMS XAConnectionFactory
47+
ConnectionFactory qcf=
48+
(ConnectionFactory)ctx.lookup("weblogic.jms.XAConnectionFactory");
49+
out.println("JMS ConnectionFactory lookup Successful ...");
50+
51+
JMSContext context = qcf.createContext();
52+
out.println("JMS Context Created Successfully ...");
53+
Destination queue = (Destination)ctx.lookup(dest);
54+
out.println("JMS Destination lookup Successful ...");
55+
56+
if ( action.equals("send") ) {
57+
context.createProducer().send(queue, "Message to a Destination");
58+
out.println("Message sent to the JMS Destination");
59+
}
60+
61+
if ( action.equals("recv") ) {
62+
JMSConsumer consumer = (JMSConsumer) context.createConsumer(queue);
63+
out.println("JMS Consumer Created Successfully ..");
64+
Message msg=null;
65+
int count = 0;
66+
do {
67+
msg = consumer.receiveNoWait();
68+
if ( msg != null ) {
69+
// out.println("Message Drained ["+msg+"]");
70+
// out.println("Message Drained ["+msg.getBody(String.class)+"]");
71+
count++;
72+
}
73+
} while( msg != null);
74+
out.println("Total Message(s) Received : " + count);
75+
}
76+
77+
} catch(Exception e) {
78+
out.println("Got an Exception [" + e + "]");
79+
}
80+
%>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2024, Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
domainInfo:
4+
AdminUserName: '@@SECRET:__weblogic-credentials__:username@@'
5+
AdminPassword: '@@SECRET:__weblogic-credentials__:password@@'
6+
ServerStartMode: 'prod'
7+
WLSUserPasswordCredentialMappings:
8+
CrossDomain:
9+
map1:
10+
RemoteDomain: '@@PROP:REMOTE_DOMAIN@@'
11+
RemoteUser: xdomain
12+
RemotePassword: '@@SECRET:__weblogic-credentials__:password@@'
13+
14+
topology:
15+
Name: '@@PROP:DOMAIN_UID@@'
16+
AdminServerName: "@@PROP:ADMIN_SERVER_NAME@@"
17+
SecurityConfiguration:
18+
CrossDomainSecurityEnabled: true
19+
Security:
20+
User:
21+
xdomain:
22+
Name: xdomain
23+
Password: '@@SECRET:__weblogic-credentials__:password@@'
24+
GroupMemberOf:
25+
- CrossDomainConnectors
26+
Cluster:
27+
"@@PROP:CLUSTER_NAME@@":
28+
DynamicServers:
29+
ServerTemplate: "@@PROP:CLUSTER_NAME@@-template"
30+
ServerNamePrefix: "@@PROP:MANAGED_SERVER_BASE_NAME@@"
31+
DynamicClusterSize: "@@PROP:MANAGED_SERVER_COUNT@@"
32+
MaxDynamicClusterSize: "@@PROP:MANAGED_SERVER_COUNT@@"
33+
CalculatedListenPorts: false
34+
Server:
35+
"@@PROP:ADMIN_SERVER_NAME@@":
36+
ListenPort: 7001
37+
NetworkAccessPoint:
38+
T3Channel:
39+
ListenPort: '@@PROP:T3CHANNELPORT@@'
40+
PublicAddress: '@@PROP:T3PUBLICADDRESS@@'
41+
PublicPort: '@@PROP:T3CHANNELPORT@@'
42+
ServerTemplate:
43+
"@@PROP:CLUSTER_NAME@@-template":
44+
Cluster: "@@PROP:CLUSTER_NAME@@"
45+
ListenPort : '@@PROP:MANAGED_SERVER_PORT@@'
46+
resources:
47+
WebAppContainer:
48+
WeblogicPluginEnabled: true
49+
appDeployments:
50+
Application:
51+
myear:
52+
SourcePath: wlsdeploy/applications/crossdomainsec.ear
53+
ModuleType: ear
54+
Target: '@@PROP:CLUSTER_NAME@@,@@PROP:ADMIN_SERVER_NAME@@'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024, Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
appDeployments:
4+
Application:
5+
myear:
6+
SourcePath: wlsdeploy/applications/crossdomainsec.ear
7+
ModuleType: ear
8+
Target: '@@PROP:CLUSTER_NAME@@,@@PROP:ADMIN_SERVER_NAME@@'

0 commit comments

Comments
 (0)