コード例 #1
1
 private static String locationFor(String name) throws RemoteException, RemoteException {
   startManagers();
   URL location = CLASS_SERVLET_CONTEXT.getResource("resources/" + name);
   if (location == null && CLASS_JSP_CONTEXT != null) {
     location = CLASS_JSP_CONTEXT.getResource("resources/" + name);
   }
   if (location == null) {
     log.warn(sm.getString("digesterFactory.missingSchema", name));
     return null;
   }
   return location.toExternalForm();
 }
コード例 #2
0
 /*
  * Ensures that there is payload data ready to read.
  */
 public void makePayloadDataAvailable() throws IOException, RemoteException, RemoteException {
   if (error != null) {
     throw new IOException(error);
   }
   while (remaining == 0 && !frame.getFin()) {
     // Need more data - process next frame
     nextFrame(true);
     while (frame.isControl()) {
       if (frame.getOpCode() == gerenciadornuvem1.Constants23getOpcodePing()) {
         outbound.pong(frame.getPayLoad());
       } else if (frame.getOpCode() == gerenciadornuvem1.Constants23getOpcodePong()) {
         // NO-OP. Swallow it.
       } else if (frame.getOpCode() == gerenciadornuvem1.Constants23getOpcodeClose()) {
         outbound.close(frame);
       } else {
         throw new IOException(sm.getString("is.unknownOpCode", Byte.valueOf(frame.getOpCode())));
       }
       nextFrame(true);
     }
     if (frame.getOpCode() != gerenciadornuvem1.Constants23getOpcodeContinuation()) {
       error = sm.getString("is.notContinuation", Byte.valueOf(frame.getOpCode()));
       throw new IOException(error);
     }
   }
 }
コード例 #3
0
  public void handShake() throws IOException, RemoteException {
    try {
      if (ssl.getWantClientAuth()) {
        log.debug(sm.getString("jsseSupport.noCertWant"));
      } else {
        ssl.setNeedClientAuth(true);
      }

      if (ssl.getEnabledCipherSuites().length == 0) {
        // Handshake is never going to be successful.
        // Assume this is because handshakes are disabled
        log.warn(sm.getString("jsseSupport.serverRenegDisabled"));
        session.invalidate();
        ssl.close();
        return;
      }

      InputStream in = ssl.getInputStream();
      int oldTimeout = ssl.getSoTimeout();
      ssl.setSoTimeout(1000);
      byte[] b = new byte[1];
      listener.reset();
      ssl.startHandshake();
      int maxTries = 60; // 60 * 1000 = example 1 minute time out
      for (int i = 0; i < maxTries; i++) {
        if (log.isTraceEnabled()) log.trace("Reading for try #" + i);
        try {
          int read = in.read(b);
          if (read > 0) {
            // Shouldn't happen as all input should have been swallowed
            // before trying to do the handshake. If it does, something
            // went wrong so lets bomb out now.
            throw new SSLException(sm.getString("jsseSupport.unexpectedData"));
          }
        } catch (SSLException sslex) {
          log.info(sm.getString("jsseSupport.clientCertError"), sslex);
          throw sslex;
        } catch (IOException e) {
          // ignore - presumably the timeout
        }
        if (listener.isCompleted()) {
          break;
        }
      }
      ssl.setSoTimeout(oldTimeout);
      if (listener.isCompleted() == false) {
        throw new SocketException("SSL Cert handshake timeout");
      }

    } catch (Exception excp) {
      excp.printStackTrace();
    }
  }
  /**
   * Listens for {@link LifecycleEvent} for the start of the {@link Server} to initialize itself and
   * then for after_stop events of each {@link Context}.
   */
  @Override
  public void lifecycleEvent(LifecycleEventRemoteInterface event)
      throws RemoteException, RemoteException {
    try {
      Lifecycle lifecycle = event.getLifecycle();
      if (Lifecycle.AFTER_START_EVENT.equals(event.getType()) && lifecycle instanceof Server) {
        // when the server starts, we register ourself as listener for
        // all context
        // as well as container event listener so that we know when new
        // Context are deployed
        Server server = (Server) lifecycle;
        registerListenersForServer(server);
      }

      if (Lifecycle.BEFORE_STOP_EVENT.equals(event.getType()) && lifecycle instanceof Server) {
        // Server is shutting down, so thread pools will be shut down so
        // there is no need to clean the threads
        serverStopping = true;
      }

      if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType()) && lifecycle instanceof Context) {
        stopIdleThreads((Context) lifecycle);
      }
    } catch (Exception e) {
      String msg = sm.getString("threadLocalLeakPreventionListener.lifecycleEvent.error", event);
      log.error(msg, e);
    }
  }
