コード例 #1
0
ファイル: UsernameTokenTest.java プロジェクト: CMoH/cxf
  @org.junit.Test
  public void testPlaintextPrincipal() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = UsernameTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPrincipalPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (test.isStreaming()) {
      SecurityTestUtil.enableStreaming(utPort);
    }

    ((BindingProvider) utPort).getRequestContext().put(SecurityConstants.USERNAME, "Alice");
    utPort.doubleIt(25);

    try {
      ((BindingProvider) utPort).getRequestContext().put(SecurityConstants.USERNAME, "Frank");
      utPort.doubleIt(30);
      fail("Failure expected on a user with the wrong role");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
      String error = "Unauthorized";
      assertTrue(ex.getMessage().contains(error));
    }

    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
  }
コード例 #2
0
  @org.junit.Test
  public void testUsernameOnBehalfOf() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = UsernameOnBehalfOfTest.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    URL wsdl = UsernameOnBehalfOfTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItOBOAsymmetricSAML2BearerPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    TokenTestUtils.updateSTSPort((BindingProvider) port, test.getStsPort());

    if (test.isStreaming()) {
      SecurityTestUtil.enableStreaming(port);
    }

    // Transport port
    ((BindingProvider) port).getRequestContext().put("ws-security.username", "alice");
    doubleIt(port, 25);

    ((java.io.Closeable) port).close();

    DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port2, test.getPort());

    TokenTestUtils.updateSTSPort((BindingProvider) port2, test.getStsPort());

    if (test.isStreaming()) {
      SecurityTestUtil.enableStreaming(port2);
    }

    ((BindingProvider) port2).getRequestContext().put("ws-security.username", "eve");
    // This time we expect a failure as the server validator doesn't accept "eve".
    try {
      doubleIt(port2, 30);
      fail("Failure expected on an unknown user");
    } catch (Exception ex) {
      // expected
    }

    ((java.io.Closeable) port2).close();
    bus.shutdown(true);
  }
コード例 #3
0
  public void connect(TokenHolder tokenHolder) {
    for (Class<? extends PublicInterface> interface1 : interfaces) {
      JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
      cpfb.setServiceClass(interface1);
      cpfb.setAddress(address + "/" + interface1.getSimpleName());
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put("mtom-enabled", Boolean.TRUE);
      cpfb.setProperties(properties);

      PublicInterface serviceInterface = (PublicInterface) cpfb.create();

      client = ClientProxy.getClient(serviceInterface);
      HTTPConduit http = (HTTPConduit) client.getConduit();
      http.getClient().setConnectionTimeout(360000);
      http.getClient().setAllowChunking(false);
      http.getClient().setReceiveTimeout(320000);

      if (!useSoapHeaderSessions) {
        ((BindingProvider) serviceInterface)
            .getRequestContext()
            .put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
      }
      add(interface1.getName(), serviceInterface);
    }
    tokenHolder.registerTokenChangeListener(this);
    notifyOfConnect();
  }
コード例 #4
0
  public void init() {
    Bus oldbus = BusFactory.getThreadDefaultBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
      GreeterService service =
          new GreeterService(GreeterTargetBean.class.getResource("/wsdl/hello_world.wsdl"));
      greeter = service.getGreeterPort();
      if (address != null) {
        ((BindingProvider) greeter)
            .getRequestContext()
            .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
      }
      client = ClientProxy.getClient(greeter);
      System.out.println("Greeter endpoint: " + client.getEndpoint().getEndpointInfo());

    } catch (RuntimeException e) {
      e.printStackTrace();
      throw e;
    } catch (Error e) {
      e.printStackTrace();
      throw e;
    } finally {
      BusFactory.setThreadDefaultBus(oldbus);
    }
  }
