Ejemplo n.º 1
0
  MemoryUsage getPeakMemoryUsage() {
    try {
      final Map<Object, Object> m = JvmContextFactory.getUserData();

      if (m != null) {
        final MemoryUsage cached = (MemoryUsage) m.get(entryPeakMemoryTag);
        if (cached != null) {
          if (log.isDebugOn())
            log.debug("getPeakMemoryUsage", entryPeakMemoryTag + " found in cache.");
          return cached;
        }

        MemoryUsage u = pool.getPeakUsage();
        if (u == null) u = ZEROS;

        m.put(entryPeakMemoryTag, u);
        return u;
      }
      // Should never come here.
      // Log error!
      log.trace("getPeakMemoryUsage", "ERROR: should never come here!");
      return ZEROS;
    } catch (RuntimeException x) {
      log.trace("getPeakMemoryUsage", "Failed to get MemoryUsage: " + x);
      log.debug("getPeakMemoryUsage", x);
      throw x;
    }
  }
Ejemplo n.º 2
0
 String connectorArg(String name) {
   Connector.Argument argument = connectorArgs.get(name);
   if (argument == null) {
     return "";
   }
   return argument.value();
 }
Ejemplo n.º 3
0
 /** Get an image ref. */
 static Ref getCachedImageRef(URL url) {
   synchronized (imageRefs) {
     AppletImageRef ref = (AppletImageRef) imageRefs.get(url);
     if (ref == null) {
       ref = new AppletImageRef(url);
       imageRefs.put(url, ref);
     }
     return ref;
   }
 }
Ejemplo n.º 4
0
 /** Get an audio clip. */
 public AudioClip getAudioClip(URL url) {
   checkConnect(url);
   synchronized (audioClips) {
     AudioClip clip = (AudioClip) audioClips.get(url);
     if (clip == null) {
       audioClips.put(url, clip = new AppletAudioClip(url));
     }
     return clip;
   }
 }
Ejemplo n.º 5
0
  /*
   * Returns a keystore entry alias and a single target keystore.
   * An alias prefix must be supplied.
   */
  private AbstractMap.SimpleEntry<String, AbstractMap.SimpleEntry<String, KeyStore>>
      getKeystoreForWriting(String alias) {

    String[] splits = alias.split(this.entryNameSeparator, 2);
    if (splits.length == 2) { // prefixed alias
      KeyStore keystore = keystores.get(splits[0]);
      if (keystore != null) {
        return new AbstractMap.SimpleEntry<>(
            splits[1], new AbstractMap.SimpleEntry<>(splits[0], keystore));
      }
    }
    return null;
  }
Ejemplo n.º 6
0
 final EventDispatcher getEventDispatcher() {
   // create and start the global event thread
   // TODO  need a way to stop this thread when the engine is done
   final ThreadGroup tg = Thread.currentThread().getThreadGroup();
   synchronized (dispatchers) {
     EventDispatcher eventDispatcher = dispatchers.get(tg);
     if (eventDispatcher == null) {
       eventDispatcher = new EventDispatcher();
       dispatchers.put(tg, eventDispatcher);
       eventDispatcher.start();
     }
     return eventDispatcher;
   }
 }
Ejemplo n.º 7
0
  /**
   * Initialize this <code>LoginModule</code>.
   *
   * <p>
   *
   * @param subject the <code>Subject</code> to be authenticated.
   *     <p>
   * @param callbackHandler a <code>CallbackHandler</code> for communicating with the end user
   *     (prompting for usernames and passwords, for example).
   *     <p>
   * @param sharedState shared <code>LoginModule</code> state.
   *     <p>
   * @param options options specified in the login <code>Configuration</code> for this particular
   *     <code>LoginModule</code>.
   */
  public void initialize(
      Subject subject,
      CallbackHandler callbackHandler,
      Map<String, ?> sharedState,
      Map<String, ?> options) {

    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;

    // initialize any configured options
    debug = "true".equalsIgnoreCase((String) options.get("debug"));
  }
Ejemplo n.º 8
0
  boolean setConnectorArg(String name, String value) {
    /*
     * Too late if the connection already made
     */
    if (vm != null) {
      return false;
    }

    Connector.Argument argument = connectorArgs.get(name);
    if (argument == null) {
      return false;
    }
    argument.setValue(value);
    return true;
  }
