Add information to SAML parser exceptions

Include namespaces and location of expected/found elements

Closes #29698

Signed-off-by: esagalara <erik.sagalara@gmail.com>
This commit is contained in:
esagalara 2024-05-20 16:13:36 +02:00 committed by Marek Posolda
parent cdfd46f191
commit 42eec96f61
3 changed files with 17 additions and 15 deletions

View file

@ -441,14 +441,10 @@ public class DefaultPicketLinkLogger implements PicketLinkLogger {
return new RuntimeException(expectedXsi); return new RuntimeException(expectedXsi);
} }
/*
*(non-Javadoc)
*
*@see org.picketlink.identity.federation.PicketLinkLogger#parserExpectedTag(java.lang.String, java.lang.String)
*/
@Override @Override
public RuntimeException parserExpectedTag(String tag, String foundElementTag) { public RuntimeException parserExpectedTag(String tag, String foundElementTag, Integer line, Integer column) {
return new RuntimeException(ErrorCodes.EXPECTED_TAG + tag + ". Found <" + foundElementTag + ">"); return new RuntimeException(ErrorCodes.EXPECTED_TAG + " " + tag + ". Found " + foundElementTag +
" at line " + line.toString() + ", column " + column);
} }
@Override @Override
@ -2386,7 +2382,7 @@ public class DefaultPicketLinkLogger implements PicketLinkLogger {
@Override @Override
public ProcessingException samlExtensionUnknownChild(Class<?> clazz) { public ProcessingException samlExtensionUnknownChild(Class<?> clazz) {
return new ProcessingException("Unknown child type specified for extension: " return new ProcessingException("Unknown child type specified for extension: "
+ (clazz == null ? "<null>" : clazz.getSimpleName()) + (clazz == null ? "<null>" : clazz.getSimpleName())
+ "."); + ".");
} }

View file

@ -291,10 +291,12 @@ public interface PicketLinkLogger {
/** /**
* @param tag * @param tag
* @param foundElementTag * @param foundElementTag
* @param line
* @param column
* *
* @return * @return
*/ */
RuntimeException parserExpectedTag(String tag, String foundElementTag); RuntimeException parserExpectedTag(String tag, String foundElementTag, Integer line, Integer column);
/** /**
* @param ns * @param ns
@ -1229,4 +1231,4 @@ public interface PicketLinkLogger {
ProcessingException samlAssertionWrongAudience(String serviceURL); ProcessingException samlAssertionWrongAudience(String serviceURL);
ProcessingException samlExtensionUnknownChild(Class<?> clazz); ProcessingException samlExtensionUnknownChild(Class<?> clazz);
} }

View file

@ -880,8 +880,10 @@ public class StaxParserUtil {
@Deprecated @Deprecated
public static void validate(StartElement startElement, String tag) { public static void validate(StartElement startElement, String tag) {
String foundElementTag = StaxParserUtil.getElementName(startElement); String foundElementTag = StaxParserUtil.getElementName(startElement);
if (!tag.equals(foundElementTag)) if (!tag.equals(foundElementTag)) {
throw logger.parserExpectedTag(tag, foundElementTag); Location location = startElement.getLocation();
throw logger.parserExpectedTag(tag, foundElementTag, location.getLineNumber(), location.getColumnNumber());
}
} }
/** /**
@ -894,8 +896,10 @@ public class StaxParserUtil {
*/ */
public static void validate(StartElement startElement, QName tag) { public static void validate(StartElement startElement, QName tag) {
if (! Objects.equals(startElement.getName(), tag)) { if (! Objects.equals(startElement.getName(), tag)) {
String foundElementTag = StaxParserUtil.getElementName(startElement); Location location = startElement.getLocation();
throw logger.parserExpectedTag(tag.getLocalPart(), foundElementTag); throw logger.parserExpectedTag(
tag.toString(), startElement.getName().toString(),
location.getLineNumber(), location.getColumnNumber());
} }
} }
@ -943,4 +947,4 @@ public class StaxParserUtil {
} }
} }
} }
} }