use of org.apache.cxf.Bus in project wildfly by wildfly.
the class WSTrustTestCase method testUsingEPR.
/**
* WS-Trust test with the STS information coming from EPR specified in service endpoint contract policy
*
* @throws Exception
*/
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void testUsingEPR() throws Exception {
Bus bus = BusFactory.newInstance().createBus();
try {
BusFactory.setThreadDefaultBus(bus);
final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
final URL wsdlURL = new URL(serviceURL + "SecurityService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
WSTrustTestUtils.setupWsse(proxy, bus);
try {
assertEquals("WS-Trust Hello World!", proxy.sayHello());
} catch (Exception e) {
throw e;
}
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.Bus in project wildfly by wildfly.
the class WSTrustTestCase method testNoClientCallback.
/**
* No CallbackHandler is provided in STSCLient. Username and password provided instead.
*
* @throws Exception
*/
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void testNoClientCallback() throws Exception {
Bus bus = BusFactory.newInstance().createBus();
try {
BusFactory.setThreadDefaultBus(bus);
final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
final URL wsdlURL = new URL(serviceURL + "SecurityService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
final QName stsServiceName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService");
final QName stsPortName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port");
URL stsURL = new URL(serviceURL.getProtocol(), serviceURL.getHost(), serviceURL.getPort(), "/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl");
WSTrustTestUtils.setupWsseAndSTSClientNoCallbackHandler(proxy, bus, stsURL.toString(), stsServiceName, stsPortName);
assertEquals("WS-Trust Hello World!", proxy.sayHello());
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.Bus in project wildfly by wildfly.
the class WSTrustTestCase method testActAs.
/**
* Request a security token that allows it to act as if it were somebody else.
*
* @throws Exception
*/
@Test
@RunAsClient
@OperateOnDeployment(ACT_AS_SERVER_DEP)
@WrapThreadContextClassLoader
public void testActAs() throws Exception {
Bus bus = BusFactory.newInstance().createBus();
try {
BusFactory.setThreadDefaultBus(bus);
final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/actaswssecuritypolicy", "ActAsService");
final URL wsdlURL = new URL(serviceURL + "ActAsService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
ActAsServiceIface proxy = (ActAsServiceIface) service.getPort(ActAsServiceIface.class);
WSTrustTestUtils.setupWsseAndSTSClientActAs((BindingProvider) proxy, bus);
assertEquals("ActAs WS-Trust Hello World!", proxy.sayHello(serviceURL.getHost(), String.valueOf(serviceURL.getPort())));
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.Bus in project tomee by apache.
the class SaajInterceptor method registerInterceptors.
public static synchronized void registerInterceptors() {
if (!interceptorsRegistered) {
final Bus bus = CxfUtil.getBus();
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
try {
SaajUniverse universe = new SaajUniverse();
bus.getOutInterceptors().add(new SaajOutInterceptor(universe));
bus.getInInterceptors().add(new SaajInInterceptor(universe));
bus.getInInterceptors().add(new SaajInFaultInterceptor(universe));
} finally {
if (oldLoader != null) {
CxfUtil.clearBusLoader(oldLoader);
}
}
interceptorsRegistered = true;
}
}
use of org.apache.cxf.Bus in project ddf by codice.
the class StsIssueTest method testBearerPkiTokenSaml2.
/**
* Test the User PKI Token
*/
public void testBearerPkiTokenSaml2(StsPortTypes portType) throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = StsIssueTest.class.getResource("/cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
SpringBusFactory.setDefaultBus(bus);
SpringBusFactory.setThreadDefaultBus(bus);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
// Build the Claims object
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.writeStartElement(WST, CLAIMS, STSUtils.WST_NS_05_12);
writer.writeNamespace(WST, STSUtils.WST_NS_05_12);
writer.writeNamespace(IC, IDENTITY_URI);
writer.writeAttribute(DIALECT, IDENTITY_URI);
// Add the Role claim
writer.writeStartElement(IC, CLAIM_TYPE, IDENTITY_URI);
writer.writeAttribute("URI", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
writer.writeEndElement();
Element claims = writer.getDocument().getDocumentElement();
// Alerternatively we can use a certificate to request a SAML
X509Security oboToken = new X509Security(doc);
Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties");
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias("client");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
if (null != certs) {
oboToken.setX509Certificate(certs[0]);
// Get a token
SecurityToken token = requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, oboToken.getElement(), bus, StsAddresses.valueOf(portType.toString()).toString(), WsdlLocations.valueOf(portType.toString()).toString(), EndPoints.valueOf(portType.toString()).toString(), claims);
if (token != null) {
validateSecurityToken(token);
}
}
bus.shutdown(true);
}
Aggregations