protected void addPathFile(final File pathComponent) throws IOException {
   if (!this.pathComponents.contains(pathComponent)) {
     this.pathComponents.addElement(pathComponent);
   }
   if (pathComponent.isDirectory()) {
     return;
   }
   final String absPathPlusTimeAndLength =
       pathComponent.getAbsolutePath()
           + pathComponent.lastModified()
           + "-"
           + pathComponent.length();
   String classpath = AntClassLoader.pathMap.get(absPathPlusTimeAndLength);
   if (classpath == null) {
     JarFile jarFile = null;
     try {
       jarFile = new JarFile(pathComponent);
       final Manifest manifest = jarFile.getManifest();
       if (manifest == null) {
         return;
       }
       classpath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
     } finally {
       if (jarFile != null) {
         jarFile.close();
       }
     }
     if (classpath == null) {
       classpath = "";
     }
     AntClassLoader.pathMap.put(absPathPlusTimeAndLength, classpath);
   }
   if (!"".equals(classpath)) {
     final URL baseURL = AntClassLoader.FILE_UTILS.getFileURL(pathComponent);
     final StringTokenizer st = new StringTokenizer(classpath);
     while (st.hasMoreTokens()) {
       final String classpathElement = st.nextToken();
       final URL libraryURL = new URL(baseURL, classpathElement);
       if (!libraryURL.getProtocol().equals("file")) {
         this.log(
             "Skipping jar library "
                 + classpathElement
                 + " since only relative URLs are supported by this"
                 + " loader",
             3);
       } else {
         final String decodedPath = Locator.decodeUri(libraryURL.getFile());
         final File libraryFile = new File(decodedPath);
         if (!libraryFile.exists() || this.isInPath(libraryFile)) {
           continue;
         }
         this.addPathFile(libraryFile);
       }
     }
   }
 }
예제 #2
0
  /**
   * Creates a new Help window associated with the JMenuItem passed as parameters
   *
   * @param help
   */
  public HelpWindow(JMenuItem help) {
    File path = new File(Configuration.instance().getTangaraPath().getParentFile(), "Help");

    File log = new File(path, LOG_FILE);

    if (!log.exists()) {
      // Log file does not exist : we create the help set
      createJavaHelp(path, Configuration.instance().getLanguage());
    } else {
      // Log file exists : we check that help set correspond to the current language
      try {
        BufferedReader reader = new BufferedReader(new FileReader(log));
        String ligne = reader.readLine();
        if (ligne != null) {
          StringTokenizer st = new StringTokenizer(ligne);
          if (st.nextToken().equals("Language")
              && !st.nextToken().equals(Configuration.instance().getLanguage()))
            // Language has changed: we re-create the help set
            createJavaHelp(path, Configuration.instance().getLanguage());
        }
        reader.close();
      } catch (Exception e) {
        LOG.error("Error while reading log file " + e);
      }
    }

    // Set up the help viewer
    // FIXME help desactivated
    //		try {
    //			URL [] list = new URL[1];
    //			list[0] = path.toURI().toURL();
    //
    //			ClassLoader cl = new URLClassLoader(list);
    //			URL url = HelpSet.findHelpSet(cl, HELPSET_NAME, new
    // Locale(Configuration.instance().getLanguage()));
    //			HelpSet hs = new HelpSet(cl, url);
    //
    //			HelpBroker hb = hs.createHelpBroker();
    //
    //			CSH.setHelpIDString(help, FIRST_PAGE);
    //
    //			help.addActionListener(new CSH.DisplayHelpFromSource(hb));
    //		} catch (Exception e1) {
    //			LOG.error("Error1 " + e1);
    //		}
  }
예제 #3
0
파일: Main.java 프로젝트: karianna/jdk8_tl
  /** Generates the transitive closure of the Class-Path attribute for the specified jar file. */
  List<String> getJarPath(String jar) throws IOException {
    List<String> files = new ArrayList<String>();
    files.add(jar);
    jarPaths.add(jar);

    // take out the current path
    String path = jar.substring(0, Math.max(0, jar.lastIndexOf('/') + 1));

    // class path attribute will give us jar file name with
    // '/' as separators, so we need to change them to the
    // appropriate one before we open the jar file.
    JarFile rf = new JarFile(jar.replace('/', File.separatorChar));

    if (rf != null) {
      Manifest man = rf.getManifest();
      if (man != null) {
        Attributes attr = man.getMainAttributes();
        if (attr != null) {
          String value = attr.getValue(Attributes.Name.CLASS_PATH);
          if (value != null) {
            StringTokenizer st = new StringTokenizer(value);
            while (st.hasMoreTokens()) {
              String ajar = st.nextToken();
              if (!ajar.endsWith("/")) { // it is a jar file
                ajar = path.concat(ajar);
                /* check on cyclic dependency */
                if (!jarPaths.contains(ajar)) {
                  files.addAll(getJarPath(ajar));
                }
              }
            }
          }
        }
      }
    }
    rf.close();
    return files;
  }
