use of org.apache.wss4j.common.saml.SAMLCallback in project cxf by apache.
the class SamlRetrievalInterceptor method handleMessage.
@Override
public void handleMessage(Message message) throws Fault {
// Create a SAML Token
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(new SamlCallbackHandler(), samlCallback);
try {
SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
Document doc = DOMUtils.createDocument();
Element token = assertion.toDOM(doc);
message.put(SAMLConstants.SAML_TOKEN_ELEMENT, token);
} catch (WSSecurityException ex) {
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
throw new Fault(new RuntimeException(ex.getMessage() + ", stacktrace: " + sw.toString()));
}
}
use of org.apache.wss4j.common.saml.SAMLCallback in project cxf by apache.
the class SamlElementCallbackHandler method getSAMLAssertion.
/**
* Mock up a SAML Assertion by using another SAMLCallbackHandler
* @throws Exception
*/
private Element getSAMLAssertion(Document doc) throws Exception {
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(new SamlCallbackHandler(saml2), samlCallback);
SamlAssertionWrapper assertionWrapper = new SamlAssertionWrapper(samlCallback);
return assertionWrapper.toDOM(doc);
}
use of org.apache.wss4j.common.saml.SAMLCallback in project cxf by apache.
the class SCTSAMLTokenProvider method createSamlToken.
private SamlAssertionWrapper createSamlToken(TokenProviderParameters tokenParameters, byte[] secret, Document doc) throws Exception {
SamlCallbackHandler handler = createCallbackHandler(tokenParameters, secret, doc);
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(handler, samlCallback);
SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
if (signToken) {
STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
// Get the password
String alias = stsProperties.getSignatureUsername();
WSPasswordCallback[] cb = { new WSPasswordCallback(alias, WSPasswordCallback.SIGNATURE) };
LOG.fine("Creating SAML Token");
stsProperties.getCallbackHandler().handle(cb);
String password = cb[0].getPassword();
LOG.fine("Signing SAML Token");
boolean useKeyValue = stsProperties.getSignatureProperties().isUseKeyValue();
assertion.signAssertion(alias, password, stsProperties.getSignatureCrypto(), useKeyValue);
}
return assertion;
}
use of org.apache.wss4j.common.saml.SAMLCallback in project cxf by apache.
the class OAuth2TestUtils method createToken.
public static String createToken(String audRestr, boolean saml2, boolean sign) throws WSSecurityException {
SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(sign);
samlCallbackHandler.setAudience(audRestr);
if (!saml2) {
samlCallbackHandler.setSaml2(false);
samlCallbackHandler.setConfirmationMethod(SAML1Constants.CONF_BEARER);
}
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(samlCallbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
if (samlCallback.isSignAssertion()) {
samlAssertion.signAssertion(samlCallback.getIssuerKeyName(), samlCallback.getIssuerKeyPassword(), samlCallback.getIssuerCrypto(), samlCallback.isSendKeyValue(), samlCallback.getCanonicalizationAlgorithm(), samlCallback.getSignatureAlgorithm());
}
return samlAssertion.assertionToString();
}
use of org.apache.wss4j.common.saml.SAMLCallback in project tesb-rt-se by Talend.
the class SamlCallbackHandler method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof SAMLCallback) {
SAMLCallback callback = (SAMLCallback) callbacks[i];
callback.setSamlVersion(SAMLVersion.VERSION_20);
callback.setIssuer("alice");
String subjectName = "uid=auth_client";
SubjectBean subjectBean = new SubjectBean(subjectName, null, SAML2Constants.CONF_SENDER_VOUCHES);
callback.setSubject(subjectBean);
AttributeStatementBean attrBean = new AttributeStatementBean();
if (subjectBean != null) {
attrBean.setSubject(subjectBean);
}
AttributeBean attributeBean = new AttributeBean();
attributeBean.setQualifiedName("attribute-role");
attributeBean.setAttributeValues(Collections.singletonList((Object) "authenticated-client"));
attrBean.setSamlAttributes(Collections.singletonList(attributeBean));
callback.setAttributeStatementData(Collections.singletonList(attrBean));
}
}
}
Aggregations