GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java SecurityManager Class
Selected Reading
Java SecurityManager ClassIntroductionThe Java SecurityManager class allows applications to implement a security policy. It allows an application to determine, before performing a possibly unsafe or sensitive operation, what the operation is and whether it is being attempted in a security context that allows the operation to be performed. The application can allow or disallow the operation. Class DeclarationFollowing is the declaration for java.lang.SecurityManager class − @Deprecated(since="17",
forRemoval=true)
public class SecurityManager
extends Object
Note − The Security Manager is deprecated and subject to removal in a future release. There is no replacement for the Security Manager. See JEP 411 for discussion and alternatives. Class constructors
Class methods
Methods inheritedThis class inherits methods from the following classes −
ExampleOur examples require that the permissions for each command is blocked. A new policy file was set that allows only the creating and setting of our Security Manager. The file is in C:/java.policy and contains the following text − grant {
permission java.lang.RuntimePermission "setSecurityManager";
permission java.lang.RuntimePermission "createSecurityManager";
permission java.lang.RuntimePermission "usePolicy";
};
The following example shows the usage of lang.SecurityManager.checkAccept() method. package com.tutorialspoint;
public class SecurityManagerDemo {
public static void main(String[] args) {
// set the policy file as the system securuty policy
System.setProperty("java.security.policy", "file:/C:/java.policy");
// create a security manager
SecurityManager sm = new SecurityManager();
// set the system security manager
System.setSecurityManager(sm);
// check if accepting socket connection is enabled
sm.checkAccept("www.tutorialspoint.com", 8080);
// print a message if we passed the check
System.out.println("Allowed!");
}
}
OutputLet us compile and run the above program, this will produce the following result − Exception in thread "main" java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release at java.base/java.lang.System.setSecurityManager(System.java:430) at com.tutorialspoint.SecurityManagerDemo.main(SecurityManagerDemo.java:14) Advertisements
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |