// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/STSServer.java
// public class STSServer extends AbstractBusTestServerBase {
// 
//     public STSServer() {
// 
//     }
// 
//     protected void run()  {
//         URL busFile = STSServer.class.getResource("cxf-sts.xml");
//         Bus busLocal = new SpringBusFactory().createBus(busFile);
//         BusFactory.setDefaultBus(busLocal);
//         setBus(busLocal);
// 
//         try {
//             new STSServer();
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/TokenTestUtils.java
// public final class TokenTestUtils {
//     
//     private TokenTestUtils() {
//         // complete
//     }
//     
//     public static void updateSTSPort(BindingProvider p, String port) {
//         STSClient stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT);
//         if (stsClient != null) {
//             String location = stsClient.getWsdlLocation();
//             if (location != null && location.contains("8080")) {
//                 stsClient.setWsdlLocation(location.replace("8080", port));
//             } else if (location != null && location.contains("8443")) {
//                 stsClient.setWsdlLocation(location.replace("8443", port));
//             }
//         }
//         stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
//         if (stsClient != null) {
//             String location = stsClient.getWsdlLocation();
//             if (location.contains("8080")) {
//                 stsClient.setWsdlLocation(location.replace("8080", port));
//             } else if (location.contains("8443")) {
//                 stsClient.setWsdlLocation(location.replace("8443", port));
//             }
//         }
//     }
// 
// }


import org.apache.coheigea.cxf.sts.xacml.common.TokenTestUtils;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.coheigea.cxf.sts.xacml.common.STSServer;
		        launchServer(PdpServer.class, true));
	}

	private DoubleItPortType doubleItWsPort = null;

	@Before
	public void beforeTest() throws Exception
	{
		/*
		 * Client
		 */
		final URL busFile = RESTfulPdpBasedAuthzInterceptorTest.class.getResource("cxf-ws-client.xml");
		this.createBus(busFile.toString());
		BusFactory.setThreadDefaultBus(this.getBus());
		final Service service = Service.create(DOUBLEIT_WSDL, SERVICE_QNAME);
		doubleItWsPort = service.getPort(DOUBLEIT_WS_PORT_QNAME, DoubleItPortType.class);
	}

	private static void doubleIt(final DoubleItPortType port, final int numToDouble)
	{
		final int resp = port.doubleIt(numToDouble);
		assertEquals(numToDouble * 2, resp);
	}

	@org.junit.Test
	public void testAuthorizedRequest() throws Exception
	{
		updateAddressPort(doubleItWsPort, PORT);
		final Client cxfClient = ClientProxy.getClient(doubleItWsPort);
		cxfClient.getRequestContext().put("ws-security.username", "alice");
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/STSServer.java
// public class STSServer extends AbstractBusTestServerBase {
// 
//     public STSServer() {
// 
//     }
// 
//     protected void run()  {
//         URL busFile = STSServer.class.getResource("cxf-sts.xml");
//         Bus busLocal = new SpringBusFactory().createBus(busFile);
//         BusFactory.setDefaultBus(busLocal);
//         setBus(busLocal);
// 
//         try {
//             new STSServer();
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/TokenTestUtils.java
// public final class TokenTestUtils {
//     
//     private TokenTestUtils() {
//         // complete
//     }
//     
//     public static void updateSTSPort(BindingProvider p, String port) {
//         STSClient stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT);
//         if (stsClient != null) {
//             String location = stsClient.getWsdlLocation();
//             if (location != null && location.contains("8080")) {
//                 stsClient.setWsdlLocation(location.replace("8080", port));
//             } else if (location != null && location.contains("8443")) {
//                 stsClient.setWsdlLocation(location.replace("8443", port));
//             }
//         }
//         stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
//         if (stsClient != null) {
//             String location = stsClient.getWsdlLocation();
//             if (location.contains("8080")) {
//                 stsClient.setWsdlLocation(location.replace("8080", port));
//             } else if (location.contains("8443")) {
//                 stsClient.setWsdlLocation(location.replace("8443", port));
//             }
//         }
//     }
// 
// }


// Path: webapp/src/test/java/org/ow2/authzforce/webapp/test/pep/cxf/RESTfulPdpBasedAuthzInterceptorTest.java
import org.apache.coheigea.cxf.sts.xacml.common.TokenTestUtils;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.coheigea.cxf.sts.xacml.common.STSServer;

		        launchServer(PdpServer.class, true));
	}

	private DoubleItPortType doubleItWsPort = null;

	@Before
	public void beforeTest() throws Exception
	{
		/*
		 * Client
		 */
		final URL busFile = RESTfulPdpBasedAuthzInterceptorTest.class.getResource("cxf-ws-client.xml");
		this.createBus(busFile.toString());
		BusFactory.setThreadDefaultBus(this.getBus());
		final Service service = Service.create(DOUBLEIT_WSDL, SERVICE_QNAME);
		doubleItWsPort = service.getPort(DOUBLEIT_WS_PORT_QNAME, DoubleItPortType.class);
	}

	private static void doubleIt(final DoubleItPortType port, final int numToDouble)
	{
		final int resp = port.doubleIt(numToDouble);
		assertEquals(numToDouble * 2, resp);
	}

	@org.junit.Test
	public void testAuthorizedRequest() throws Exception
	{
		updateAddressPort(doubleItWsPort, PORT);
		final Client cxfClient = ClientProxy.getClient(doubleItWsPort);
		cxfClient.getRequestContext().put("ws-security.username", "alice");
		TokenTestUtils.updateSTSPort((BindingProvider) doubleItWsPort, STS_PORT);