Networking and Security provided by java.
With the help of java.security and java.net Packages.
It also provide brief information about the Permission and Policy Classes of java.securty Packages.
1. COLLAGE NAME:-
SHREE P.M.PATEL INSTITUTE OF POST GRADUATE STUDIES
AND RESEARCH IN APPLIED SCIENCE, ANAND
MANAGED BY:
ANAND PEOPLE MEDICARE SOCIETY, ANAND
SEMINAR ON
NETWORKING AND SECURITY IN JAVA
Prepared By,
Kavankumar Nileshkumar. Solanki
SY MSc.IT Sem.III
Roll No. 03
Date:-19/07/2020
3. OBJECTIVES
Sockets in Java
Creating and using Socket
java.security Package
Permission and Security Policy
Policy Class
4. SOCKETS IN JAVA
An IP Port on a specific host machine is called Socket.
The emergence of sockets first appeared in early Unix systems in the 1970s and have now become the
‘standard’ low-level communication primitive.
There two types of Sockets
Connection-Oriented Sockets-
Almost based on TCP.
Connection Sockets-
Usually based on UDP(User Datagram Protocol)
5. CREATING AND USING SOCKETS
Communication over the Internet involves sockets for creating connection.
Sockets connect to numbered communication ports.
The bottom 1,024 ports are reserved for system use.
Port 21-FTP
Port 23-Telnet
Port 25-Email
Port 80-HTTP
Port 119-Usenet
Java supports sockets with the Socket class.
6. CONSTRUCTORS OF THE CLIENT SOCKETS
Constructors Does this
Socket() It creates an unconnected socket, with the system-default type of
SocketIm.
Socket(InetAddress address, int port) It creates a stream socket and connections it to specified port
number at the specified IP address.
Socket (InetAddress address, int port, Boolean stream) It is deprecated and it uses DatagramSocket instead for UDP
transport.
Socket (InetAddress address, int port, InetAddress localAddr,
int localPort)
It creates a socket and connects it to the specified remote address
on the specified remote port.
Socket (Proxy proxy) It creates an unconnected socket, specifying the type of proxy that
should be used regardless of any other setting.
protectedSocket(SocketImpl impl) It creates an unconnected Socket with a user-specified SocketImpl.
Socket(String host, int port) It creates a stream socket and connects it to the specified port
number on the named host.
Socket(String host, int port, Boolean stream) It is deprecated and it uses DatagramSocket instead for UDP
transport.
Socket (String host, int port, InetAddress localAddr,
int localPort)
It creates a socket and connects it to the specified remote address
on the specified remote port.
7. EXAMPLE OF CLIENT SOCKET
import java.io.*;
import java.net.*;
public class SocketDemo{
public static void main(String[] args){
try{
Socket s=new Socket(“www.sun.com”,80); //www.sun.com is InetAddress, 80 is Port Num. for HTTP;
BufferedReader in=new BufferedReader( new InputStreamReader(s.getInputStream())); //To Read From Socket;
PrintWriter out=new PrintWriter(s.getOutputStream()); //To Write to a Socket;
System.out.print(“GET/index.htmlnn”);
out.flush(); //Flush out the PrintWriter Object;
String line;
while((line==in.readLine())!=null){
System.out.println(line);}
}
catch(Exception ex){ }
}
}
9. JAVA.SECURITY PACKAGE
This package provides classes and interfaces for security framework.
The classes of this package implement access control security architecture.
This implemented security architecture is easily configurable.
Using this package, we can avail all support for the generation and storage of cryptographic public key.
It also supports number of cryptographic operations which includes operations for message digest and
generation of signature.
This package also contains classes for signed/ guarded objects and random number generation.
10. INTERFACES OF THE JAVA.SECURITY PACKAGE
Interface Description
DomainCombiner It provides a means to dynamically update the ProtectionDomain
associated with the current AccessControlContext.
Guard This interface represents a guard, which is used to protect access to
another object.
Key It is a top level interface for all key.
KeyStore.Entry It is a marker interface for KeyStore entry types.
KeyStore.LoadStoreParametere It is a marker interface for KeyStore load and store parameter.
KeyStore.ProtectionParametere It is a marker interface for KeyStore protection parameter.
Policy. Parameters It is marker interface for Policy parameters.
Principal This interface represent the abstract notion of a principal, which can
be used to represent any entity.
PrivateKey Int is private Key.
PrivilegedAction<T> It is computation to be performed with privileges enabled.
12. PERMISSION AND SECURITY POLICY
The two most important classes of java.security package are the
java.security.Permission
java.security.Policy
13. PERMISSION CLASS
This is an abstract class in java.security package which represents access to a system resource.
A permission has a name and abstract function defining the semantics of a particular Permission
subclass.
A Permission object may include a list of permitted actions.
All subclasses of Permission class must implement the implies() method to compare Permissions.
14. CONSTRUCTORS OF THE JAVA,SECURITY.PERMISSION CLASS
Constructor Does this
Permission(String name) It creates a permission with a name specified.
15. METHODS OF THE JAVA.SECURITY.PERMISSION CLASS
Methods Does this
void checkGuard(Object object) It implements the guard interface for permission.
abstract Boolean equals(Object object) It checks two Permission objects for equality.
abstract String getActions() It gives actions as a String.
String getName() It gives name of this Permission.
abstract int hashCode() It gives hash code value for this Permission object.
abstract Boolean implies(Permission permission) It checks if the specified permission’s actions are
“implied by” this object’s actions.
PermissionCollection new PermissionCollection() It yields an empty PermissionCollection for a given
Permission object, or null if one is not defined.
String toString() It yields a string describing this Permission.
16. POLICY CLASS
An object of Policy class is used to determine whether the code running in Java Runtime Environment
has permission to perform security-sensitive operations.
In the runtime, there is only one Policy object is installed at a time.
A Policy object is installed by using setPolicy() method and can be obtained by using getPolicy().
If no Policy object is installed, getPolicy() installs a default Policy implementation.
To provide a custom implementation, we can subclass Policy class.
After an instance of Policy object is installed, Java runtime call implice() method to find whether the
running code can perform operations protected by Security Manager.
The invocation of refresh() method causes the Policy object to refresh/reload its data.
17. NASTED CLASS OF JAVA.SECURITY.POLICY CLASS
Class Description
static interface Policy.Parameter Its represents a marker interface for Policy
parameters.
18. FIELD SUMMARY OF JAVA.SECURITY.POLICY CLASS
Field Description
static PermissionCollection
UNSUPPORTED_EMPTY_COLLECTION
It is a read-only empty PermissionCollection
instance.