Why doesn't this security check pass?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Robert_Paris
Posted On:   Tuesday, February 10, 2004 08:37 AM

I have the following code: //MyPolicy is saving the AccessControlContext just for testing purposes MyPolicy.acc.checkPermission( new FilePermission( "D:\Test.txt", "write" ); //This DOES write out, so I know the first one had permission System.out.println( "ACC had the permission to write" ); AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { FileOutputStream fo = new FileOutputStream( "D:\Test.txt" ); } catch (Exception e) { e.printStackTrace(); //This throws a SecurityException } return null; } }, MyPolicy.acc );    More>>

I have the following code:

			
//MyPolicy is saving the AccessControlContext just for testing purposes
MyPolicy.acc.checkPermission( new FilePermission( "D:\Test.txt", "write" );

//This DOES write out, so I know the first one had permission
System.out.println( "ACC had the permission to write" );

AccessController.doPrivileged( new PrivilegedAction()
{
public Object run()
{
try
{
FileOutputStream fo = new FileOutputStream( "D:\Test.txt" );
}
catch (Exception e)
{
e.printStackTrace(); //This throws a SecurityException
}
return null;
}
}, MyPolicy.acc );


Can someone explain why the above throws a SecurityException (doesn't have
permission to write to the file)? I thought that it would check the
permission against the AccessControlContext passed in? Am i wrong on this?

Note: I'm using JRE 1.3.1 here.    <<Less
About | Sitemap | Contact