use of com.xpn.xwiki.validation.XWikiValidationInterface in project xwiki-platform by xwiki.
the class XWikiDocument method executeValidationScript.
private boolean executeValidationScript(XWikiContext context, String validationScript) {
try {
ContextualAuthorizationManager authorization = Utils.getComponent(ContextualAuthorizationManager.class);
DocumentReference validationScriptReference = getCurrentDocumentReferenceResolver().resolve(validationScript, getDocumentReference());
// Make sure target document is allowed to execute Groovy
// TODO: this check should probably be right in XWiki#parseGroovyFromPage
authorization.checkAccess(Right.PROGRAM, validationScriptReference);
XWikiValidationInterface validObject = (XWikiValidationInterface) context.getWiki().parseGroovyFromPage(validationScript, context);
return validObject.validateDocument(this, context);
} catch (Throwable e) {
XWikiValidationStatus.addExceptionToContext(getFullName(), "", e, context);
return false;
}
}
use of com.xpn.xwiki.validation.XWikiValidationInterface in project xwiki-platform by xwiki.
the class BaseClass method executeValidationScript.
private boolean executeValidationScript(BaseObject obj, String validationScript, XWikiContext context) {
try {
ContextualAuthorizationManager authorization = Utils.getComponent(ContextualAuthorizationManager.class);
DocumentReference validationScriptReference = getCurrentDocumentReferenceResolver().resolve(validationScript, getDocumentReference());
// Make sure target document is allowed to execute Groovy
// TODO: this check should probably be right in XWiki#parseGroovyFromPage
authorization.checkAccess(Right.PROGRAM, validationScriptReference);
XWikiValidationInterface validObject = (XWikiValidationInterface) context.getWiki().parseGroovyFromPage(validationScript, context);
return validObject.validateObject(obj, context);
} catch (Throwable e) {
XWikiValidationStatus.addExceptionToContext(getName(), "", e, context);
return false;
}
}
use of com.xpn.xwiki.validation.XWikiValidationInterface in project xwiki-platform by xwiki.
the class XWikiDocumentMockitoTest method testValidate.
@Test
public void testValidate() throws XWikiException, AccessDeniedException {
this.document.setValidationScript("validationScript");
this.baseClass.setValidationScript("validationScript");
doReturn(new XWikiValidationInterface() {
@Override
public boolean validateObject(BaseObject object, XWikiContext context) {
return true;
}
@Override
public boolean validateDocument(XWikiDocument doc, XWikiContext context) {
return true;
}
}).when(this.oldcore.getSpyXWiki()).parseGroovyFromPage("validationScript", this.oldcore.getXWikiContext());
// With PR
assertTrue(this.document.validate(this.oldcore.getXWikiContext()));
assertTrue(this.baseClass.validateObject(this.baseObject, this.oldcore.getXWikiContext()));
// Without PR
doThrow(AccessDeniedException.class).when(this.oldcore.getMockContextualAuthorizationManager()).checkAccess(Right.PROGRAM, new DocumentReference("wiki", "space", "validationScript"));
assertFalse(this.document.validate(this.oldcore.getXWikiContext()));
assertFalse(this.baseClass.validateObject(this.baseObject, this.oldcore.getXWikiContext()));
}
Aggregations