SlideShare a Scribd company logo
Remote Method Invocation
www.sunilos.com
www.raystec.com
www.SunilOS.com 2
Single Server App
Server
Payment
<<Service>>
Shop
<<JSP>>
Inventory
<<Service>>
www.SunilOS.com 3
Distributed Application
Client
Shop
<<JSP>>
Server 1
Payment
<<Service>>
Server - 2
Inventory
<<Service>>
www.SunilOS.com 4
Communication Protocol
Client
Shop
<<JSP>>
Server 1
Payment
<<Service>>
Server - 2
Inventory
<<Service>>
RMI
SOAP
(XML)
CORBA
www.SunilOS.com5
Java Remote Object Invocation (RMI)
 Java RMI allows the programmer to execute a method of
remote class using the same semantics as local method
call.
Local Machine (Client)
AddServer remoteObject;
int s;
…
s=remoteObject.sum(1,2);
System.out.println(s);
Remote Machine
(Server)
public int sum(int
a,int b) {
return a + b;
}
1,2
3
www.SunilOS.com 6
The General RMI Architecture
 The server must first bind its
name to the registry.
 The client looks up the
server name in the registry
to establish remote
references.
 The Stub serializes the
parameters to skeleton, the
skeleton invokes the remote
method and serializes the
result back to the stub.
www.SunilOS.com 7
The Stub and Skeleton
 A client invokes a remote method, the call is first forwarded to
stub.
 The stub is responsible for sending the remote call over to the
server-side skeleton.
 The stub opens a socket to the remote server, marshals the
object parameters and forwards the data stream to the skeleton.
 A skeleton contains a method that receives the remote calls,
unmarshals the parameters, and invokes the actual remote object
implementation.
Stub
RMI Client RMI Server
skeleton
return
call
www.SunilOS.com 8
Steps for Developing an RMI System
1. Define the remote interface.
2. Develop the remote object by implementing the remote
interface.
3. Develop the client program.
4. Compile the Java source files.
5. Generate the client stubs and server skeletons.
6. Start the RMI registry.
7. Start the remote server objects.
8. Run the client.
www.SunilOS.com 9
Class Hierarchy
Remote
<<interface>>
AddServerIntf
<<interface>>
+ sum(int a,int b):int
AddServerImpl
+ sum(int a,int b):int
+add(int a):int
extends
implements
UnicastRemoteObject
extends
RMIRegistry
<<index>>
Client
www.SunilOS.com 10
Step 1: Defining the Remote Interface
import java.rmi.*;
public interface AddServerIntf extends Remote
{
public int sum(int a,int b) throws
RemoteException;
}
www.SunilOS.com 11
Step 2: Defining the Remote Server
 The server is a simple unicast remote server. Server is created by
extending java.rmi.server.UnicastRemoteObject.
 The server uses the RMISecurityManager to protect its resources
