Пример #1
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);
  }
  @org.junit.Test
  public void testIntermediaryTransformationCaching() throws Exception {

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

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

    URL wsdl = IntermediaryTransformationCachingTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1EndorsingPort");
    DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportPort, PORT);
    if (standalone) {
      TokenTestUtils.updateSTSPort((BindingProvider) transportPort, STSPORT);
    }

    // Make initial successful invocation
    doubleIt(transportPort, 25);

    // Make another invocation - this should work as the intermediary caches the token
    // even though its STSClient is disabled after the first invocation
    doubleIt(transportPort, 30);

    bus.shutdown(true);
  }