예제 #4
0
  public static void main(String[] args) throws IOException {
    List /*<String>*/ classes = new ArrayList();
    String origJavaHome = System.getProperty("java.home");
    String javaHome = origJavaHome.toLowerCase();
    if (javaHome.endsWith("jre")) {
      origJavaHome = origJavaHome.substring(0, origJavaHome.length() - 4);
      javaHome = javaHome.substring(0, javaHome.length() - 4);
    }
    for (int i = 0; i < args.length; i++) {
      try {
        File file = new File(args[i]);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = null;
        while ((line = reader.readLine()) != null) {
          StringTokenizer tok = new StringTokenizer(line, "[ \t\n\r\f");
          if (tok.hasMoreTokens()) {
            String t = tok.nextToken();
            // Understand only "Loading" from -XX:+TraceClassLoadingPreorder.
            // This ignores old "Loaded" from -verbose:class to force correct
            // classlist generation on Mustang.
            if (t.equals("Loading")) {
              t = tok.nextToken();
              t = t.replace('.', '/');

              // Check to make sure it came from the boot class path
              if (tok.hasMoreTokens()) {
                String tmp = tok.nextToken();
                if (tmp.equals("from")) {
                  if (tok.hasMoreTokens()) {
                    tmp = tok.nextToken().toLowerCase();
                    // System.err.println("Loaded " + t + " from " + tmp);
                    if (tmp.startsWith(javaHome)) {
                      // OK, remember this class for later
                      classes.add(t);
                    }
                  }
                }
              }
            }
          }
        }
      } catch (IOException e) {
        System.err.println("Error reading file " + args[i]);
        throw (e);
      }
    }

    Set /*<String>*/ seenClasses = new HashSet();

    for (Iterator iter = classes.iterator(); iter.hasNext(); ) {
      String str = (String) iter.next();
      if (seenClasses.add(str)) {
        System.out.println(str);
      }
    }

    // Try to complete certain packages
    // Note: not using this new code yet; need to consider whether the
    // footprint increase is worth any startup gains
    // Note also that the packages considered below for completion are
    // (obviously) platform-specific
    // JarFile rtJar = new JarFile(origJavaHome + File.separator +
    //                             "jre" + File.separator +
    //                             "lib" + File.separator +
    //                             "rt.jar");
    // completePackage(seenClasses, rtJar, "java/awt");
    // completePackage(seenClasses, rtJar, "sun/awt");
    // completePackage(seenClasses, rtJar, "sun/awt/X11");
    // completePackage(seenClasses, rtJar, "java/awt/im/spi");
    // completePackage(seenClasses, rtJar, "java/lang");
  }
예제 #5
0
  /**
   * Authenticate users
   *
   * @param oc the streams
   * @param ci the ConnectInfo
   */
  private void authentification(ObjectConnection oc, Message message, String data) {
    String passwd = null;
    String name = null;
    String authenticationServer = null;
    String hostname = null;
    int port = 0;
    StringTokenizer stk = new StringTokenizer(data, " ");

    try {
      passwd = stk.nextToken();
      hostname = stk.nextToken();
      port = Integer.parseInt(stk.nextToken());
    } catch (Exception ex) {
      Logging.getLogger().warning("#Err > Incorrect authentication message.");
      try {
        oc.write("BAD_MESSAGE");
      } catch (Exception e) {
      }

      return;
    }

    name = message.getSender().getName();
    authenticationServer = message.getSender().getAuthenticationServer();
    UserConcept user = null;

    try {
      user = store.getUserStore().getUser(message.getSender().getName());
    } catch (Exception e) {
      e.printStackTrace();
    }

    // password ok
    if (user != null && store.getUserStore().checkUserPassword(user, passwd)) {
      // disconnect already connected user
      if (isAlreadyKnown(message.getSender())) {
        ConnectInfo oldUser = getCompleteConnectInfo(message.getSender());
        try {
          ObjectConnection myoc = this.sendMessageTo(oldUser, "Client", "DISCONNECT");
          myoc.close();
        } catch (Exception e) {
          // we can't do much here, the client might have crashed
        }
        this.removeConnectInfo(oldUser);
      }

      connections.add(
          new ConnectInfo(
              name, authenticationServer, hostname, port, user.getPublicKey(), "Client"));
      try {
        oc.write("AUTH_ACCEPTED " + user.getPrivateKey());
      } catch (Exception e) {
        e.printStackTrace();
      }
      this.sendUserList();
    } else {
      try {
        oc.write("NOT_VALID_USER");
      } catch (Exception e) {
      }
    }
  }
