Java PropertyPermission implies() Method



Description

The java PropertyPermission implies(Permission p) method checks if this PropertyPermission implies the specified Permission. This is done by checking p is PropertyPermission object, actions of p are subset of this object's actions and if this object's name implies p's actions.

Declaration

Following is the declaration for java.util.PropertyPermission.implies() method

public boolean implies(Permission p)

Parameters

p − The Permission object to be checked.

Return Value

This method returns true if this object implies the specified Permission.

Exception

NA

Checking Read Permission using PropertyPermission Instance Example

The following example shows the usage of Java PropertyPermission implies() method to check a permission object. We've built a PropertyPermission object, and then check the permission to be read using implies() method.

package com.tutorialspoint;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;
   
   public static void main(String[] args) {

      // Create property permission object
      permission = new PropertyPermission("java.*", "read,write");

      // Check permission
      checkFileReadPermission("java.home");
   }

   private static void checkFileReadPermission(String path) {

      // Check permission on read action
      if(permission.implies(new PropertyPermission(path, "read"))) {
         System.out.println("Has permissions on "+path+" for read");
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Has permissions on java.home for read

Checking Write Permission using PropertyPermission Instance Example

The following example shows the usage of Java PropertyPermission implies() method to check a permission object. We've built a PropertyPermission object, and then check the permission to write using implies() method.

package com.tutorialspoint;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;
   
   public static void main(String[] args) {

      // Create property permission object
      permission = new PropertyPermission("java.*", "read,write");

      // Check permission
      checkFileWritePermission("java.home");
   }
      
   private static void checkFileWritePermission(String path) {

      // Check permission on read action
      if(permission.implies(new PropertyPermission(path, "write"))) {
         System.out.println("Has permissions on "+path+" for write");
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Has permissions on java.home for write
java_util_propertypermission.htm
Advertisements