ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.



Similar documents
! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer

Network Communication

Remote Method Invocation

Brazil + JDBC Juin 2001, douin@cnam.fr

Network/Socket Programming in Java. Rajkumar Buyya

Programmation RMI Sécurisée

Remote Method Invocation

TP N 10 : Gestion des fichiers Langage JAVA

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Cours. Client/serveur avancé en Java (servlets, RMI, etc.) M.M.F.A.I. François Bourdoncle

Socket Programming in Java

Remote Method Invocation in JAVA

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Java Network. Slides prepared by : Farzana Rahman

TP : Système de messagerie - Fichiers properties - PrepareStatement

Assignment 4 Solutions

Lesson: All About Sockets

Creating a Simple, Multithreaded Chat System with Java

Remote Method Invocation (RMI)

POB-JAVA Documentation

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Licence Informatique Année Exceptions

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

Chapter 2 Introduction to Java programming

public static void main(string[] args) { System.out.println("hello, world"); } }

C:\Documents and Settings\Gijs\Desktop\src\client\Client.java dinsdag 3 november :50

Langages Orientés Objet Java

Programmation Orientée Objets. et langage Java

!"# $ %!&' # &! ())*!$

JAVA Program For Processing SMS Messages

Liste d'adresses URL

Division of Informatics, University of Edinburgh

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

2 RENSEIGNEMENTS CONCERNANT L ASSURÉ SI CELUI-CI N EST PAS LE REQUÉRANT INFORMATION CONCERNING THE INSURED PERSON IF OTHER THAN THE APPLICANT

Remote Method Invocation

TP JSP : déployer chaque TP sous forme d'archive war

Advanced Network Programming Lab using Java. Angelos Stavrou

NETWORK PROGRAMMING IN JAVA USING SOCKETS

OBJECT ORIENTED PROGRAMMING LANGUAGE

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Mail User Agent Project

Java Programming Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Note concernant votre accord de souscription au service «Trusted Certificate Service» (TCS)

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Les Broadcast Receivers...

Thursday, February 7, DOM via PHP

The Java Series Introduction to Java RMI and CORBA. The Java Series. Java RMI and CORBA Raul RAMOS / CERN-IT User Support Slide 1

An Overview of Java. overview-1

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

An Android-based Instant Message Application

Building a Multi-Threaded Web Server

Annexe - OAuth Introduction. Xavier de Rochefort xderoche@labri.fr - labri.fr/~xderoche 15 mai 2014

Aucune validation n a été faite sur l exemple.

Certificate of Incorporation Certificat de constitution

Java Interview Questions and Answers

Socket Programming. A er learning the contents of this chapter, the reader will be able to:

Building a Java chat server

Stockage distribué sous Linux

How To Get A Kongo Republic Tourist Visa

java Features Version April 19, 2013 by Thorsten Kracht

Power Distribution System. Additional Information on page 2 See Page 2 Page 6. Eaton. See Page 2. Additional Information on page 2

Threads in der Client/Server-Programmierung mit Java

"Internationalization vs. Localization: The Translation of Videogame Advertising"

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

Java Programming: Sockets in Java

Personnalisez votre intérieur avec les revêtements imprimés ALYOS design

Audit de sécurité avec Backtrack 5

Multithreaded Programming

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Calcul parallèle avec R

Crash Course in Java

CISC 4700 L01 Network & Client- Server Programming Spring Harold, Chapter 8: Sockets for Clients

CS 121 Intro to Programming:Java - Lecture 11 Announcements

Message Oriented Middlewares

Apéndice C: Código Fuente del Programa DBConnection.java

Network Programming using sockets

Configuration Guide. SafeNet Authentication Service. SAS Agent for AD FS

RAPPORT FINANCIER ANNUEL PORTANT SUR LES COMPTES 2014

Tuple spaces and Object spaces. Distributed Object Systems 12. Tuple spaces and Object spaces. Communication. Tuple space. Mechanisms 2.