예제 #6
0
  /**
   * Reads messages from the network. A message is either a command for the server or for an
   * internal Service.
   *
   * @param sock the Socket
   */
  private void getMessage(Socket sock) {
    int i;
    boolean alreadyConnected;
    boolean isAuthentication;

    Message message;
    byte[] signature;

    String cmd;
    String cmdData;
    StringTokenizer stk;

    ObjectConnection oc = null;

    try {
      /* streams initialization */
      oc = new ObjectConnection(sock);
      message = (Message) oc.read();
      signature = (byte[]) oc.read();
    } catch (Exception ex) {
      ex.printStackTrace();
      Logging.getLogger().warning("#Err > Unable to read message.");
      return;
    }

    // check wether a user is known or not
    alreadyConnected = isAlreadyKnown(message.getSender());

    // check if command is authentication
    isAuthentication =
        message.getApplication().equals("Server")
            && ((String) message.getData()).startsWith("AUTH");

    // signature check
    if (alreadyConnected && !isAuthentication) {
      boolean sigok = false;
      try {
        ConnectInfo ci = message.getSender();
        if (ci.verifier == null) ci = this.getCompleteConnectInfo(ci);
        sigok = ci.verifier.verify(message, signature);
      } catch (Exception e) {
        e.printStackTrace();
      }

      if (!sigok) {
        try {
          oc.write("FAILED bad signature");
        } catch (Exception e) {
        }
        Logging.getLogger().warning("#Err > bad signature: " + message.getSender());
        return;
      }
    }

    if (message.getApplication().equals("Server")) {
      cmd = null;

      try {
        stk = new StringTokenizer((String) message.getData());
        cmd = stk.nextToken();
        cmdData = stk.nextToken("\0").substring(1);
      } catch (Exception ex) {
        if (cmd == null) cmd = "";

        cmdData = "";
      }

      /* if the user asks for authentication, we try to do it and exits this method */
      if (cmd.equals("AUTH")) {
        try {
          oc.write("OK");
        } catch (Exception e) {
          e.printStackTrace();
        }

        authentification(oc, message, cmdData);
      } else if (!alreadyConnected) {
        Logging.getLogger().info("Access denied to " + message.getSender());
        try {
          oc.write("FAILED No Connection");
        } catch (Exception e) {
        }
      } else {
        internalCommand(oc, message, cmd, cmdData);
      }
    } else if (!alreadyConnected) {
      Logging.getLogger().info("Access denied to " + message.getSender());
      try {
        oc.write("FAILED No Connection");
      } catch (Exception e) {
      }
    } else {
      Service s;

      /* seek the destination service */
      boolean serviceFound = false;
      for (i = 0; i < this.services.size(); i++) {
        s = (Service) services.get(i);

        if (s.getName().equalsIgnoreCase(message.getApplication())) {
          serviceFound = true;
          UserConcept user = null;
          ServiceConcept service = null;
          try {
            user = store.getUserStore().getUser(message.getSender().getName());
            service = store.getServiceStore().getService(message.getReceiver().getName());
          } catch (Exception e) {
          }

          /* tests serviceManager for permissions */
          boolean isAutorizedService = false;
          try {
            isAutorizedService = store.getServiceStore().isAuthorizedService(user, service);
          } catch (Exception e) {
          }

          if (!isAutorizedService) {
            Logging.getLogger()
                .info(
                    "#Err > "
                        + message.getSender()
                        + " : Service denied to "
                        + message.getReceiver().getName());
            try {
              oc.write("FAILED You don't have acces to this service");
            } catch (Exception e) {
            }
          } else {
            try {
              oc.write("OK");
            } catch (Exception e) {
            }
            serviceFound = true;
            s.process(oc, message);
          }
          break;
        }
      }

      if (!serviceFound) {
        try {
          oc.write("FAILED unknown");
        } catch (Exception e) {
        }
        Logging.getLogger()
            .warning("#Err > Service " + message.getReceiver().getName() + " unknown");
      }
    }

    oc.close();
  }