Java.util.PropertyPermission.getActions() の使い方

Javaコード

package ListResourceBundle;

import java.util.PropertyPermission;

public class ActionsDemo {
private static PropertyPermission permission;

public static void main(String[] args) {
// Build property permissions
permission = new PropertyPermission(“java.changfa.*", “read,write");

// Check permissions
checkFilePermissions(“java.changfa.usr");
}

private static void checkFilePermissions(String path) {
// Check permission given name
if (path.matches(permission.getName())) {
// Get actions list
String actions = permission.getActions();
// Match read write actions
if (actions.contains(“read"))
System.out.println(“message1: " + path + " for read");
if (actions.contains(“write"))
System.out.println(“message2: " + path + " for write");
}
}
}

実行結果
message1: java.changfa.usr for read
message2: java.changfa.usr for write

Java

Posted by arkgame