コード例 #5
0
  private PIXConsumerPortType getPort(String url) {
    PIXConsumerPortType port = nhinService.getPIXConsumerPortSoap();

    log.info("Setting endpoint address to Nhin Subject Discovery Service to " + url);
    ((BindingProvider) port)
        .getRequestContext()
        .put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

    return port;
  }
  private AdapterSubscriptionManagerPortType getPort(String url) {
    AdapterSubscriptionManagerPortType port = service.getAdapterSubscriptionManagerPortSoap();

    log.info("Setting endpoint address to Nhin Hiem Subscribe Service to " + url);
    ((BindingProvider) port)
        .getRequestContext()
        .put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

    return port;
  }
コード例 #7
0
  private NotificationConsumer getPort(String url) {
    NotificationConsumer port = nhinService.getNotificationConsumerPort();

    log.info("Setting endpoint address to Nhin Hiem Notify Service to " + url);
    ((BindingProvider) port)
        .getRequestContext()
        .put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

    return port;
  }
コード例 #8
0
  private static VboxPortType getPortType(String url) {
    if (null == port) {
      VboxService svc = new VboxService();
      port = svc.getVboxServicePort();
      ((BindingProvider) port)
          .getRequestContext()
          .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    }

    return port;
  }
コード例 #9
0
  private static VboxPortType getPortType() {
    if (null == port) {
      VboxService svc = new VboxService();
      port = svc.getVboxServicePort();
      ((BindingProvider) port)
          .getRequestContext()
          .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:18083/");
    }

    return port;
  }
コード例 #10
0
  private EntityNotificationProducerSecuredPortType getPort(String url) {
    EntityNotificationProducerSecuredPortType port =
        service.getEntityNotificationProducerSecuredPortSoap();

    log.info("Setting endpoint address to Entity Notification Secured Service to " + url);
    ((BindingProvider) port)
        .getRequestContext()
        .put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

    return port;
  }
コード例 #11
0
  public HelloClient() throws Exception {
    QName qname = new QName("http://ws.examples.jboss.com/", "HelloWorldImplService");
    URL wsdl = new URL("http://localhost:8080/helloWorld/Simple?wsdl");

    Service service = Service.create(wsdl, qname);
    port = service.getPort(HelloWorldPortType.class);

    ((BindingProvider) port)
        .getRequestContext()
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/helloWorld/Simple");
  }
コード例 #12
0
ファイル: ServiceC.java プロジェクト: mattbmtrain/appc
  @Override
  public int jumble(int leftOne, int rightOne, int leftTwo, int rightTwo) {

    String serviceCclientId = "822f1b79-3758-42b8-a168-3be466253ab4";

    String url = "https://api.apim.ibmcloud.com/mbrightau1ibmcom-dev/sb";
    Map<String, List<String>> serviceARequestHeaders = new HashMap<String, List<String>>();
    serviceARequestHeaders.put("X-IBM-Client-Id", Collections.singletonList(serviceCclientId));

    IServiceA serviceA = new ServiceAService().getServiceAPort();
    ((BindingProvider) serviceA)
        .getRequestContext()
        .put(MessageContext.HTTP_REQUEST_HEADERS, serviceARequestHeaders);
    ((BindingProvider) serviceA)
        .getRequestContext()
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url + "/ServiceAService");

    IServiceB serviceB = new ServiceBService().getServiceBPort();
    ((BindingProvider) serviceB)
        .getRequestContext()
        .put(MessageContext.HTTP_REQUEST_HEADERS, serviceARequestHeaders);
    ((BindingProvider) serviceB)
        .getRequestContext()
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url + "/ServiceBService");

    int result = serviceB.minus(serviceA.plus(leftOne, rightOne), serviceA.plus(leftTwo, rightTwo));

    LOGGER.info(
        "leftOne="
            + leftOne
            + ", rightOne="
            + rightOne
            + ",leftTwo="
            + leftTwo
            + ", rightTwo="
            + rightTwo
            + ", result="
            + result);

    return result;
  }