Ejemplo n.º 9
0
  /*
   * Returns a keystore entry alias and a list of target keystores.
   * When the supplied alias prefix identifies a keystore then that single
   * keystore is returned. When no alias prefix is supplied then all the
   * keystores are returned.
   */
  private AbstractMap.SimpleEntry<String, Collection<KeyStore>> getKeystoresForReading(
      String alias) {

    String[] splits = alias.split(this.entryNameSeparatorRegEx, 2);
    if (splits.length == 2) { // prefixed alias
      KeyStore keystore = keystores.get(splits[0]);
      if (keystore != null) {
        return new AbstractMap.SimpleEntry<>(
            splits[1], (Collection<KeyStore>) Collections.singleton(keystore));
      }
    } else if (splits.length == 1) { // unprefixed alias
      // Check all keystores for the first occurrence of the alias
      return new AbstractMap.SimpleEntry<>(alias, keystores.values());
    }
    return new AbstractMap.SimpleEntry<>(
        "", (Collection<KeyStore>) Collections.<KeyStore>emptyList());
  }
Ejemplo n.º 10
0
  private static SortedMap<String, Object> makeMap(Map<String, ?> items) {
    if (items == null || items.isEmpty())
      throw new IllegalArgumentException("Null or empty items map");

    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (Object key : items.keySet()) {
      if (key == null || key.equals(""))
        throw new IllegalArgumentException("Null or empty item name");
      if (!(key instanceof String)) {
        throw new ArrayStoreException("Item name is not string: " + key);
        // This can happen because of erasure.  The particular
        // exception is a historical artifact - an implementation
        // detail that leaked into the API.
      }
      map.put((String) key, items.get(key));
    }
    return map;
  }
Ejemplo n.º 11
0
 private void writeGenerators(RIFFWriter writer, Map<Integer, Short> generators)
     throws IOException {
   Short keyrange = (Short) generators.get(SF2Region.GENERATOR_KEYRANGE);
   Short velrange = (Short) generators.get(SF2Region.GENERATOR_VELRANGE);
   if (keyrange != null) {
     writer.writeUnsignedShort(SF2Region.GENERATOR_KEYRANGE);
     writer.writeShort(keyrange);
   }
   if (velrange != null) {
     writer.writeUnsignedShort(SF2Region.GENERATOR_VELRANGE);
     writer.writeShort(velrange);
   }
   for (Map.Entry<Integer, Short> generator : generators.entrySet()) {
     if (generator.getKey() == SF2Region.GENERATOR_KEYRANGE) continue;
     if (generator.getKey() == SF2Region.GENERATOR_VELRANGE) continue;
     writer.writeUnsignedShort(generator.getKey());
     writer.writeShort(generator.getValue());
   }
 }
Ejemplo n.º 12
0
  /**
   * Converts the map of year to month lengths ranging from minYear to maxYear into a linear
   * contiguous array of epochDays. The index is the hijrahMonth computed from year and month and
   * offset by minYear. The value of each entry is the epochDay corresponding to the first day of
   * the month.
   *
   * @param minYear The minimum year for which data is provided
   * @param maxYear The maximum year for which data is provided
   * @param years a Map of year to the array of 12 month lengths
   * @return array of epochDays for each month from min to max
   */
  private int[] createEpochMonths(
      int epochDay, int minYear, int maxYear, Map<Integer, int[]> years) {
    // Compute the size for the array of dates
    int numMonths = (maxYear - minYear + 1) * 12 + 1;

    // Initialize the running epochDay as the corresponding ISO Epoch day
    int epochMonth = 0; // index into array of epochMonths
    int[] epochMonths = new int[numMonths];
    minMonthLength = Integer.MAX_VALUE;
    maxMonthLength = Integer.MIN_VALUE;

    // Only whole years are valid, any zero's in the array are illegal
    for (int year = minYear; year <= maxYear; year++) {
      int[] months = years.get(year); // must not be gaps
      for (int month = 0; month < 12; month++) {
        int length = months[month];
        epochMonths[epochMonth++] = epochDay;

        if (length < 29 || length > 32) {
          throw new IllegalArgumentException("Invalid month length in year: " + minYear);
        }
        epochDay += length;
        minMonthLength = Math.min(minMonthLength, length);
        maxMonthLength = Math.max(maxMonthLength, length);
      }
    }

    // Insert the final epochDay
    epochMonths[epochMonth++] = epochDay;

    if (epochMonth != epochMonths.length) {
      throw new IllegalStateException(
          "Did not fill epochMonths exactly: ndx = "
              + epochMonth
              + " should be "
              + epochMonths.length);
    }

    return epochMonths;
  }
