Jump to content

[Java] Help with doPrivilege access controller and security


joel24

Recommended Posts

I'm currently writing a Java applet to access and scan wifi networks and I need to execute the netsh with the parameters "wlan show networks mode=bssid".

 

The script is being run from a HTML page and so the Applet is limited to the sandbox environment. What would be the best way to grant permissions to execute said command?

 

At the moment I'm getting warnings when compiling the class, sorry this is my first Java applet - feel free to point me toward any relevant tutorials?

warning: [unchecked] unchecked con

version

                        AccessController.doPrivileged(new PrivilegedAction() {

                                                      ^

  required: PrivilegedAction<T>

  found:    <anonymous PrivilegedAction>

  where T is a type-variable:

    T extends Object declared in method <T>doPrivileged(PrivilegedAction<T>)

c:\users\joel\desktop\javaTest\wifox.java:28: warning: [unchecked] unchecked met

hod invocation: method doPrivileged in class AccessController is applied to give

n types

                        AccessController.doPrivileged(new PrivilegedAction() {

                                                    ^

  required: PrivilegedAction<T>

  found: <anonymous PrivilegedAction>

  where T is a type-variable:

    T extends Object declared in method <T>doPrivileged(PrivilegedAction<T>)

2 warnings

 

and the current code

public static void testing() {
		AccessController.doPrivileged(new PrivilegedAction() {
		public Object run() {
			try {
				// Run "netsh" Windows command
				Process process = Runtime.getRuntime().exec("netsh.exe wlan show networks mode=bssid");

				// Get input streams
				BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
				BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));

				// Read command standard output
				String s;
				System.out.println("Networks Found: ");
				while ((s = stdInput.readLine()) != null) {
					System.out.println(s);
				}

				// Read command errors
				System.out.println("Errors: ");
				while ((s = stdError.readLine()) != null) {
					System.out.println(s);
				}
			} catch (Exception e) {
				e.printStackTrace(System.err);
			}
		}
	});
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.