コード例 #13
0
  public static ListsSoap getListsClient(String username, String password, String endPointAddress) {
    if (username == null || username.isEmpty()) {
      throw new IllegalArgumentException("username can't be null or empty.");
    }

    if (password == null || username.isEmpty()) {
      throw new IllegalArgumentException("password can't be null or empty.");
    }

    if (endPointAddress == null || username.isEmpty()) {
      throw new IllegalArgumentException("endPointAddress can't be null or empty.");
    }

    Lists service = new Lists();
    ListsSoap port = service.getListsSoap();

    ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
    ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
    ((BindingProvider) port)
        .getRequestContext()
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPointAddress);

    return port;
  }
コード例 #14
0
ファイル: ColdMigration.java プロジェクト: mikelopez/jvm
  private static void putVMFiles(String remoteFilePath, String localFilePath) throws Exception {
    String serviceUrl = url.substring(0, url.lastIndexOf("sdk") - 1);
    String httpUrl =
        serviceUrl + "/folder" + remoteFilePath + "?dcPath=" + datacenter + "&dsName=" + datastore;
    httpUrl = httpUrl.replaceAll("\\ ", "%20");
    System.out.println("Putting VM File " + httpUrl);
    URL fileURL = new URL(httpUrl);
    HttpURLConnection conn = (HttpURLConnection) fileURL.openConnection();
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setAllowUserInteraction(true);

    // Maintain session
    List cookies = (List) headers.get("Set-cookie");
    cookieValue = (String) cookies.get(0);
    StringTokenizer tokenizer = new StringTokenizer(cookieValue, ";");
    cookieValue = tokenizer.nextToken();
    String path = "$" + tokenizer.nextToken();
    String cookie = "$Version=\"1\"; " + cookieValue + "; " + path;

    // set the cookie in the new request header
    Map map = new HashMap();
    map.put("Cookie", Collections.singletonList(cookie));
    ((BindingProvider) vimPort).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, map);

    conn.setRequestProperty("Cookie", cookie);
    conn.setRequestProperty("Content-Type", "application/octet-stream");
    conn.setRequestMethod("PUT");
    conn.setRequestProperty("Content-Length", "1024");
    long fileLen = new File(localFilePath).length();
    System.out.println("File size is: " + fileLen);
    conn.setChunkedStreamingMode((int) fileLen);
    OutputStream out = conn.getOutputStream();
    InputStream in = new BufferedInputStream(new FileInputStream(localFilePath));
    int bufLen = 9 * 1024;
    byte[] buf = new byte[bufLen];
    byte[] tmp = null;
    int len = 0;
    while ((len = in.read(buf, 0, bufLen)) != -1) {
      tmp = new byte[len];
      System.arraycopy(buf, 0, tmp, 0, len);
      out.write(tmp, 0, len);
    }
    in.close();
    out.close();
    conn.getResponseMessage();
    conn.disconnect();
  }
コード例 #15
0
 @Override
 public void newToken(String token) {
   if (useSoapHeaderSessions) {
     for (PublicInterface p : getServiceInterfaces().values()) {
       List<Header> headers = new ArrayList<Header>();
       try {
         Token tokenObject = new Token(token);
         Header sessionHeader =
             new Header(
                 new QName("uri:org.bimserver.shared", "token"),
                 tokenObject,
                 new JAXBDataBinding(Token.class));
         headers.add(sessionHeader);
       } catch (JAXBException e) {
         LOGGER.error("", e);
       }
       ((BindingProvider) p).getRequestContext().put(Header.HEADER_LIST, headers);
     }
   }
 }
コード例 #16
0
  /**
   * This method retrieves the port for the UDDI server with the correct endpoint.
   *
   * @return
   */
  private UDDIInquiryPortType getUDDIInquiryWebService() throws UDDIAccessorException {
    UDDIInquiryPortType oPort = null;

    try {
      UDDIService oService = new UDDIService();
      oPort = oService.getUDDIInquiryPort();

      // Need to load in the correct UDDI endpoint URL address.
      // --------------------------------------------------------
      ((BindingProvider) oPort)
          .getRequestContext()
          .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, m_sUDDIInquiryEndpointURL);
    } catch (Exception e) {
      String sErrorMessage =
          "Failed to retrieve the UDDI Inquiry Web Service port.  Error: " + e.getMessage();
      log.error(sErrorMessage, e);
      throw new UDDIAccessorException(sErrorMessage, e);
    }

    return oPort;
  }
