Is there an easy way to investigate if AccessController.doPrivileged() is really needed?

StackOverflow https://stackoverflow.com/questions/18271064

  •  24-06-2022
  •  | 
  •  

質問

I have this code that attaches a JavaServer to the RMIRegistry, which is done in a PrivilegedAction

        //start javaengineserver
        AccessController.doPrivileged(new PrivilegedAction() 
        {
            public Object run() 
            {
                try
                {
                    startServer(port, getSession());
                } catch (RmiException e) 
                {
                    e.printStackTrace();
                    AWTSwingErrorDialog.show(e, "Error while attaching JavaEngineServer to rmiregistry.exe");
                }
                return null;
            }
        });

I found some other Questions about the doPrivileged method, and they all say that there are some comands that need the extra permissions like getting Environment Variables.

So i looked threw the code behind the startServer(port, session) method and i haven't found anything that looks like it needs extra permissions, but is there a way to confirm that, other than Test all the usages and functionality by hand?

Thank you.

役に立ちましたか?

解決

I don't think there is a (reliable) easy way. There is an unreliable way though: temporarily replace that code with something that just calls startServer, and try running it in a security sandbox.

I suspect that the doPrivileged call is needed though. A method with that name and a port parameter is likely to try to create / bind / listen on a ServerSocket. The latter will fail if the SecurityManager.checkListen method does not allow the operation ... which it won't do in a typical sandbox. (We don't normally want untrusted code to be able to start stealth network services ...)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top