All About Class SecurityManager in Java

0
38
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

SecurityManager in Java
SecurityManager in Java

SecurityManager in Java:

The SecurityManager in java is an abstract class that allows applications to implement security policy to run untrusted code.

It allows an application to determine, before performing a possibly unsafe or sensitive operation. What the operation is and whether the operation is being performed by a class created by a ClassLoader rather than installed locally.

Classes loaded via ClassLoader (if they have been downloaded over network) may be less trustworthy than classes from files installed locally. The application has the option of allowing or disallowing the operation by using SecurityManager.
The SecurityManager class contains a large number of methods whose names begins with the word called check. These methods are called by various methods in the java library before those methods perform certain sensitive operations.
The SecurityManager is thereby given an opportunity to prevent completion of the operation by throwing an Exception.

Security Manager in Java

A security manager routine simply return if the operation is permitted but throws an Exception if the operation is not permitted. The only exception to this convention is checkTopLevel window,which returns a boolean value.

The current Security manager is set by the setSecurityManager() method in class System. The current security manager is obtained by getSecurityManager() method.

SecurityManager in Java

SecurityManager is typically used for Webbrowser based applications or applet where untrusted code needs to run in a controlled environment. It uses a sandbox model of Security which ensures these web browser based applets do not cause any harm due to security.

It ensures that the applet perform anything within the Sandbox not outside of the constraints of the Sandbox. Any method of the java application can try to access resources outside of the JVM by seeking a permission from SecurityManager.

If the access is denied, SecurityManager can throw SecurityException . The set of checkXXX methods are defined in the SecurityManager to get access permission for different resources.

The structure of the class SecurityManager is given as:


public abstract class java.lang.SecurityManager extends 
                      java.lang.Object{
//Member elements
protected boolean inCheck;//this field is true if there is a 
//security check in progress , false otherwise
//constructors
protected SecurityManager();//constructs a new SecurityManager.
//An application is not allowed to create a new security manager
// if there is already a current security manager in place.It can throw 
//SecurityException if a SecurityManager already exists.
//Methods
public void checkAccept(String host,int port);
//permission to accept a network connection
public void checkAccess(Thread th);
//permission to modify a thread
public void checkAccess(ThreadGroup tg);
//permission to modify a ThreadGroup.
public void checkConnect(String host,int port);
//permission to establish a network connection or send datagram
public void checkConnect(String host,int port,Object context);
//permission to establish a network connection or send datagram
public void checkCreateClassLoader();
//permission to create a ClassLoader object
public void checkDelete(String file);
//permission to delete a file
public void checkExec(String command);
//permission to call an external program
public void checkExit(int status);
//permission to stop the JVM and exit the java environment.
public void checkLink(String lib);
//permission to dynamically link an external library to java environment.
public void checkListen(int port);
//permission to listen for a network connection
public void checkPackageAccess(String pkg);
//permission to access a class in a package
public void checkPackageDefinition(String pkg);
//permission to define classes in a package
public void checkPropertiesAccess();
//permission to get or set Properties object that defines all of the system properties
public void checkPropertyAccess(String key);
//permission to get or set any one System Property
public void checkPrintJobAccess();
//permission to initiate a print job request
public void checkRead(FileDescriptor fd);
//permission to read from a file descriptor
public void checkRead(String file);
//permission to read a file
public void checkRead(String file,Object context);
//permission to read a file with context
public void checkSecurityAccess(String action);
//permission to perform a security action
public void checkSetFactory();
//permission to set a factory class that determines classes to be used for managing
//network connections and their content.
public void checkSystemClipboardAccess();
//permission to access System Clipboard
public boolean checkTopLevelWindow(Object window);
//permission to create a top level window on the screen
public void checkWrite(FileDescriptor fd);
//permission to write to a file descriptor
public void checkWrite(String file);
//permission to write to a file
public boolean getInCheck();
public ThreadGroup getThreadGroup();
public void checkMulticast(InetAddress address,byte tl);
//permission to use a multicast connection
public void checkMulticast(InetAddress address);
//permission to use a multicast connection
public void checkMemberAccess(Class class,int whichMember);
////permission to access a member of the class
public void checkAwtEventQueueAccess();
//permission to access the AWT event queue.
protected native int classDepth(String name);
protected native int classLoaderDepth();
protected native ClassLoader currentClassLoader();
protected native class[] getClassContext();
public Object getSecurityContext();
protected boolean inClass(String name);
protected boolean inClassLoader();
protected Class currentLoaderClass();
}
 

 

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here