Closed Jess103 closed 1 year ago
Ok it was the line break in assertion that was making this whole issue. I just replaced the special characters like "
 ;" and "
 ;" and it magically works so well now.. wow....
Hi Jess103, I'm tryng to follow your suggest but I continue to have your same error. Here my code
` try { InitializationService.initialize(); } catch (InitializationException e) { // TODO Auto-generated catch block e.printStackTrace(); } org.opensaml.saml.saml2.core.impl.StatusCodeBuilder statusCodeBuilder = new org.opensaml.saml.saml2.core.impl.StatusCodeBuilder(); StatusCode statusCode = statusCodeBuilder.buildObject(); statusCode.setValue(StatusCode.SUCCESS);
org.opensaml.saml.saml2.core.impl.StatusBuilder statusBuilder = new org.opensaml.saml.saml2.core.impl.StatusBuilder();
org.opensaml.saml.saml2.core.Status status = statusBuilder.buildObject();
status.setStatusCode(statusCode);
org.opensaml.saml.saml2.core.impl.IssuerBuilder issuerBuilder = new org.opensaml.saml.saml2.core.impl.IssuerBuilder();
org.opensaml.saml.saml2.core.Issuer issuer = issuerBuilder.buildObject();
issuer.setValue("https://example.com/issuer");
org.opensaml.saml.saml2.core.impl.ResponseBuilder responseBuilder = new org.opensaml.saml.saml2.core.impl.ResponseBuilder();
org.opensaml.saml.saml2.core.Response response = responseBuilder.buildObject();
response.setID(UUID.randomUUID().toString());
response.setVersion(SAMLVersion.VERSION_20);
response.setIssuer(issuer);
response.setStatus(status);
response.setIssueInstant(new DateTime()); // Specifica la data e l'ora di creazione della Response
org.opensaml.saml.saml2.core.impl.AssertionBuilder assertionBuilder = new org.opensaml.saml.saml2.core.impl.AssertionBuilder();
org.opensaml.saml.saml2.core.Assertion assertion = assertionBuilder.buildObject();
assertion.setID(UUID.randomUUID().toString());
assertion.setIssueInstant(new DateTime());
assertion.setSubject(createSubject("provai1",11));
org.opensaml.saml.saml2.core.Issuer issuer2 = issuerBuilder.buildObject();
issuer2.setValue("https://example.com/issuer");
assertion.setIssuer(issuer2);
/* OneLogin */
// 1. Sign Assertion > Turn signed string back to Assertion
org.opensaml.saml.saml2.core.impl.AssertionMarshaller aMarshaller = new org.opensaml.saml.saml2.core.impl.AssertionMarshaller();
String astStr = null;
try {
astStr = Util.addSign(aMarshaller.marshall(assertion), privateKey, cert, null);
astStr = astStr.replace(" ", "").replace("
", "");
} catch (XPathExpressionException | ParserConfigurationException | XMLSecurityException
| MarshallingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
assertion = (Assertion) stringTOobject(astStr);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 2. Add Assertion into Response
response.getAssertions().add(assertion);
// 3. Sign Response > Turn signed string back to Response
org.opensaml.saml.saml2.core.impl.ResponseMarshaller marshaller = new org.opensaml.saml.saml2.core.impl.ResponseMarshaller();
String resStr = null;
try {
resStr = Util.addSign(marshaller.marshall(response), privateKey, cert, null);
resStr = resStr.replace(" ", "").replace("
", "");
} catch (XPathExpressionException | ParserConfigurationException | XMLSecurityException
| MarshallingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
response = (org.opensaml.saml.saml2.core.Response) stringTOobject(resStr);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 4. To XMLString
try {
String samlStr = SerializeSupport.nodeToString(marshaller.marshall(response));
LOGGER.debug("Result in Base64: "+Util.base64encoder(samlStr));
} catch (MarshallingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}`
but when I tried to execute it, I have this
I'm using this tool to verify my Saml https://samltool.io/
this is the xml generated `<?xml version="1.0" encoding="UTF-8"?>
using this version:
I resolved the problem
Hi,
I have alreay posted the same question in stackoverflow but no luck that I'm submitting the issue here.
Java Version : 8 Validation Check Tool : https://samltool.io/ Signing Assertion Only : Valid Signing Response Only : Valid Signing Both : Response Signature Invalid I tried
sign assertion > add assertion in response > sign response pull out assertion from the response > sign assertion > add agdin in response > sign response but nothing worked; always getting the "Response Signature Invlid" when I sign both. Is signing both using onelogin(java-saml.jar) not allowed? Onelogin Toolkit though spits valid "Sign Message and Assertion"...