禁止Java,如何禁用Java安全管理器?

Is there any way to completely disable Java security manager?

I'm experimenting with source code of db4o. It uses reflection to persist objects and it seems that security manager doesn't allow reflection to read and write private or protected fields.

My code:

public static void main(String[] args) throws IOException {

System.out.println("start");

new File( DB_FILE_NAME ).delete();

ObjectContainer container = Db4o.openFile( DB_FILE_NAME );

String ob = new String( "test" );

container.store( ob );

ObjectSet result = container.queryByExample( String.class );

System.out.println( "retrieved (" + result.size() + "):" );

while( result.hasNext() ) {

System.out.println( result.next() );

}

container.close();

System.out.println("finish");

}

Output:

start

[db4o 7.4.68.12069 2009-04-18 00:21:30]

AccessibleObject#setAccessible() is not available. Private fields can not be stored.

retrieved (0):

finish

This thread suggests modifying java.policy file to allow reflection but it doesn't seem to work for me.

I'm starting JVM with arguments

-Djava.security.manager -Djava.security.policy==/home/pablo/.java.policy

so specified policy file will be the only policy file used

The file looks like this:

grant {

permission java.security.AllPermission;

permission java.lang.reflect.ReflectPermission "suppressAccessChecks";

};

I spent last 3 hrs on this and don't have any ideas how to make this work.

Any help appreciated.

解决方案

You could try adding this to the main() of your program:

System.setSecurityManager(null);

Worked for me for a "trusted" WebStart application when I was having security manager issues. Not sure if it will work for your db4o case, but it might be worth a try.

EDIT: I'm not suggesting that this is a general solution to security manager problems. I was just proposing it as a way to help debug the original poster's problem. Clearly, if you want to benefit from a security manager then you should not disable it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值