コード例 #1
0
 private static URI getDummyServiceAddress(URI[] addresses) throws Exception {
   if (!SystemProperties.isSslEnabled()) {
     // In non-ssl mode we just connect to the first address
     return addresses[0];
   }
   final int port = SystemProperties.getServerProxyPort();
   return new URI("https", null, "localhost", port, "/", null, null);
 }
コード例 #2
0
    @Override
    public void soap(SoapMessage message) throws Exception {
      if (request == null) {
        request = new ProxyMessageEncoder(reqOuts, getHashAlgoId());
        outputContentType = request.getContentType();
      }

      // We have the request SOAP message, we can start sending the
      // request to server proxy.
      continueProcessing();

      // In SSL mode, we need to send the OCSP response of our SSL cert.
      if (SystemProperties.isSslEnabled()) {
        writeOcspResponses();
      }

      request.soap(requestSoap);
    }
コード例 #3
0
  private static URI[] getServiceAddresses(ServiceId serviceProvider, SecurityServerId serverId)
      throws Exception {
    log.trace("getServiceAddresses({})", serviceProvider);

    Collection<String> hostNames = GlobalConf.getProviderAddress(serviceProvider.getClientId());
    if (hostNames == null || hostNames.isEmpty()) {
      throw new CodedException(
          X_UNKNOWN_MEMBER,
          "Could not find addresses for service provider \"%s\"",
          serviceProvider);
    }

    if (serverId != null) {
      final String securityServerAddress = GlobalConf.getSecurityServerAddress(serverId);
      if (securityServerAddress == null) {
        throw new CodedException(
            X_INVALID_SECURITY_SERVER, "Could not find security server \"%s\"", serverId);
      }

      if (!hostNames.contains(securityServerAddress)) {
        throw new CodedException(
            X_INVALID_SECURITY_SERVER, "Invalid security server \"%s\"", serviceProvider);
      }

      hostNames = Collections.singleton(securityServerAddress);
    }

    String protocol = SystemProperties.isSslEnabled() ? "https" : "http";
    int port = SystemProperties.getServerProxyPort();

    List<URI> addresses = new ArrayList<>(hostNames.size());
    for (String host : hostNames) {
      addresses.add(new URI(protocol, null, host, port, "/", null, null));
    }

    return addresses.toArray(new URI[] {});
  }
コード例 #4
0
  private void sendRequest(HttpSender httpSender) throws Exception {
    log.trace("sendRequest()");
    try {
      // If we're using SSL, we need to include the provider name in
      // the HTTP request so that server proxy could verify the SSL
      // certificate properly.
      if (SystemProperties.isSslEnabled()) {
        httpSender.setAttribute(AuthTrustVerifier.ID_PROVIDERNAME, requestServiceId);
      }

      // Start sending the request to server proxies. The underlying
      // SSLConnectionSocketFactory will select the fastest address
      // (socket that connects first) from the provided addresses.
      // Dummy service address is only needed so that host name resolving
      // could do its thing and start the ssl connection.
      URI[] addresses = getServiceAddresses(requestServiceId, requestSoap.getSecurityServer());
      httpSender.setAttribute(ID_TARGETS, addresses);
      httpSender.setTimeout(SystemProperties.getClientProxyTimeout());

      httpSender.addHeader(HEADER_HASH_ALGO_ID, getHashAlgoId());
      httpSender.addHeader(HEADER_PROXY_VERSION, ProxyMain.getVersion());

      try {
        httpSender.doPost(
            getDummyServiceAddress(addresses), reqIns, CHUNKED_LENGTH, outputContentType);
      } catch (Exception e) {
        // Failed to connect to server proxy
        MonitorAgent.serverProxyFailed(createRequestMessageInfo());
        // Rethrow
        throw e;
      }
    } finally {
      if (reqIns != null) {
        reqIns.close();
      }
    }
  }