Java 安全管理器 - 它检查什么?

发布于 2024-10-20 01:22:53 字数 522 浏览 2 评论 0原文

这篇关于 Java 安全性的文章说:

Java库中的代码参考 安全经理每当出现危险时 即将尝试操作。

那么,这到底是什么意思呢?假设我已经实现了自己的安全管理器并为整个 JVM 启用了它。现在,java运行时是否会针对每个java调用(例如System.out.println()等)咨询我的安全管理器,还是仅针对危险的api调用(例如System.exit()、文件操作)进行咨询ETC?

编辑:让我澄清一下我的问题,

我并不是质疑安全经理的可能性。我只是想问安全检查是针对单独的危险API进行的,还是针对每个方法调用进行的。对于具有大量代码的应用程序来说,这反过来会导致性能大幅下降。

This article about Java security says:

Code in the Java library consults the
Security Manager whenever a dangerous
operation is about to be attempted.

So, what does this exactly mean? Say, if I've implemented my own securitymanager and enabled it for the whole JVM. Now, does the java runtime consults my securitymanager for each and every java call(like System.out.println() etc) or it consults only for dangerous api calls like System.exit() ,file operations etc?

edit: let me clarify my question,

I'm not questioning the possiblities of the securitymanager. I'm just asking if the security checks are done for the dangerous api's alone or it is done for each and every method call. Which inturn causes a huge performance degradation in case of applications with large amounts of code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

执手闯天涯 2024-10-27 01:22:53

如果代码如此,它只会咨询 SecurityManager。它不会对每一个操作都执行此操作。

例如,在 Runtime.exit 中,您会看到 SecurityManager 被咨询:

public void exit(int status) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
    security.checkExit(status);
}
Shutdown.exit(status);
}

同样,在 File 中,您将看到大多数方法都咨询 SecurityManager。示例:

public boolean canWrite() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
    security.checkWrite(path);
}
return fs.checkAccess(this, FileSystem.ACCESS_WRITE);
}

如果您正在编写一个可能“危险”的方法,那么您还应该咨询 SecurityManager。

It will only consult the SecurityManager if the code says so. It won't do it for every single operation.

For example in Runtime.exit, you see that the SecurityManager is consulted:

public void exit(int status) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
    security.checkExit(status);
}
Shutdown.exit(status);
}

Similarly, in File, you will see that most methods consult the SecurityManager. Example:

public boolean canWrite() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
    security.checkWrite(path);
}
return fs.checkAccess(this, FileSystem.ACCESS_WRITE);
}

If you are writing a method which might be "dangerous" then you should also consult the SecurityManager.

依 靠 2024-10-27 01:22:53

使用安全管理器,您可以控制对以下内容的访问:

  1. 文件操作
  2. 反射设施
  3. 读/写 IO
  4. 线程/线程组操作
  5. 套接字操作(侦听、接受等)
  6. 创建您自己的类加载器的能力。

对于每个这样的事情,SecurityManager 中都有一个 check*() 方法。

要获得详尽的列表,请检查 安全常量

Using security manager you could control access to :

  1. File operations
  2. Reflection facility
  3. Read/Write IO
  4. Thread/Thread group operations
  5. Socket operations(listen, accept etc.)
  6. Power to create your own classloader.

For each such thing there is a check*() method in SecurityManager

For an exhaustive list check the constants in SecurityConstants

苍暮颜 2024-10-27 01:22:53

安全管理器使用策略文件来查看允许的内容和不允许的内容。由该策略文件确定的“危险”操作在执行期间被授予或拒绝。

您可以在此处找到有关 Sun/Oracle JVM 默认策略的更多详细信息:

http://download.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html

The security manager uses a policy file to see what is permitted and what's not permitted. "Dangerous" operations, as determined by this policy file, is granted or denied during the execution.

You can find more details about the default policy for Sun/Oracle JVM here:

http://download.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文