use of org.opensaml.common.SAMLObject in project MaxKey by dromara.
the class WebServicePostEncoder method encodeMsgContext.
@SuppressWarnings("rawtypes")
public VelocityContext encodeMsgContext(MessageContext messageContext) throws MessageEncodingException {
SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
SAMLObject outboundMessage = samlMsgCtx.getOutboundSAMLMessage();
if (outboundMessage == null) {
throw new MessageEncodingException("No outbound SAML message contained in message context");
}
signMessage(samlMsgCtx);
samlMsgCtx.setOutboundMessage(outboundMessage);
return encodeMsgContext(samlMsgCtx);
}
use of org.opensaml.common.SAMLObject in project entcore by opendigitaleducation.
the class SamlValidator method decryptAssertion.
private Assertion decryptAssertion(Response response) throws Exception {
EncryptedAssertion encryptedAssertion;
if (response.getEncryptedAssertions() != null && response.getEncryptedAssertions().size() == 1) {
encryptedAssertion = response.getEncryptedAssertions().get(0);
} else {
throw new ValidationException("Encrypted Assertion not found.");
}
BasicX509Credential decryptionCredential = new BasicX509Credential();
decryptionCredential.setPrivateKey(privateKey);
Decrypter decrypter = new Decrypter(null, new StaticKeyInfoCredentialResolver(decryptionCredential), new InlineEncryptedKeyResolver());
decrypter.setRootInNewDocument(true);
Assertion assertion = decrypter.decrypt(encryptedAssertion);
if (assertion != null && assertion.getSubject() != null && assertion.getSubject().getEncryptedID() != null) {
SAMLObject s = decrypter.decrypt(assertion.getSubject().getEncryptedID());
if (s instanceof BaseID) {
assertion.getSubject().setBaseID((BaseID) s);
} else if (s instanceof NameID) {
assertion.getSubject().setNameID((NameID) s);
}
assertion.getSubject().setEncryptedID(null);
}
if (assertion != null && assertion.getAttributeStatements() != null) {
for (AttributeStatement statement : assertion.getAttributeStatements()) {
for (EncryptedAttribute ea : statement.getEncryptedAttributes()) {
Attribute a = decrypter.decrypt(ea);
statement.getAttributes().add(a);
}
statement.getEncryptedAttributes().clear();
}
}
return assertion;
}
Aggregations