Topic: 我想了解下JVM 中的默认SecurityManager

  Print this page

1.我想了解下JVM 中的默认SecurityManager Copy to clipboard
Posted by: micsolaris
Posted on: 2008-11-20 01:01

最近在看关于JVM的书,里面涉及到一个SecurityManager,当我new一个SecurityManager的时候来测试程序对File的read功能,但是总是会报异常。是不是默认的SecurityManager是禁止一切访问的啊。
package com.ricky.www;

import java.io.FilePermission;
import java.security.Permission;

import sun.security.util.SecurityConstants;

public class Test {
  public static void main(String[] args) {
    SecurityManager manager = new SecurityManager();
    System.setSecurityManager(manager);
    Permission perm = new FilePermission("c:/family/ricky.txt", SecurityConstants.FILE_READ_ACTION);
    manager.checkPermission(perm);
  }
}


Exception in thread "main" java.security.AccessControlException: access denied (java.io.FilePermission c:/family/ricky.txt read)
  at java.security.AccessControlContext.checkPermission(Unknown Source)
  at java.security.AccessController.checkPermission(Unknown Source)
  at java.lang.SecurityManager.checkPermission(Unknown Source)
  at com.ricky.www.Test.main(Test.java:13)

2.Re:我想了解下JVM 中的默认SecurityManager [Re: micsolaris] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-11-22 01:13

Does the file have the read permission for your current user?

run a "ls -l ricky.txt" could find out this.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923