Home » Java programming language

Java SecurityManager checkSystemClipboardAccess() method with example

SecurityManager Class checkSystemClipboardAccess() method: Here, we are going to learn about the checkSystemClipboardAccess() method of SecurityManager Class with its syntax and example.
Submitted by Preeti Jain, on December 18, 2019

SecurityManager Class checkSystemClipboardAccess() method

  • checkSystemClipboardAccess() method is available in java.lang package.
  • checkSystemClipboardAccess() method invokes checkPermission with the AWTPermission("accessClipboard") permission to access the system clipboard properties.
  • checkSystemClipboardAccess() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • checkSystemClipboardAccess() method may throw an exception at the time of accessing system clipboard properties.
    SecurityException – This exception may throw when the calling thread does not have the right to access the system clipboard.

Syntax:

    public void checkSystemClipboardAccess();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is void, it returns nothing.

Example:

// Java program to demonstrate the example 
// of void checkSystemClipboardAccess ()
// method of SecurityManager 

public class CheckSystemClipboardAccess extends SecurityManager {
    public static void main(String[] args) {

        // By using setProperty() method is to set the policy property 
        // with security manager
        System.setProperty("java.security.policy", "file:/C:/java.policy");

        // Instantiating a CheckSystemClipboardAccess object
        CheckSystemClipboardAccess csc = new CheckSystemClipboardAccess();

        // By using setSecurityManager() method is to set the
        // security manager
        System.setSecurityManager(csc);

        // By using checkSystemClipboardAccess() method is to
        // check restriction on system clipboard
        csc.checkSystemClipboardAccess();

        // Display the message
        System.out.println("Not Restricted..");
    }
}

Output

Exception in thread "main" java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.