Permission for reading System.in in java
java, security
Solution
If you're using `System.console` in a JVM with the `SecurityManager` enabled, you'll need the following RuntimePermissions:
permission java.lang.RuntimePermission "readFileDescriptor";
permission java.lang.RuntimePermission "writeFileDescriptor";
Why?
The `System.in` and `System.out` file descriptors (0 and 1, with 2 representing `System.err`) are already open to the JVM. The `SecurityManager` verifies that you have write access to the open file descriptors through the `checkWrite(FileDescriptor fd)` method, and similarly that you have read access through the `checkRead(FileDescriptor fd)` method. The `RuntimePermission` required by those methods are listed in the javadocs.
While the "writeFileDescriptor" might appear superfluous, it is necessary for initializing the Console object (atleast in the Oracle Java 7 runtime).
Problem
I have some code which is reading user input from console using below code. ``` Console console = System.console(); String input = console.readLine(); ``` However, this code should run in a very secure env, where every action's permissions are controlled through a policy file. So I did my testing of the java code with policy file as ``` grant codeBase "file:/myjar.jar" { permission java.security.AllPermission; }; ``` I have no clue, what permission I should use to grant permission to `console.readLine()`.