Home  >  Core Java

Example of PropertyPermission in Java

By Arvind Rai, June 09, 2013
java.util.PropertyPermission gives permission to the specified property. The property can be like java.home, os.name etc. And the action can be read and write. Object is created as below
PropertyPermission pp = new PropertyPermission("java.home","read");
Wildcard can also be used to specify property name. If we say java.* then properties like java.home, java.home.user has been permitted for specified action. Find the example below.

package com.concretepage.util;
import java.util.PropertyPermission;
public class PropertyPermissionDemo {
    public static void main(String[] args) {
        PropertyPermission pp = new PropertyPermission("java.*","read,write");
        
        //check permission for java.home 
        if("java.home".matches(pp.getName())){
            System.out.println("Permission for java.home :"+pp.getActions());
        }else{
            System.out.println("No permission for java.home");
        }
        
        //check permission for java.home.user
        if("java.home.user".matches(pp.getName())){
            System.out.println("Permission for java.home.user: "+pp.getActions());
        }else{
            System.out.println("No permission for java.home.user");
        }
        
        //check permission for os.name 
        if("os.name".matches(pp.getName())){
            System.out.println("Permission for os.name: "+pp.getActions());
        }else{
            System.out.println("No permission for os.name");
        }
        
    }
}


Output
Permission for java.home :read,write
Permission for java.home.user: read,write
No permission for os.name
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us