use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class STSRESTTest method testIssueSymmetricKeySaml1.
@org.junit.Test
public void testIssueSymmetricKeySaml1() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = STSRESTTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token";
WebClient client = WebClient.create(address, busFile.toString());
client.accept("application/xml");
client.path("saml1.1");
client.query("keyType", SYMMETRIC_KEY_KEYTYPE);
Response response = client.get();
Document assertionDoc = response.readEntity(Document.class);
assertNotNull(assertionDoc);
// Process the token
List<WSSecurityEngineResult> results = processToken(assertionDoc.getDocumentElement());
assertTrue(results != null && results.size() == 1);
SamlAssertionWrapper assertion = (SamlAssertionWrapper) results.get(0).get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(assertion != null);
assertTrue(assertion.getSaml2() == null && assertion.getSaml1() != null);
assertTrue(assertion.isSigned());
List<String> methods = assertion.getConfirmationMethods();
String confirmMethod = null;
if (methods != null && !methods.isEmpty()) {
confirmMethod = methods.get(0);
}
assertTrue(OpenSAMLUtil.isMethodHolderOfKey(confirmMethod));
SAMLKeyInfo subjectKeyInfo = assertion.getSubjectKeyInfo();
assertTrue(subjectKeyInfo.getSecret() != null);
bus.shutdown(true);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class STSRESTTest method testValidateSAML2Token.
@org.junit.Test
public void testValidateSAML2Token() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = STSRESTTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token";
WebClient client = WebClient.create(address, busFile.toString());
client.type("application/xml").accept("application/xml");
client.path("saml2.0");
// 1. Get a token via GET
Response response = client.get();
Document assertionDoc = response.readEntity(Document.class);
assertNotNull(assertionDoc);
// 2. Now validate it in the STS using POST
client = WebClient.create(address, busFile.toString());
client.type("application/xml").accept("application/xml");
client.query("action", "validate");
// Create RequestSecurityToken
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
String namespace = STSUtils.WST_NS_05_12;
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Validate");
writer.writeEndElement();
writer.writeStartElement("wst", "TokenType", namespace);
String tokenType = namespace + "/RSTR/Status";
writer.writeCharacters(tokenType);
writer.writeEndElement();
writer.writeStartElement("wst", "ValidateTarget", namespace);
StaxUtils.copy(assertionDoc.getDocumentElement(), writer);
writer.writeEndElement();
writer.writeEndElement();
response = client.post(new DOMSource(writer.getDocument().getDocumentElement()));
RequestSecurityTokenResponseType securityResponse = response.readEntity(RequestSecurityTokenResponseType.class);
StatusType status = null;
for (Object obj : securityResponse.getAny()) {
if (obj instanceof JAXBElement<?>) {
JAXBElement<?> jaxbElement = (JAXBElement<?>) obj;
if ("Status".equals(jaxbElement.getName().getLocalPart())) {
status = (StatusType) jaxbElement.getValue();
break;
}
}
}
assertNotNull(status);
// Check the token was valid
String validCode = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/status/valid";
assertEquals(validCode, status.getCode());
bus.shutdown(true);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class STSRESTTest method testExplicitlyIssueSAML1TokenViaPOST.
@org.junit.Test
public void testExplicitlyIssueSAML1TokenViaPOST() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = STSRESTTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token";
WebClient client = WebClient.create(address, busFile.toString());
client.type("application/xml").accept("application/xml");
client.query("action", "issue");
// Create RequestSecurityToken
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
String namespace = STSUtils.WST_NS_05_12;
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Issue");
writer.writeEndElement();
writer.writeStartElement("wst", "TokenType", namespace);
writer.writeCharacters(SAML1_TOKEN_TYPE);
writer.writeEndElement();
writer.writeEndElement();
Response response = client.post(new DOMSource(writer.getDocument().getDocumentElement()));
RequestSecurityTokenResponseType securityResponse = response.readEntity(RequestSecurityTokenResponseType.class);
validateSAMLSecurityTokenResponse(securityResponse, false);
bus.shutdown(true);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class STSRESTTest method testIssueSAML2TokenViaWSTrust.
@org.junit.Test
public void testIssueSAML2TokenViaWSTrust() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = STSRESTTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token";
WebClient client = WebClient.create(address, busFile.toString());
client.accept("application/xml");
client.path("saml2.0");
client.query("wstrustResponse", "true");
Response response = client.get();
RequestSecurityTokenResponseType securityResponse = response.readEntity(RequestSecurityTokenResponseType.class);
validateSAMLSecurityTokenResponse(securityResponse, true);
bus.shutdown(true);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class STSRESTTest method testIssueBearerSAML1Token.
@org.junit.Test
public void testIssueBearerSAML1Token() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = STSRESTTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
String address = "https://localhost:" + STSPORT + "/SecurityTokenService/token";
WebClient client = WebClient.create(address, busFile.toString());
client.accept("application/xml");
client.path("saml1.1");
client.query("keyType", BEARER_KEYTYPE);
Response response = client.get();
Document assertionDoc = response.readEntity(Document.class);
assertNotNull(assertionDoc);
// Process the token
List<WSSecurityEngineResult> results = processToken(assertionDoc.getDocumentElement());
assertTrue(results != null && results.size() == 1);
SamlAssertionWrapper assertion = (SamlAssertionWrapper) results.get(0).get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertTrue(assertion != null);
assertTrue(assertion.getSaml2() == null && assertion.getSaml1() != null);
assertTrue(assertion.isSigned());
List<String> methods = assertion.getConfirmationMethods();
String confirmMethod = null;
if (methods != null && !methods.isEmpty()) {
confirmMethod = methods.get(0);
}
assertTrue(confirmMethod.contains("bearer"));
bus.shutdown(true);
}
Aggregations