use of ddf.security.samlp.SignatureException in project ddf by codice.
the class LogoutRequestService method getSamlpSoapLogoutResponse.
private Response getSamlpSoapLogoutResponse(LogoutWrapper<LogoutResponse> samlResponse, String statusCode, String statusMessage) {
if (samlResponse == null) {
return Response.serverError().build();
}
LOGGER.debug("Configuring SAML Response for SOAP.");
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement(ROOT_NODE_NAME));
LOGGER.debug("Setting SAML status on Response for SOAP");
if (statusCode != null) {
if (statusMessage != null) {
samlResponse.getMessage().setStatus(SamlProtocol.createStatus(statusCode, statusMessage));
} else {
samlResponse.getMessage().setStatus(SamlProtocol.createStatus(statusCode));
}
}
try {
LOGGER.debug("Signing SAML Response for SOAP.");
LogoutResponse logoutResponse = simpleSign.forceSignSamlObject(samlResponse.getMessage());
Envelope soapMessage = SamlProtocol.createSoapMessage(logoutResponse);
LOGGER.debug("Converting SAML Response to DOM");
String assertionResponse = DOM2Writer.nodeToString(OpenSAMLUtil.toDom(soapMessage, doc));
String encodedSamlResponse = Base64.getEncoder().encodeToString(assertionResponse.getBytes(StandardCharsets.UTF_8));
return Response.ok(encodedSamlResponse).build();
} catch (SignatureException | WSSecurityException | XMLStreamException e) {
LOGGER.debug("Failure constructing SOAP LogoutResponse", e);
return Response.serverError().build();
}
}
use of ddf.security.samlp.SignatureException in project ddf by codice.
the class LogoutRequestService method validateSignature.
private boolean validateSignature(LogoutRequest logoutRequest) {
Signature signature = logoutRequest.getSignature();
if (signature == null) {
LOGGER.debug("Unsigned logoutRequest");
return false;
}
Element dom = logoutRequest.getDOM();
if (dom == null) {
LOGGER.debug("Incorrectly formatted logoutRequest");
return false;
}
try {
simpleSign.validateSignature(signature, dom.getOwnerDocument());
return true;
} catch (SignatureException e) {
LOGGER.debug("Invalid signature on logoutRequest", e);
return false;
}
}
Aggregations