Java.util.PropertyPermission.implies() Method


Advertisements


Description

The java.util.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

Example

The following example shows the usage of java.util.PropertyPermission.implies(Permission) 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 permissions
   checkFileReadPermission("java.home");
   checkFileWritePermission("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");
   }
   }
   
   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");
   }
   }
}

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

Has permissions on java.home for read
Has permissions on java.home for write

java_util_propertypermission.htm

Advertisements