예제 #1
0
  public void runPreProcess() {

    Authorization auth = new glguerin.authkit.imp.macosx.MacOSXAuthorization();
    Privilege priv = new Privilege("system.privilege.admin");
    // see kAuthorizationRightExecute in the AuthorizationTags.h from Security.framework
    int count = 0;
    boolean succeed = false;
    do {
      try {
        auth.authorize(priv, true);
        succeed = true;
        break;
      } catch (Throwable t) {
        System.out.println("Throwable " + t);
      }
      count++;
    } while (count <= 3);

    if (succeed) {
      String preinstallPath = createTemporaryPreinstallFile();
      if (preinstallPath == null) return;
      String[] progArray = {preinstallPath, System.getProperty("user.name")};
      try {
        Process p = auth.execPrivileged(progArray);
        Thread.sleep(1000L);
      } catch (Throwable t) {
        System.out.println("Throwable " + t);
        t.printStackTrace();
      }
    }
  }