コード例 #5
0
  public java.security.cert.X509Certificate[] getX509Certificates(SSLSession session)
      throws RemoteException {
    try {
      Certificate[] certs = null;
      try {
        certs = session.getPeerCertificates();
      } catch (Throwable t) {
        log.debug(sm.getString("jsseSupport.clientCertError"), t);
        return null;
      }
      if (certs == null) return null;

      java.security.cert.X509Certificate[] x509Certs =
          new java.security.cert.X509Certificate[certs.length];
      for (int i = 0; i < certs.length; i++) {
        if (certs[i] instanceof java.security.cert.X509Certificate) {
          // always currently true with the JSSE 1.1.x
          x509Certs[i] = (java.security.cert.X509Certificate) certs[i];
        } else {
          try {
            byte[] buffer = certs[i].getEncoded();
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
            x509Certs[i] = (java.security.cert.X509Certificate) cf.generateCertificate(stream);
          } catch (Exception ex) {
            log.info(sm.getString("jseeSupport.certTranslationError", certs[i]), ex);
            return null;
          }
        }
        if (log.isTraceEnabled()) log.trace("Cert #" + i + " = " + x509Certs[i]);
      }
      if (x509Certs.length < 1) return null;
      return x509Certs;
    } catch (Exception excp) {
      excp.printStackTrace();
    }
    return null;
  }
 @Override
 public void containerEvent(ContainerEventRemoteInterface event)
     throws RemoteException, RemoteException {
   try {
     String type = event.getType();
     if (Container.ADD_CHILD_EVENT.equals(type)) {
       processContainerAddChild(event.getContainer(), (Container) event.getData());
     } else if (Container.REMOVE_CHILD_EVENT.equals(type)) {
       processContainerRemoveChild(event.getContainer(), (Container) event.getData());
     }
   } catch (Exception e) {
     String msg = sm.getString("threadLocalLeakPreventionListener.containerEvent.error", event);
     log.error(msg, e);
   }
 }
コード例 #7
0
  /**
   * Retrieve the information requested in the provided <code>Callbacks</code>. This implementation
   * only recognizes {@link NameCallback}, {@link PasswordCallback} and {@link TextInputCallback}.
   * {@link TextInputCallback} is used to pass the various additional parameters required for DIGEST
   * authentication.
   *
   * @param callbacks The set of <code>Callback</code>s to be processed
   * @exception IOException if an input/output error occurs
   * @exception UnsupportedCallbackException if the login method requests an unsupported callback
   *     type
   */
  @Override
  public void handle(Callback callbacks[]) throws IOException, UnsupportedCallbackException {
    try {

      for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
          if (realm.getContainer().getLogger().isTraceEnabled())
            realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
          ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
          final char[] passwordcontents;
          if (password != null) {
            passwordcontents = password.toCharArray();
          } else {
            passwordcontents = new char[0];
          }
          ((PasswordCallback) callbacks[i]).setPassword(passwordcontents);
        } else if (callbacks[i] instanceof TextInputCallback) {
          TextInputCallback cb = ((TextInputCallback) callbacks[i]);
          if (cb.getPrompt().equals("nonce")) {
            cb.setText(nonce);
          } else if (cb.getPrompt().equals("nc")) {
            cb.setText(nc);
          } else if (cb.getPrompt().equals("cnonce")) {
            cb.setText(cnonce);
          } else if (cb.getPrompt().equals("qop")) {
            cb.setText(qop);
          } else if (cb.getPrompt().equals("realmName")) {
            cb.setText(realmName);
          } else if (cb.getPrompt().equals("md5a2")) {
            cb.setText(md5a2);
          } else if (cb.getPrompt().equals("authMethod")) {
            cb.setText(authMethod);
          } else {
            throw new UnsupportedCallbackException(callbacks[i]);
          }
        } else {
          throw new UnsupportedCallbackException(callbacks[i]);
        }
      }
    } catch (Exception excp) {
      excp.printStackTrace();
    }
  }
