Security manager fixes

Some fixes for the test suite when running under a security manager. 

There is still a lot more to do.