Ejemplo n.º 13
0
  @Override
  public void engineStore(KeyStore.LoadStoreParameter param)
      throws IOException, NoSuchAlgorithmException, CertificateException {
    if (param instanceof DomainLoadStoreParameter) {
      DomainLoadStoreParameter domainParameter = (DomainLoadStoreParameter) param;
      List<KeyStoreBuilderComponents> builders =
          getBuilders(domainParameter.getConfiguration(), domainParameter.getProtectionParams());

      for (KeyStoreBuilderComponents builder : builders) {

        try {

          KeyStore.ProtectionParameter pp = builder.protection;
          if (!(pp instanceof KeyStore.PasswordProtection)) {
            throw new KeyStoreException(
                new IllegalArgumentException(
                    "ProtectionParameter" + " must be a KeyStore.PasswordProtection"));
          }
          char[] password = ((KeyStore.PasswordProtection) builder.protection).getPassword();

          // Store the keystores
          KeyStore keystore = keystores.get(builder.name);

          try (FileOutputStream stream = new FileOutputStream(builder.file)) {

            keystore.store(stream, password);
          }
        } catch (KeyStoreException e) {
          throw new IOException(e);
        }
      }
    } else {
      throw new UnsupportedOperationException(
          "This keystore must be stored using a " + "DomainLoadStoreParameter");
    }
  }
Ejemplo n.º 14
0
  /*
   * Parse a keystore domain configuration file and associated collection
   * of keystore passwords to create a collection of KeyStore.Builder.
   */
  private List<KeyStoreBuilderComponents> getBuilders(
      URI configuration, Map<String, KeyStore.ProtectionParameter> passwords) throws IOException {

    PolicyParser parser = new PolicyParser(true); // expand properties
    Collection<PolicyParser.DomainEntry> domains = null;
    List<KeyStoreBuilderComponents> builders = new ArrayList<>();
    String uriDomain = configuration.getFragment();

    try (InputStreamReader configurationReader =
        new InputStreamReader(PolicyUtil.getInputStream(configuration.toURL()), "UTF-8")) {
      parser.read(configurationReader);
      domains = parser.getDomainEntries();

    } catch (MalformedURLException mue) {
      throw new IOException(mue);

    } catch (PolicyParser.ParsingException pe) {
      throw new IOException(pe);
    }

    for (PolicyParser.DomainEntry domain : domains) {
      Map<String, String> domainProperties = domain.getProperties();

      if (uriDomain != null && (!uriDomain.equalsIgnoreCase(domain.getName()))) {
        continue; // skip this domain
      }

      if (domainProperties.containsKey(ENTRY_NAME_SEPARATOR)) {
        this.entryNameSeparator = domainProperties.get(ENTRY_NAME_SEPARATOR);
        // escape any regex meta characters
        char ch = 0;
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < this.entryNameSeparator.length(); i++) {
          ch = this.entryNameSeparator.charAt(i);
          if (REGEX_META.indexOf(ch) != -1) {
            s.append('\\');
          }
          s.append(ch);
        }
        this.entryNameSeparatorRegEx = s.toString();
      }

      Collection<PolicyParser.KeyStoreEntry> keystores = domain.getEntries();
      for (PolicyParser.KeyStoreEntry keystore : keystores) {
        String keystoreName = keystore.getName();
        Map<String, String> properties = new HashMap<>(domainProperties);
        properties.putAll(keystore.getProperties());

        String keystoreType = DEFAULT_KEYSTORE_TYPE;
        if (properties.containsKey(KEYSTORE_TYPE)) {
          keystoreType = properties.get(KEYSTORE_TYPE);
        }

        Provider keystoreProvider = null;
        if (properties.containsKey(KEYSTORE_PROVIDER_NAME)) {
          String keystoreProviderName = properties.get(KEYSTORE_PROVIDER_NAME);
          keystoreProvider = Security.getProvider(keystoreProviderName);
          if (keystoreProvider == null) {
            throw new IOException("Error locating JCE provider: " + keystoreProviderName);
          }
        }

        File keystoreFile = null;
        if (properties.containsKey(KEYSTORE_URI)) {
          String uri = properties.get(KEYSTORE_URI);

          try {
            if (uri.startsWith("file://")) {
              keystoreFile = new File(new URI(uri));
            } else {
              keystoreFile = new File(uri);
            }

          } catch (URISyntaxException | IllegalArgumentException e) {
            throw new IOException(
                "Error processing keystore property: " + "keystoreURI=\"" + uri + "\"", e);
          }
        }

        KeyStore.ProtectionParameter keystoreProtection = null;
        if (passwords.containsKey(keystoreName)) {
          keystoreProtection = passwords.get(keystoreName);

        } else if (properties.containsKey(KEYSTORE_PASSWORD_ENV)) {
          String env = properties.get(KEYSTORE_PASSWORD_ENV);
          String pwd = System.getenv(env);
          if (pwd != null) {
            keystoreProtection = new KeyStore.PasswordProtection(pwd.toCharArray());
          } else {
            throw new IOException(
                "Error processing keystore property: " + "keystorePasswordEnv=\"" + env + "\"");
          }
        } else {
          keystoreProtection = new KeyStore.PasswordProtection(null);
        }

        builders.add(
            new KeyStoreBuilderComponents(
                keystoreName, keystoreType, keystoreProvider, keystoreFile, keystoreProtection));
      }
      break; // skip other domains
    }
    if (builders.isEmpty()) {
      throw new IOException("Error locating domain configuration data " + "for: " + configuration);
    }

    return builders;
  }