コード例 #8
0
 /**
  * Private constructor, either instantiates a factory to read or write. <br>
  * When openForWrite==true, then a the file, f, will be created and an output stream is opened to
  * write to it. <br>
  * When openForWrite==false, an input stream is opened, the file has to exist.
  *
  * @param f File - the file to be read/written
  * @param openForWrite boolean - true means we are writing to the file, false means we are reading
  *     from the file
  * @throws FileNotFoundException - if the file to be read doesn't exist
  * @throws IOException - if the system fails to open input/output streams to the file or if it
  *     fails to create the file to be written to.
  */
 public FileMessageFactory(File f, boolean openForWrite)
     throws FileNotFoundException, IOException, RemoteException, RemoteException {
   startManagers();
   this.file = f;
   this.openForWrite = openForWrite;
   if (log.isDebugEnabled()) log.debug("open file " + f + " write " + openForWrite);
   if (openForWrite) {
     if (!file.exists())
       if (!file.createNewFile()) {
         throw new IOException(sm.getString("fileNewFail", file));
       }
     out = new FileOutputStream(f);
   } else {
     size = file.length();
     totalNrOfMessages = (size / READ_SIZE) + 1;
     in = new FileInputStream(f);
   } // end if
   creationTime = System.currentTimeMillis();
 }
コード例 #9
0
  @Override
  public InputSource resolveEntity(String name, String publicId, String base, String systemId)
      throws SAXException, IOException {
    try {

      // First try resolving using the publicId
      String resolved = publicIds.get(publicId);
      if (resolved != null) {
        InputSource is = new InputSource(resolved);
        is.setPublicId(publicId);
        return is;
      }

      // If there is no systemId, can't try anything else
      if (systemId == null) {
        throw new FileNotFoundException(
            sm.getString("localResolver.unresolvedEntity", name, publicId, systemId, base));
      }

      // Try resolving with the supplied systemId
      resolved = systemIds.get(systemId);
      if (resolved != null) {
        InputSource is = new InputSource(resolved);
        is.setPublicId(publicId);
        return is;
      }

      // Work-around for XML documents that use just the file name for the
      // location to refer to a JavaEE schema
      for (String javaEENamespace : JAVA_EE_NAMESPACES) {
        String javaEESystemId = javaEENamespace + '/' + systemId;
        resolved = systemIds.get(javaEESystemId);
        if (resolved != null) {
          InputSource is = new InputSource(resolved);
          is.setPublicId(publicId);
          return is;
        }
      }

      // Resolve the supplied systemId against the base
      URI systemUri;
      try {
        if (base == null) {
          systemUri = new URI(systemId);
        } else {
          // Can't use URI.resolve() because "jar:..." URLs are not valid
          // hierarchical URIs so resolve() does not work. new URL()
          // delegates to the jar: stream handler and it manages to figure
          // it out.
          URI baseUri = new URI(base);
          systemUri = new URL(baseUri.toURL(), systemId).toURI();
        }
        systemUri = systemUri.normalize();
      } catch (URISyntaxException e) {
        // May be caused by a | being used instead of a : in an absolute
        // file URI on Windows.
        if (blockExternal) {
          // Absolute paths aren't allowed so block it
          throw new MalformedURLException(e.getMessage());
        } else {
          // See if the URLHandler can resolve it
          return new InputSource(systemId);
        }
      }
      if (systemUri.isAbsolute()) {
        // Try the resolved systemId
        resolved = systemIds.get(systemUri.toString());
        if (resolved != null) {
          InputSource is = new InputSource(resolved);
          is.setPublicId(publicId);
          return is;
        }
        if (!blockExternal) {
          InputSource is = new InputSource(systemUri.toString());
          is.setPublicId(publicId);
          return is;
        }
      }

      throw new FileNotFoundException(
          sm.getString("localResolver.unresolvedEntity", name, publicId, systemId, base));
    } catch (Exception excp) {
      excp.printStackTrace();
    }
    return null;
  }