com.izforge.izpack.installer
Class PrivilegedRunner

java.lang.Object
  extended by com.izforge.izpack.installer.PrivilegedRunner

public class PrivilegedRunner
extends java.lang.Object

This class is responsible for allowing the installer to re-launch itself with administrator permissions. The way of achieving this greatly varies among the platforms. The JDK classes are of not help here as there is no way to tell a JVM to run as a different user but to launch a new one.

Author:
Julien Ponge

Field Summary
private  boolean vetoed
           
 
Constructor Summary
PrivilegedRunner()
          Builds a default privileged runner.
PrivilegedRunner(boolean vetoed)
          Builds a privileged runner with a vetoing parameter.
 
Method Summary
 boolean canWriteToProgramFiles()
           
private  void copyStream(java.io.OutputStream out, java.io.InputStream in)
           
private  java.io.File extractMacElevator()
           
private  java.io.File extractVistaElevator()
           
private  java.util.List<java.lang.String> getElevator(java.lang.String javaCommand, java.lang.String installer)
           
private  java.lang.String getInstallerJar()
           
private  java.lang.String getJavaCommand()
           
private  java.lang.String getJavaExecutable()
           
 boolean isElevationNeeded()
          Checks if the current user is an administrator or not.
 boolean isPlatformSupported()
          Checks if the current platform is supported.
static boolean isPrivilegedMode()
           
 boolean isVetoed()
          Tells whether the elevation is vetoed by some of the invoker logic.
private  void makeExecutable(java.lang.String path)
           
 int relaunchWithElevatedRights()
          Relaunches the installer with elevated rights.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vetoed

private boolean vetoed
Constructor Detail

PrivilegedRunner

public PrivilegedRunner()
Builds a default privileged runner.


PrivilegedRunner

public PrivilegedRunner(boolean vetoed)
Builds a privileged runner with a vetoing parameter.

Parameters:
vetoed - should the elevation be vetoed?
Method Detail

isVetoed

public boolean isVetoed()
Tells whether the elevation is vetoed by some of the invoker logic.

Returns:
true if the elevation is to be vetoed.

isPlatformSupported

public boolean isPlatformSupported()
Checks if the current platform is supported.

Returns:
true if the platform is supported, false otherwise.

isElevationNeeded

public boolean isElevationNeeded()
Checks if the current user is an administrator or not.

Returns:
true if elevation is needed to have administrator permissions, false otherwise.

canWriteToProgramFiles

public boolean canWriteToProgramFiles()

relaunchWithElevatedRights

public int relaunchWithElevatedRights()
                               throws java.io.IOException,
                                      java.lang.InterruptedException
Relaunches the installer with elevated rights.

Returns:
the status code returned by the launched process (by convention, 0 means a success).
Throws:
java.io.IOException
java.lang.InterruptedException

getElevator

private java.util.List<java.lang.String> getElevator(java.lang.String javaCommand,
                                                     java.lang.String installer)
                                              throws java.io.IOException,
                                                     java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

extractVistaElevator

private java.io.File extractVistaElevator()
                                   throws java.io.IOException
Throws:
java.io.IOException

extractMacElevator

private java.io.File extractMacElevator()
                                 throws java.io.IOException,
                                        java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

makeExecutable

private void makeExecutable(java.lang.String path)
                     throws java.lang.InterruptedException,
                            java.io.IOException
Throws:
java.lang.InterruptedException
java.io.IOException

copyStream

private void copyStream(java.io.OutputStream out,
                        java.io.InputStream in)
                 throws java.io.IOException
Throws:
java.io.IOException

getInstallerJar

private java.lang.String getInstallerJar()

getJavaCommand

private java.lang.String getJavaCommand()

getJavaExecutable

private java.lang.String getJavaExecutable()

isPrivilegedMode

public static boolean isPrivilegedMode()