use of org.apache.cxf.systest.sts.common.CommonCallbackHandler in project cxf by apache.
the class IssueUnitTest method testSAMLinWSSecToOtherRealm.
@org.junit.Test
public void testSAMLinWSSecToOtherRealm() throws Exception {
createBus(getClass().getResource("cxf-client.xml").toString());
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
CallbackHandler callbackHandler = new CommonCallbackHandler();
// Create SAML token
Element samlToken = createSAMLAssertion(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, crypto, "mystskey", callbackHandler, null, "alice", "a-issuer");
String id = null;
QName elName = DOMUtils.getElementQName(samlToken);
if (elName.equals(new QName(WSS4JConstants.SAML_NS, "Assertion")) && samlToken.hasAttributeNS(null, "AssertionID")) {
id = samlToken.getAttributeNS(null, "AssertionID");
} else if (elName.equals(new QName(WSS4JConstants.SAML2_NS, "Assertion")) && samlToken.hasAttributeNS(null, "ID")) {
id = samlToken.getAttributeNS(null, "ID");
}
if (id == null) {
id = samlToken.getAttributeNS(WSS4JConstants.WSU_NS, "Id");
}
SecurityToken wstoken = new SecurityToken(id, samlToken, null, null);
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.TOKEN, wstoken);
properties.put(SecurityConstants.TOKEN_ID, wstoken.getId());
// Get a token
SecurityToken token = requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, null, bus, DEFAULT_ADDRESS, null, properties, "b-issuer", "Transport_SAML_Port");
/*
SecurityToken token =
requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, null,
bus, DEFAULT_ADDRESS, null, properties, "b-issuer", null);
*/
assertEquals(SAML2_TOKEN_TYPE, token.getTokenType());
assertNotNull(token.getToken());
List<WSSecurityEngineResult> results = processToken(token);
assertTrue(results != null && results.size() == 1);
SamlAssertionWrapper assertion = (SamlAssertionWrapper) results.get(0).get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
assertNotNull(assertion);
assertTrue(assertion.isSigned());
List<String> methods = assertion.getConfirmationMethods();
String confirmMethod = null;
if (methods != null && !methods.isEmpty()) {
confirmMethod = methods.get(0);
}
assertTrue(confirmMethod != null && confirmMethod.contains("bearer"));
assertEquals("b-issuer", assertion.getIssuerString());
String subjectName = assertion.getSaml2().getSubject().getNameID().getValue();
assertEquals("Subject must be ALICE instead of " + subjectName, "ALICE", subjectName);
}
use of org.apache.cxf.systest.sts.common.CommonCallbackHandler in project cxf by apache.
the class SAMLDelegationTest method testTransportForgedDelegationToken.
@org.junit.Test
public void testTransportForgedDelegationToken() throws Exception {
createBus(getClass().getResource("cxf-client.xml").toString());
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
CallbackHandler callbackHandler = new CommonCallbackHandler();
// Create SAML token
Element samlToken = createSAMLAssertion(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE, crypto, "eve", callbackHandler, "alice", "a-issuer");
try {
requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, samlToken, bus, DEFAULT_ADDRESS, true, "Transport_Port");
fail("Failure expected on a forged delegation token");
} catch (Exception ex) {
// expected
}
try {
requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, samlToken, bus, DEFAULT_ADDRESS, false, "Transport_Port");
fail("Failure expected on a forged delegation token");
} catch (Exception ex) {
// expected
}
}
Aggregations