Ejemplo n.º 15
0
  private Map<String, j86.com.sun.jdi.connect.Connector.Argument> parseConnectorArgs(
      Connector connector, String argString) {
    Map<String, j86.com.sun.jdi.connect.Connector.Argument> arguments =
        connector.defaultArguments();

    /*
     * We are parsing strings of the form:
     *    name1=value1,[name2=value2,...]
     * However, the value1...valuen substrings may contain
     * embedded comma(s), so make provision for quoting inside
     * the value substrings. (Bug ID 4285874)
     */
    String regexPattern =
        "(quote=[^,]+,)|"
            + // special case for quote=.,
            "(\\w+=)"
            + // name=
            "(((\"[^\"]*\")|"
            + //   ( "l , ue"
            "('[^']*')|"
            + //     'l , ue'
            "([^,'\"]+))+,)"; //     v a l u e )+ ,
    Pattern p = Pattern.compile(regexPattern);
    Matcher m = p.matcher(argString);
    while (m.find()) {
      int startPosition = m.start();
      int endPosition = m.end();
      if (startPosition > 0) {
        /*
         * It is an error if parsing skips over any part of argString.
         */
        throw new IllegalArgumentException(
            MessageOutput.format("Illegal connector argument", argString));
      }

      String token = argString.substring(startPosition, endPosition);
      int index = token.indexOf('=');
      String name = token.substring(0, index);
      String value = token.substring(index + 1, token.length() - 1); // Remove comma delimiter

      /*
       * for values enclosed in quotes (single and/or double quotes)
       * strip off enclosing quote chars
       * needed for quote enclosed delimited substrings
       */
      if (name.equals("options")) {
        StringBuilder sb = new StringBuilder();
        for (String s : splitStringAtNonEnclosedWhiteSpace(value)) {
          while (isEnclosed(s, "\"") || isEnclosed(s, "'")) {
            s = s.substring(1, s.length() - 1);
          }
          sb.append(s);
          sb.append(" ");
        }
        value = sb.toString();
      }

      Connector.Argument argument = arguments.get(name);
      if (argument == null) {
        throw new IllegalArgumentException(
            MessageOutput.format(
                "Argument is not defined for connector:", new Object[] {name, connector.name()}));
      }
      argument.setValue(value);

      argString = argString.substring(endPosition); // Remove what was just parsed...
      m = p.matcher(argString); //    and parse again on what is left.
    }
    if ((!argString.equals(",")) && (argString.length() > 0)) {
      /*
       * It is an error if any part of argString is left over,
       * unless it was empty to begin with.
       */
      throw new IllegalArgumentException(
          MessageOutput.format("Illegal connector argument", argString));
    }
    return arguments;
  }