コード例 #17
0
ファイル: DemoAuth.java プロジェクト: stefanbirkner/java
  /** @param args */
  public static void main(String[] args) {
    try {
      Properties props = new Properties();
      if (args.length == 0) {
        props.load(new FileInputStream("demo.properties"));
      } else {
        props.load(new FileInputStream(args[0]));
      }

      ObjectFactory of = new ObjectFactory();

      Amount amount = new Amount();
      amount.setValue(Long.parseLong(props.getProperty("amount.value")));
      amount.setCurrency(props.getProperty("amount.currency"));

      Card card = new Card();
      card.setCvc(props.getProperty("card.cvc"));
      card.setExpiryMonth(props.getProperty("card.expiryMonth"));
      card.setExpiryYear(props.getProperty("card.expiryYear"));
      card.setHolderName(props.getProperty("card.holderName"));
      card.setNumber(props.getProperty("card.number"));

      PaymentRequest pr = new PaymentRequest();
      pr.setAmount(of.createPaymentRequestAmount(amount));
      pr.setCard(of.createPaymentRequestCard(card));
      pr.setMerchantAccount(
          of.createPaymentRequestMerchantAccount(props.getProperty("merchantAccount")));
      pr.setReference(
          of.createPaymentRequestReference(
              props.getProperty("reference") + "-" + System.currentTimeMillis()));
      pr.setShopperIP(of.createPaymentRequestShopperIP(props.getProperty("shopperIP")));
      pr.setShopperReference(
          of.createPaymentRequestShopperReference(props.getProperty("shopperReference")));

      // Create a dynamic Service instance
      Payment payment = new Payment();

      PaymentPortType port = payment.getPort(PaymentPortType.class);

      ((BindingProvider) port)
          .getRequestContext()
          .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, props.getProperty("url"));
      ((BindingProvider) port)
          .getRequestContext()
          .put(BindingProvider.USERNAME_PROPERTY, props.getProperty("username"));
      ((BindingProvider) port)
          .getRequestContext()
          .put(BindingProvider.PASSWORD_PROPERTY, props.getProperty("password"));

      PaymentResult result = port.authorise(pr);

      System.out.println(
          "Payment result resultCode="
              + result.getResultCode().getValue()
              + " pspReference="
              + result.getPspReference().getValue()
              + " auth="
              + result.getAuthCode().getValue()
              + " refusalReason="
              + result.getRefusalReason().getValue());

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #18
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    /**
     * SOAP settings - wsdl: the WSDL url you are using (Test/Live) - wsUser: your web service user
     * to modify Payouts - wsPassword: your web service user's password
     */
    String wsdl = "https://pal-test.adyen.com/pal/servlet/soap/Payout?wsdl";
    String wsUser = "******";
    String wsPassword = "******";

    /**
     * Create SOAP client, using classes in adyen-wsdl-cxf.jar library (generated by wsdl2java tool,
     * Apache CXF).
     *
     * @see WebContent/WEB-INF/lib/adyen-wsdl-cxf.jar
     */
    PayoutService service = new PayoutService(new URL(wsdl));
    PayoutPortType client = service.getPayoutHttpPort();

    // Set HTTP Authentication
    ((BindingProvider) client).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, wsUser);
    ((BindingProvider) client)
        .getRequestContext()
        .put(BindingProvider.PASSWORD_PROPERTY, wsPassword);

    /**
     * You can decline a Payout by sending a decline request to the Payout service. The following
     * fields are sent:
     *
     * <pre>
     * - merchantAccount    : The merchant account used in the Payout payment.
     * - originalReference  : The PSP reference received after the Payout was submitted.
     * </pre>
     */
    ModifyRequest declineRequest = new ModifyRequest();
    declineRequest.setMerchantAccount("YourMerchantAccount");
    declineRequest.setOriginalReference("ThePspReferenceOfThePayout");

    /** Send the decline payout request. */
    ModifyResponse declineResult = client.decline(declineRequest);

    /**
     * If the message is syntactically valid and merchantAccount is correct you will receive a
     * declineResponse with the following fields:
     *
     * <pre>
     * - pspReference      : A new reference to uniquely identify this request. This reference will be the
     *                       pspReference of the payment.
     * - response          : In case of success, this will be [payout-decline-received] or, in case of an error,
     *                       an informational message will be returned.
     * </pre>
     *
     * The actual result of the declined Payout is sent via a notification with eventCode
     * REFUND_WITH_DATA. The success field indicates if the Payout was successful (true) or not
     * (false). If false, the reason field of the notification will give a short description why. We
     * send back the PSP reference of the Payout as originalReference.
     */
    PrintWriter out = response.getWriter();

    out.println("Decline Payout Result:");
    out.println("- pspReference: " + declineResult.getPspReference());
    out.println("- response: " + declineResult.getResponse());
  }
