Ejemplo n.º 1
0
  /**
   * 'handler' can be of any type that implements 'exportedInterface', but only methods declared by
   * the interface (and its superinterfaces) will be invocable.
   */
  public <T> InAppServer(
      String name,
      String portFilename,
      InetAddress inetAddress,
      Class<T> exportedInterface,
      T handler) {
    this.fullName = name + "Server";
    this.exportedInterface = exportedInterface;
    this.handler = handler;

    // In the absence of authentication, we shouldn't risk starting a server as root.
    if (System.getProperty("user.name").equals("root")) {
      Log.warn(
          "InAppServer: refusing to start unauthenticated server \"" + fullName + "\" as root!");
      return;
    }

    try {
      File portFile = FileUtilities.fileFromString(portFilename);
      secretFile = new File(portFile.getPath() + ".secret");
      Thread serverThread = new Thread(new ConnectionAccepter(portFile, inetAddress), fullName);
      // If there are no other threads left, the InApp server shouldn't keep us alive.
      serverThread.setDaemon(true);
      serverThread.start();
    } catch (Throwable th) {
      Log.warn("InAppServer: couldn't start \"" + fullName + "\".", th);
    }
    writeNewSecret();
  }
Ejemplo n.º 2
0
 private PermissionInfo[] getFileRelativeInfos(PermissionInfo[] permissionInfos, Bundle bundle) {
   if (permissionInfos == null || !(bundle instanceof AbstractBundle)) return permissionInfos;
   PermissionInfo[] results = new PermissionInfo[permissionInfos.length];
   for (int i = 0; i < permissionInfos.length; i++) {
     results[i] = permissionInfos[i];
     if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { // $NON-NLS-1$
       if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { // $NON-NLS-1$
         File file = new File(permissionInfos[i].getName());
         if (!file.isAbsolute()) { // relative name
           File target =
               ((AbstractBundle) bundle).getBundleData().getDataFile(permissionInfos[i].getName());
           if (target != null)
             results[i] =
                 new PermissionInfo(
                     permissionInfos[i].getType(),
                     target.getPath(),
                     permissionInfos[i].getActions());
         }
       }
     }
   }
   return results;
 }