1

全局并最终存储安全经理的检查是否可以接受?

给定以下代码行:

public static final boolean SEC_ON = (System.getSecurityManager() != null);

将其放在库中并在 JVM 的整个生命周期内重用结果是否可以接受?

为什么?或者为什么不呢?

[更新] Java EE - JSP 规范的参考实现中存在类似代码。任何使用它的应用服务器/servlet 容器都不支持 SecurityManager 的动态配置。

4

3 回答 3

1

由于安全管理器可以在 JVM 的生命周期内随时更改,因此这不是一个好的做法。如果他们需要便捷的快捷方式,则应使用以下方法:

public static boolean isSecurityOn() {
    return (System.getSecurityManager() != null);
}
于 2013-08-20T14:50:03.087 回答
1

不可以。如果最初不存在,可以随时安装安全管理器。

于 2013-08-19T23:03:57.067 回答
0

After petitioning the Java EE user group on the subject (https://java.net/projects/javaee-spec/lists/users/archive/2013-08/message/8), it appears their stance is to not make any such determination about whether it's ok to do this or not.

So, sadly while we may wish the answer to be "you should not do that", the reality is that you cannot rely on that assumption, because someone is and will probably continue to do it.

于 2013-08-22T19:22:20.567 回答