检查权限抛出SecurityException,即使我能够写

时间:2016-07-06 03:57:16

标签: java file-permissions access-control

public void checkPermissionUsingAccessController(String path)
    {
        try
        {
            AccessController.checkPermission(new FilePermission(path, "write"));
            System.out.println("Passed");
        }
        catch(SecurityException e)
        {
            System.out.println("Sorry no rights");
        }
    }

    public static void main(String[] args)
    {
        UserPrivileges userPrivileges = new UserPrivileges();
                    userPrivileges.checkPermissionUsingAccessController(System.getProperty("user.dir"));
        PropertiesExample example = new PropertiesExample();
        example.saveProperties("example");
        System.out.println(System.getProperty("user.dir"));
    }

打印:Sorry no rights

当我运行这个程序时,即使AccessController告诉该应用程序没有写入权限,我仍然可以写入pwd。谁能告诉我哪里错了?

0 个答案:

没有答案