ESAPI.override()
構成をオーバーライドするためだけに使用されます。他の種類のメソッドを拡張するには、私の場合AntiSamy.scan
、呼び出し構造内のすべてのクラスを拡張する必要があります。
これは、柔軟性のない実装が原因です。たとえば、次の場所にありますHTMLValidationRule.java
。
private String invokeAntiSamy( String context, String input ) throws ValidationException {
// CHECKME should this allow empty Strings? " " us IsBlank instead?
if ( StringUtilities.isEmpty(input) ) {
if (allowNull) {
return null;
}
throw new ValidationException( context + " is required", "AntiSamy validation error: context=" + context + ", input=" + input, context );
}
String canonical = super.getValid( context, input );
try {
AntiSamy as = new AntiSamy();
CleanResults test = as.scan(canonical, antiSamyPolicy);
List<String> errors = test.getErrorMessages();
if ( !errors.isEmpty() ) {
LOGGER.info( Logger.SECURITY_FAILURE, "Cleaned up invalid HTML input: " + errors );
}
return test.getCleanHTML().trim();
} catch (ScanException e) {
throw new ValidationException( context + ": Invalid HTML input", "Invalid HTML input: context=" + context + " error=" + e.getMessage(), e, context );
} catch (PolicyException e) {
throw new ValidationException( context + ": Invalid HTML input", "Invalid HTML input does not follow rules in antisamy-esapi.xml: context=" + context + " error=" + e.getMessage(), e, context );
}
}
AntiSamy as = new AntiSamy();
カスタム実装では使用できないためです。