public class demo1swing extends JFrame implements ActionListener{

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Socket-based Network Communication in J2SE and J2ME

Brekeke PBX Web Service

Congo Republic Tourist visa Application

Introduction au BIM. ESEB Seyssinet-Pariset Economie de la construction contact@eseb.fr

Report of the case study in Sistemi Distribuiti A simple Java RMI application

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

SoapHeader : s'authentifier proprement a un WebService SOAP

Java Management Extensions SNMP Manager API

Transcription:

ExempleRMI.java import java.lang.*; import java.rmi.registry.*; import java.rmi.server.*; import java.io.*; import java.util.*; ExempleRMI.java import pkgexemple.*; public class ExempleRMI public static void main(string args[]) throws Exception int l_portadaptateur = 9999; int l_portserveursocket = 0; int l_portminclientsocket = 0; int l_portmaxclientsocket = 0; if (args.length == 4) l_portadaptateur = Integer.parseInt(args[0]); l_portserveursocket = Integer.parseInt(args[1]); l_portminclientsocket = Integer.parseInt(args[2]); l_portmaxclientsocket = Integer.parseInt(args[3]); Mise en place d'un SetSecurityManager ===================================== Fichier de defintion des droits et proprietes System.setProperty("java.security.policy","../server.java.policy"); Instanciation de la security if (l_portserveursocket!= 0) System.setSecurityManager(new RMISecurityManager()); Création de l'objet distribué HelloOD od = null; System.out.println("Création de l'objet distribué"); if (l_portserveursocket == 0) od = new HelloOD("Pierre","DUPONT"); else od = new HelloOD(l_portServeurSocket, l_portminclientsocket, l_portmaxclientsocket, "Pierre","DUPONT"); System.out.println("Enregistrement de l'objet distribué"); Naming.rebind("rmi:localhost:"+l_portAdaptateur+"/HELLO",od); System.out.println("Bus en ecoute..."); DataInputStream in = new DataInputStream(System.in); System.out.print("Taper rc, pour arreter le serveur..."); System.out.flush(); String valeur= in.readline(); Naming.unbind("rmi:localhost:"+l_portAdaptateur+"/HELLO"); UnicastRemoteObject.unexportObject(od, true /* pour forcer la destruction de l'od meme si il y encore des clients qui

l'utilisent */ ExempleRMI.java ); Page 2

Client2.java Client2.java import pkgexemple.*; public class Client2 public static void main(string args[]) throws Exception if (args.length == 3) System.setProperty("java.security.policy","../client.java.policy"); System.setSecurityManager(new RMISecurityManager()); HelloODInt helloservices = (HelloODInt)(Naming.lookup("rmi:"+args[0]+":"+args[1]+"/HELLO")); helloservices.setident(args[2],args[3]);

Client.java Client1.java import pkgexemple.*; public class Client1 public static void main(string args[]) throws Exception if (args.length == 3) System.setProperty("java.security.policy","../client.java.policy"); System.setSecurityManager(new RMISecurityManager()); HelloODInt helloservices = (HelloODInt)(Naming.lookup("rmi:"+args[0]+":"+args[1]+"/HELLO")); String messageold = ""; String message = ""; message = helloservices.hello(); while(true) if (message.equals(messageold)==false) System.out.println(message); messageold = message; message = helloservices.hello();

grant permission pour que le client puisse se connecter sur le port de l'adaptateur permission java.net.socketpermission "*:9999","connect,accept,listen,resolve"; permission pour que le client puisse se connecter sur l'objet distribué permission java.net.socketpermission "*:9200","connect,accept,listen,resolve"; permission pour que le client puisse se connecter aux ports locaux permission java.net.socketpermission "*:9300-9310","connect,accept,listen,resolve"; ;

grant On lui prefere une securite plus selectif: permission pour que le client puisse se connecter sur le port de l'adaptateur permission java.net.socketpermission "*:9999","connect,accept,listen,resolve"; permission pour que le client puisse se connecter sur l'objet distribué permission java.net.socketpermission "*:9200","connect,accept,listen,resolve"; permission pour que le client puisse se connecter sur les ports locaux permission java.net.socketpermission "*:9300-9310","connect,accept,listen,resolve"; ;

MyRMISocketFactory.java package pkgexemple; MyRMISocketFactory.java import java.rmi.server.*; import java.io.*; import java.net.*; import java.util.*; public class MyRMISocketFactory extends RMISocketFactory implements Serializable private String ident; private int portminlocalsocket; private int portmaxlocalsocket; public MyRMISocketFactory(String a_ident, int a_portminlocalsocket, int a_portmaxlocalsocket) super(); ident = a_ident; portminlocalsocket = a_portminlocalsocket; portmaxlocalsocket = a_portmaxlocalsocket; public Socket createsocket(string host, int port) throws IOException System.out.println(ident + " ** Creation d'un socket: "+ host+" "+port); System.out.println(ident + " ** plage local : " + portminlocalsocket + " " + portmaxlocalsocket); Socket socket=null; try InetAddress l_inetadress = InetAddress.getLocalHost(); int l_num=0; boolean l_fini=false; while(! l_fini) int l_port = portminlocalsocket+l_num; try socket = new Socket(host,port,l_inetAdress,l_port); System.out.println(" **Création du socket sur le port local: "+ l_port); l_fini=true; catch(exception l_ex2) System.out.println(" ** echec sur port local: "+l_port); l_num++; if (l_port > portmaxlocalsocket) l_fini=true; socket.setsotimeout(1000); socket.setsolinger(false,0); System.out.println(" ** remote port : "+ socket.getport()); System.out.println(" ** local port : "+ socket.getlocalport()); System.out.println(" ** local adress : "+ socket.getlocaladdress().tostring()); catch(exception l_ex)system.out.println(" ** Exception: "+l_ex); return socket; public ServerSocket createserversocket(int port) throws IOException System.out.println(ident + " Création du serveur de socket: "+port); return new ServerSocket(port);

HelloOD.java package pkgexemple; HelloOD.java import java.rmi.server.*; import pkgexemple.myrmisocketfactory; import pkgexemple.individu; public class HelloOD extends UnicastRemoteObject implements HelloODInt private Individu individu; public HelloOD(int a_portadaptateur, int a_portminclient, int a_portmaxclient, String nom,string prenom) throws RemoteException super(a_portadaptateur, (RMIClientSocketFactory)(new MyRMISocketFactory("*** [Client-side socket factory]", a_portminclient, a_portmaxclient)), (RMIServerSocketFactory)(new MyRMISocketFactory("*** [Server-side socket factory]", -1, -1)) ); System.out.println("Remote: "+this.tostring()); individu = new Individu(nom,prenom); public HelloOD(String nom,string prenom) throws RemoteException super(); System.out.println("Remote: "+this.tostring()); individu = new Individu(nom,prenom); public String hello() return("hello " + individu.getnom() + " " + individu.getprenom()); synchronized public void setident(string nom,string prenom) individu.setnom(nom); individu.setprenom(prenom); public Individu getindividu() return(individu); public void setindividu(individu a_individu) individu = a_individu;

HelloODInt.java package pkgexemple; HelloODInt.java public interface HelloODInt extends Remote POUR LE CAS A ============= public String hello() throws RemoteException; public void setident(string nom,string prenom) throws RemoteException; POUR LE CAS B ============= public Individu getindividu() throws RemoteException; public void setindividu(individu a_individu) throws RemoteException;

Individu.java package pkgexemple; Individu.java import java.rmi.server.*; import java.io.serializable; public class Individu implements Serializable String nom; String prenom; public Individu(String a_nom,string a_prenom) nom = a_nom; prenom = a_prenom; public String getnom()return(nom); public String getprenom()return(prenom); public void setnom(string a_nom)nom=a_nom; public void setprenom(string a_prenom)prenom=a_prenom; public boolean equals(object a_object) if (a_object == null) return false; Individu l_ind = (Individu)a_object; return( l_ind.nom.equals(this.nom) && l_ind.prenom.equals(this.prenom) );