コード例 #19
0
  /**
   * Why does this return a web service? Going directly to the IUnifiedRepository requires the
   * following:
   *
   * <p>
   *
   * <ul>
   *   <li>PentahoSessionHolder setup including password and tenant ID. (The server doesn't even
   *       process passwords today-- it assumes that Spring Security processed it. This would
   *       require code changes.)
   *   <li>User must specify path to Jackrabbit files (i.e. system/jackrabbit).
   * </ul>
   */
  protected synchronized IUnifiedRepository getRepository() throws ParseException {
    if (repository != null) {
      return repository;
    }

    final String NAMESPACE_URI = "http://www.pentaho.org/ws/1.0"; // $NON-NLS-1$
    final String SERVICE_NAME = "unifiedRepository"; // $NON-NLS-1$

    String urlString =
        getOptionValue(
                Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_URL_KEY"),
                Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_URL_NAME"),
                true,
                false)
            .trim();
    if (urlString.endsWith("/")) {
      urlString = urlString.substring(0, urlString.length() - 1);
    }
    urlString = urlString + "/webservices/" + SERVICE_NAME + "?wsdl";

    URL url;
    try {
      url = new URL(urlString);
    } catch (MalformedURLException e) {
      throw new IllegalArgumentException(e);
    }

    Service service = Service.create(url, new QName(NAMESPACE_URI, SERVICE_NAME));
    IUnifiedRepositoryJaxwsWebService port =
        service.getPort(IUnifiedRepositoryJaxwsWebService.class);
    // http basic authentication
    ((BindingProvider) port)
        .getRequestContext()
        .put(
            BindingProvider.USERNAME_PROPERTY,
            getOptionValue(
                Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_USERNAME_KEY"),
                Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_USERNAME_NAME"),
                true,
                false));
    ((BindingProvider) port)
        .getRequestContext()
        .put(
            BindingProvider.PASSWORD_PROPERTY,
            getOptionValue(
                Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_PASSWORD_KEY"),
                Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_PASSWORD_NAME"),
                true,
                true));
    // accept cookies to maintain session on server
    ((BindingProvider) port)
        .getRequestContext()
        .put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    // support streaming binary data
    // TODO mlowery this is not portable between JAX-WS implementations
    // (uses com.sun)
    ((BindingProvider) port)
        .getRequestContext()
        .put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
    binding.setMTOMEnabled(true);
    final UnifiedRepositoryToWebServiceAdapter unifiedRepositoryToWebServiceAdapter =
        new UnifiedRepositoryToWebServiceAdapter(port);
    repository = unifiedRepositoryToWebServiceAdapter;
    return unifiedRepositoryToWebServiceAdapter;
  }