Exemplo n.º 1
0
  @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);
  }
Exemplo n.º 2
0
  @org.junit.Test
  public void testPlaintext() 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, "DoubleItPlaintextPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

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

    utPort.doubleIt(25);

    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
  }
Exemplo n.º 3
0
  @org.junit.Test
  public void testNoUsernameToken() 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, "DoubleItInlinePolicyPort");
    DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

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

    try {
      utPort.doubleIt(25);
      fail("Failure expected on no UsernameToken");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
      String error = "The received token does not match the token inclusion requirement";
      assertTrue(
          ex.getMessage().contains(error)
              || ex.getMessage().contains("UsernameToken not satisfied"));
    }

    ((java.io.Closeable) utPort).close();
    bus.shutdown(true);
  }
 @org.junit.AfterClass
 public static void cleanup() throws Exception {
   SecurityTestUtil.cleanup();
   stopAllServers();
 }