使用Java的应用程序包装器
是否可以使用Java为其他(Java)应用程序实现包装器应用程序 其目的是为独立于用于处理特定文档的应用程序的文档强制实施使用策略 我有一个加密文件,需要在某种编辑器中解密和打开。因此,包装器应用程序将解密文件并启动自身内的编辑器,例如,通过拒绝对应用程序的写访问来强制执行只读策略。因此,使用Java的应用程序包装器,java,security,file-access,securitymanager,Java,Security,File Access,Securitymanager,是否可以使用Java为其他(Java)应用程序实现包装器应用程序 其目的是为独立于用于处理特定文档的应用程序的文档强制实施使用策略 我有一个加密文件,需要在某种编辑器中解密和打开。因此,包装器应用程序将解密文件并启动自身内的编辑器,例如,通过拒绝对应用程序的写访问来强制执行只读策略。因此,Runtime.getRuntime().exec()方法不适合:) 还有一些方法可以拦截同一应用程序中的方法调用,但没有一种方法可以包装整个其他应用程序 我还读过关于修改JVM本身以拦截文件访问的内容。听起来
Runtime.getRuntime().exec()方法不适合:)
还有一些方法可以拦截同一应用程序中的方法调用,但没有一种方法可以包装整个其他应用程序
我还读过关于修改JVM本身以拦截文件访问的内容。听起来不错。但我需要根据用户动态更改策略。据我所知,这可能不起作用
我想可能没有任何方法可以使用Java代码来实现这一点,但我希望得到任何提示和帮助。EclipseRPC可能是一个不错的选择。它提供编辑器视图,可以在运行时轻松更改以启用/禁用保存和其他功能。由于Eclipse是用Java编写的,您已经拥有的大多数Java代码都可以很好地使用该框架
我还读过关于修改JVM本身以拦截文件访问的内容。听起来不错。但我需要根据用户动态更改策略
设置一个自定义的SecurityManager
,该管理器覆盖以引发异常
下面是一个防止子帧退出VM的简单示例(checkExit(int)
)
为什么应用程序需要是“包装器”应用程序?我认为您可以使用EclipseRPC实现这种类型的需求。您只需通过禁用EclipseRPC编辑器提供的任何特定保存函数来禁用在代码中保存的功能。我想使用EclipseRPC需要编写自己的编辑器。还是我弄错了?这不是我一开始想要的。对不起,如果我之前没有弄清楚的话。最好将编辑器的工作(例如.txt文件)留给用户,但将控件留给对我的应用程序的文件访问。EclipseRPC有一个内置编辑器,也有内置的文件浏览器。我认为它非常适合您的项目。我确实明白您将编辑器的选择权留给用户的观点,但在我看来,这可能比它的价值更麻烦。麻烦是这样的。:)但这正是问题的关键所在我正在开发一个DLP系统的原型,希望任何类型的文档都能得到权限管理的支持。谢谢你的评论。
import java.awt.GridLayout;
import java.awt.event.*;
import java.security.Permission;
import javax.swing.*;
/** NoExit demonstrates how to prevent 'child' applications from
* ending the VM with a call to System.exit(0). */
public class NoExit extends JFrame implements ActionListener {
JButton frameLaunch = new JButton("Frame");
JButton exitLaunch = new JButton("Exit");
/** Stores a reference to the original security manager. */
ExitManager sm;
public NoExit() {
super("Launcher Application");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
sm = new ExitManager( System.getSecurityManager() );
System.setSecurityManager(sm);
setLayout(new GridLayout(0,1));
frameLaunch.addActionListener(this);
exitLaunch.addActionListener(this);
add( frameLaunch );
add( exitLaunch );
pack();
setSize( getPreferredSize() );
setLocationByPlatform(true);
}
public void actionPerformed(ActionEvent ae) {
if ( ae.getSource()==frameLaunch ) {
TargetFrame tf = new TargetFrame();
} else {
// change back to the standard SM that allows exit.
System.setSecurityManager(
sm.getOriginalSecurityManager() );
// exit the VM when *we* want
System.exit(0);
}
}
public static void main(String[] args) {
NoExit ne = new NoExit();
ne.setVisible(true);
}
}
/** Our custom ExitManager does not allow the VM to exit, but does
* allow itself to be replaced by the original security manager. */
class ExitManager extends SecurityManager {
SecurityManager original;
ExitManager(SecurityManager original) {
this.original = original;
}
/** Deny permission to exit the VM. */
public void checkExit(int status) {
throw( new SecurityException() );
}
/** Allow this security manager to be replaced,
if fact, allow pretty much everything. */
public void checkPermission(Permission perm) {
}
public SecurityManager getOriginalSecurityManager() {
return original;
}
}
/** This example frame attempts to System.exit(0) on closing, we must
* prevent it from doing so. */
class TargetFrame extends JFrame {
TargetFrame() {
super("Close Me!");
add(new JLabel("Hi!"));
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.out.println("Bye!");
System.exit(0);
}
});
pack();
setSize( getPreferredSize() );
setLocationByPlatform(true);
setVisible(true);
}
}