while engaging in remote communication.
import java.rmi.*; import java.rmi.server.*;
import java.rmi.registry.*;
public class AddServerImpl extends UnicastRemoteObject implements
AddServerIntf {
AddServerImpl() throws RemoteException{
super();
}
….
www.SunilOS.com 12
Step 2: Defining the Remote Server ( Cont.)
// Remote method implementation
public int sum(int a,int b) throws RemoteException{
return a + b;
}
The server must bind its name to the registry, the client will look up the
server name.
Use java.rmi.Naming class to bind the server name to registry. In this
example the name of server is “ADD-SERVER”.
In the main method of your server object, the RMI security manager is
created and installed.
www.SunilOS.com 13
Step 2: Defining the Remote Server
 Main method to start Server
public static void main(String args[]) throws Exception{
//set the security manager
System.setSecurityManager(new RMISecurityManager());
//create a local instance of the server object
AddServerImpl serverObj= new AddServerImpl();
//Bind server instance with RMI Registry
Naming.rebind("ADD-SERVER" , serverObj);
System.out.println("Server is started.....");
}
www.SunilOS.com 14
Step 3: Developing the Client program
 Client will look up the name of server in the registry using
java.rmi.Naming class.
 The server name is specified as URL:
o rmi://host:port/name
 Default RMI port is 1099.
 The name specified in the URL must exactly match the name that
the server has bound to the registry. In this example, the name of
server is “ADD-SERVER”.
 The remote method invocation is programmed using the remote
interface name (remoteObject) as prefix and the remote method
name (sum) as suffix.
www.SunilOS.com 15
Step 3: Developing the client program (Cont.)
public class SampleClient{
public static void main(String[] args){
// set the security manager for the client
System.setSecurityManager(new RMISecurityManager());
//get the remote object from the registry
try {
String url = “rmi://localhost:1099/ADD-SERVER”;
AddServerIntf remoteObject =(AddServerIntf)Naming.lookup(url);
System.out.println(" SUM = " + remoteObject.sum(1,2) );
}catch (RemoteException exc) {
System.out.println("Error in lookup: " + exc.toString()); }
catch (java.net.MalformedURLException exc) {
System.out.println("Malformed URL: " + exc.toString()); }
catch (java.rmi.NotBoundException exc) {
System.out.println("NotBound: " + exc.toString());
}
}
www.SunilOS.com 16
Step 4 : Compiling Classes
Assume the program is in c:rmi
o c:rmi> set CLASSPATH=”c:/rmi”
o c:rmi> javac AddServerIntf.java
o c:rmi> javac AddServerImpl.java
o c:rmi> javac SampleClient.java
www.SunilOS.com 17
Step 5: Generating stubs and skeletons
 The RMI system provides an RMI compiler (rmic) that
takes your RMI interface and class and generates stub
and skeleton.
 Assuming that classes are stored in c:/rmi folder and
run following commands from command prompt:
o c:rmi> set CLASSPATH=”c:/rmi”
o c:rmi> javac AddServerIntf.java
o c:rmi> javac AddServerImpl.java
o c:rmi> rmic AddServerImpl
www.SunilOS.com 18
Step 6: Starting the RMI registry
 The RMI Server objects are bound with the RMI Registry
and registry is started by calling command:
o rmiregistry
 By default port #1099 is used by RMI Registry. You can
also bind registry to a different port number by indicating
the port number next to command as:
o rmiregistry <new port>
 c:rmi>rmiregistry 1099
www.SunilOS.com 19
Steps 7: Starting Server and Client
 First Registry is started then Server will be started and bound to
Registry by a unique name.
 A security policy will be set when server is started. Granted
permissions are declared in a policy file. It is a text file. Policy file is
applied by –D command option:
o –Djava.security.policy=policy.all
 Open a command prompt and start server by:
o c:rmi> java –Djava.security.policy=policy.all AddServerImpl
 Open another command prompt and run client:
o c:rmi> java –Djava.security.policy=policy.all SampleClient
www.SunilOS.com 20
Java Policy File
The Java application must first obtain information
regarding its privileges. It can obtain the security
policy through a policy file.
In our example, we will allow Java code to have
all permissions. Policy file contents will be:
grant {
permission java.security.AllPermission;
};
Specific Permissions
grant {
permission java.io.filePermission “/tmp/*”, “read”, “write”;
permission java.net.SocketPermission “www.sunrays..co.in :
999”,”connect”;
permission java.net.SocketPermission “*:1024-65535”,”connect,request”;
permission java.net.SocketPermission “*:80”,”connect”;
};
Allows classes to read/write any file under the “/tmp” directory and its
subdirectories.
Allows classes to establish a network connection with the host
“www.SunilOS.com” at port 999.
Allows classes to connect to or accept connections on unprivileged
ports greater than 1024, on any host.
Allows all classes to connect to the HTTP port 80 on any host.
www.SunilOS.com 21
www.SunilOS.com 22
Run it!
 Open Command Prompt 1
 >rmiregistry
 Open Command Prompt 2
 >java -Djava.security.policy=policy.all AddServer
 Open Command Prompt 3
 >java -Djava.security.policy=policy.all AddClient
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 23
Thank You!
www.SunilOS.com 24
www.SunilOS.com

More Related Content

What's hot (20)

PDF
Java 8 Lambda Expressions
Scott Leberknight
 
PPTX
Operators php
Chandni Pm
 
PPTX
Java swing
Apurbo Datta
 
PPTX
Network programming in java - PPT
kamal kotecha
 
PPT
Network programming in Java
Tushar B Kute
 
PPT
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PPTX
Message passing in Distributed Computing Systems
Alagappa Govt Arts College, Karaikudi
 
PPTX
Ajax ppt - 32 slides
Smithss25
 
PPT
Active Server Page(ASP)
Keshab Nath
 
PDF
Remote Method Invocation (RMI)
Peter R. Egli
 
PPTX
Constructor ppt
Vinod Kumar
 
PPT
Java Networking
Sunil OS
 
PPS
Wrapper class
kamal kotecha
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Basics of JAVA programming
Elizabeth Thomas
 
PPT
Operator Overloading
Nilesh Dalvi
 
PDF
Java I/o streams
Hamid Ghorbani
 
Java 8 Lambda Expressions
Scott Leberknight
 
Operators php
Chandni Pm
 
Java swing
Apurbo Datta
 
Network programming in java - PPT
kamal kotecha
 
Network programming in Java
Tushar B Kute
 
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Message passing in Distributed Computing Systems
Alagappa Govt Arts College, Karaikudi
 
Ajax ppt - 32 slides
Smithss25
 
Active Server Page(ASP)
Keshab Nath
 
Remote Method Invocation (RMI)
Peter R. Egli
 
Constructor ppt
Vinod Kumar
 
Java Networking
Sunil OS
 
Wrapper class
kamal kotecha
 
Java interfaces
Raja Sekhar
 
Basics of JAVA programming
Elizabeth Thomas
 
Operator Overloading
Nilesh Dalvi
 
Java I/o streams
Hamid Ghorbani
 

Similar to Java RMI (20)

PDF
JavaRMI, JAVA RPC , INTRO , DESCRIPTION , EXPLAINED.pdf
ishankumra13579
 
PDF
Remote Method Invocation in JAVA
Jalpesh Vasa
 
PPTX
Rmi
Jafar Nesargi
 
PPTX
Remote Method Invocation (Java RMI)
Sonali Parab
 
PPTX
Introduction To Rmi
SwarupKulkarni
 
PPT
Distributed Objects and JAVA
elliando dias
 
DOCX
Remote Method Invocation
Sonali Parab
 
PPTX
Java RMI Presentation
Masud Rahman
 
PDF
Remote Method Invocation, Advanced programming
Gera Paulos
 
PDF
Java rmi
Fazlur Rahman
 
DOCX
ADB Lab Manual.docx
SaiKumarPrajapathi
 
PPT
Java remote method invocation
Van Dawn
 
PDF
Introduction to Remote Method Invocation (RMI)
eLink Business Innovations
 
PDF
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
hobbeljovie
 
PDF
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
ciggoaljasi
 
PPTX
Rmi
Vijay Kiran
 
DOCX
remote method invocation
Arun Nair
 
PPT
Rmi
phanleson
 
PPT
Rmi
leminhvuong
 
JavaRMI, JAVA RPC , INTRO , DESCRIPTION , EXPLAINED.pdf
ishankumra13579
 
Remote Method Invocation in JAVA
Jalpesh Vasa
 
Remote Method Invocation (Java RMI)
Sonali Parab
 
Introduction To Rmi
SwarupKulkarni
 
Distributed Objects and JAVA
elliando dias
 
Remote Method Invocation
Sonali Parab
 
Java RMI Presentation
Masud Rahman
 
Remote Method Invocation, Advanced programming
Gera Paulos
 
Java rmi
Fazlur Rahman
 
ADB Lab Manual.docx
SaiKumarPrajapathi
 
Java remote method invocation
Van Dawn
 
Introduction to Remote Method Invocation (RMI)
eLink Business Innovations
 
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
hobbeljovie
 
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
ciggoaljasi
 
remote method invocation
Arun Nair
 
Ad

More from Sunil OS (20)

PPT
Threads V4
Sunil OS
 
PPT
Java IO Streams V4
Sunil OS
 
PPT
OOP V3.1
Sunil OS
 
PPT
Java Basics V3
Sunil OS
 
PPT
DJango
Sunil OS
 
PPT
PDBC
Sunil OS
 
PPT
OOP v3
Sunil OS
 
PPT
Threads v3
Sunil OS
 
PPT
Exception Handling v3
Sunil OS
 
PPT
Collection v3
Sunil OS
 
PPT
Java 8 - CJ
Sunil OS
 
PPTX
Machine learning ( Part 3 )
Sunil OS
 
PPTX
Machine learning ( Part 2 )
Sunil OS
 
PPTX
Machine learning ( Part 1 )
Sunil OS
 
PPT
Python Pandas
Sunil OS
 
PPT
Python part2 v1
Sunil OS
 
PPT
Angular 8
Sunil OS
 
PPT
Python Part 1
Sunil OS
 
PPT
C# Variables and Operators
Sunil OS
 
PPT
C# Basics
Sunil OS
 
Threads V4
Sunil OS
 
Java IO Streams V4
Sunil OS
 
OOP V3.1
Sunil OS
 
Java Basics V3
Sunil OS
 
DJango
Sunil OS
 
PDBC
Sunil OS
 
OOP v3
Sunil OS
 
Threads v3
Sunil OS
 
Exception Handling v3
Sunil OS
 
Collection v3
Sunil OS
 
Java 8 - CJ
Sunil OS
 
Machine learning ( Part 3 )
Sunil OS
 
Machine learning ( Part 2 )
Sunil OS
 
Machine learning ( Part 1 )
Sunil OS
 
Python Pandas
Sunil OS
 
Python part2 v1
Sunil OS
 
Angular 8
Sunil OS
 
Python Part 1
Sunil OS
 
C# Variables and Operators
Sunil OS
 
C# Basics
Sunil OS
 
Ad

Recently uploaded (20)

PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
John Keats introduction and list of his important works
vatsalacpr
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 

Java RMI

  • 2. www.SunilOS.com 2 Single Server App Server Payment <<Service>> Shop <<JSP>> Inventory <<Service>>
  • 3. www.SunilOS.com 3 Distributed Application Client Shop <<JSP>> Server 1 Payment <<Service>> Server - 2 Inventory <<Service>>
  • 4. www.SunilOS.com 4 Communication Protocol Client Shop <<JSP>> Server 1 Payment <<Service>> Server - 2 Inventory <<Service>> RMI SOAP (XML) CORBA
  • 5. www.SunilOS.com5 Java Remote Object Invocation (RMI)  Java RMI allows the programmer to execute a method of remote class using the same semantics as local method call. Local Machine (Client) AddServer remoteObject; int s; … s=remoteObject.sum(1,2); System.out.println(s); Remote Machine (Server) public int sum(int a,int b) { return a + b; } 1,2 3
  • 6. www.SunilOS.com 6 The General RMI Architecture  The server must first bind its name to the registry.  The client looks up the server name in the registry to establish remote references.  The Stub serializes the parameters to skeleton, the skeleton invokes the remote method and serializes the result back to the stub.
  • 7. www.SunilOS.com 7 The Stub and Skeleton  A client invokes a remote method, the call is first forwarded to stub.  The stub is responsible for sending the remote call over to the server-side skeleton.  The stub opens a socket to the remote server, marshals the object parameters and forwards the data stream to the skeleton.  A skeleton contains a method that receives the remote calls, unmarshals the parameters, and invokes the actual remote object implementation. Stub RMI Client RMI Server skeleton return call
  • 8. www.SunilOS.com 8 Steps for Developing an RMI System 1. Define the remote interface. 2. Develop the remote object by implementing the remote interface. 3. Develop the client program. 4. Compile the Java source files. 5. Generate the client stubs and server skeletons. 6. Start the RMI registry. 7. Start the remote server objects. 8. Run the client.
  • 9. www.SunilOS.com 9 Class Hierarchy Remote <<interface>> AddServerIntf <<interface>> + sum(int a,int b):int AddServerImpl + sum(int a,int b):int +add(int a):int extends implements UnicastRemoteObject extends RMIRegistry <<index>> Client
  • 10. www.SunilOS.com 10 Step 1: Defining the Remote Interface import java.rmi.*; public interface AddServerIntf extends Remote { public int sum(int a,int b) throws RemoteException; }
  • 11. www.SunilOS.com 11 Step 2: Defining the Remote Server  The server is a simple unicast remote server. Server is created by extending java.rmi.server.UnicastRemoteObject.  The server uses the RMISecurityManager to protect its resources while engaging in remote communication. import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { AddServerImpl() throws RemoteException{ super(); } ….
  • 12. www.SunilOS.com 12 Step 2: Defining the Remote Server ( Cont.) // Remote method implementation public int sum(int a,int b) throws RemoteException{ return a + b; } The server must bind its name to the registry, the client will look up the server name. Use java.rmi.Naming class to bind the server name to registry. In this example the name of server is “ADD-SERVER”. In the main method of your server object, the RMI security manager is created and installed.
  • 13. www.SunilOS.com 13 Step 2: Defining the Remote Server  Main method to start Server public static void main(String args[]) throws Exception{ //set the security manager System.setSecurityManager(new RMISecurityManager()); //create a local instance of the server object AddServerImpl serverObj= new AddServerImpl(); //Bind server instance with RMI Registry Naming.rebind("ADD-SERVER" , serverObj); System.out.println("Server is started....."); }
  • 14. www.SunilOS.com 14 Step 3: Developing the Client program  Client will look up the name of server in the registry using java.rmi.Naming class.  The server name is specified as URL: o rmi://host:port/name  Default RMI port is 1099.  The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name of server is “ADD-SERVER”.  The remote method invocation is programmed using the remote interface name (remoteObject) as prefix and the remote method name (sum) as suffix.
  • 15. www.SunilOS.com 15 Step 3: Developing the client program (Cont.) public class SampleClient{ public static void main(String[] args){ // set the security manager for the client System.setSecurityManager(new RMISecurityManager()); //get the remote object from the registry try { String url = “rmi://localhost:1099/ADD-SERVER”; AddServerIntf remoteObject =(AddServerIntf)Naming.lookup(url); System.out.println(" SUM = " + remoteObject.sum(1,2) ); }catch (RemoteException exc) { System.out.println("Error in lookup: " + exc.toString()); } catch (java.net.MalformedURLException exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); } }
  • 16. www.SunilOS.com 16 Step 4 : Compiling Classes Assume the program is in c:rmi o c:rmi> set CLASSPATH=”c:/rmi” o c:rmi> javac AddServerIntf.java o c:rmi> javac AddServerImpl.java o c:rmi> javac SampleClient.java
  • 17. www.SunilOS.com 17 Step 5: Generating stubs and skeletons  The RMI system provides an RMI compiler (rmic) that takes your RMI interface and class and generates stub and skeleton.  Assuming that classes are stored in c:/rmi folder and run following commands from command prompt: o c:rmi> set CLASSPATH=”c:/rmi” o c:rmi> javac AddServerIntf.java o c:rmi> javac AddServerImpl.java o c:rmi> rmic AddServerImpl
  • 18. www.SunilOS.com 18 Step 6: Starting the RMI registry  The RMI Server objects are bound with the RMI Registry and registry is started by calling command: o rmiregistry  By default port #1099 is used by RMI Registry. You can also bind registry to a different port number by indicating the port number next to command as: o rmiregistry <new port>  c:rmi>rmiregistry 1099
  • 19. www.SunilOS.com 19 Steps 7: Starting Server and Client  First Registry is started then Server will be started and bound to Registry by a unique name.  A security policy will be set when server is started. Granted permissions are declared in a policy file. It is a text file. Policy file is applied by –D command option: o –Djava.security.policy=policy.all  Open a command prompt and start server by: o c:rmi> java –Djava.security.policy=policy.all AddServerImpl  Open another command prompt and run client: o c:rmi> java –Djava.security.policy=policy.all SampleClient
  • 20. www.SunilOS.com 20 Java Policy File The Java application must first obtain information regarding its privileges. It can obtain the security policy through a policy file. In our example, we will allow Java code to have all permissions. Policy file contents will be: grant { permission java.security.AllPermission; };
  • 21. Specific Permissions grant { permission java.io.filePermission “/tmp/*”, “read”, “write”; permission java.net.SocketPermission “www.sunrays..co.in : 999”,”connect”; permission java.net.SocketPermission “*:1024-65535”,”connect,request”; permission java.net.SocketPermission “*:80”,”connect”; }; Allows classes to read/write any file under the “/tmp” directory and its subdirectories. Allows classes to establish a network connection with the host “www.SunilOS.com” at port 999. Allows classes to connect to or accept connections on unprivileged ports greater than 1024, on any host. Allows all classes to connect to the HTTP port 80 on any host. www.SunilOS.com 21
  • 22. www.SunilOS.com 22 Run it!  Open Command Prompt 1  >rmiregistry  Open Command Prompt 2  >java -Djava.security.policy=policy.all AddServer  Open Command Prompt 3  >java -Djava.security.policy=policy.all AddClient
  • 23. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 23