Java 安全管理器找出谁请求访问
我编写了一个自己的安全管理器,我的问题是,我在程序中运行其他用户的代码,并且我必须确保没有滥用。
所以我的问题是:我如何能够在安全管理器的方法中找到,谁在 checkXXXXX() 方法中要求访问权限。
谢谢
i wrote a own Security Manager and my problem is, that i run code from other users in my program, and i have to ensure that there is no abuse.
So my Question is: How i am able to find out in the Methods of the Security Manager , who asks for the Access in the checkXXXXX() - methods.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,在一般情况下没有简单的方法可以做到这一点。
(如果您在 Web 容器中运行,这可能提供一种获取当前请求的身份验证详细信息的方法。但这听起来不像您的用例。)
我想您可以尝试多种方法要实现这一点,尽管您需要小心防止欺骗用户身份的代码。一种想法是将每个用户身份与一个不同的线程组相关联,并让安全管理器阻止在其他线程组中创建线程;阅读 javadoc
Thread(ThreadGroup group, Runnable target, String name)
,注意它关于线程组检查的内容。No there is no simple way to do this in the general case.
(If you were running within a web container, that might provide a way to get hold of the current request's authentication details. But that doesn't sound like your use-case.)
I guess there are a variety of ways that you could attempt to implement this, though you'd need to be careful to protect against code that spoofs the user identity. One idea is to associate each user identity with a distinct ThreadGroup, and get your security manager to block creation of threads in other thread groups; read the javadoc for
Thread(ThreadGroup group, Runnable target, String name)
, paying attention to what it says about the thread group check.