use of org.xwiki.security.authorization.AuthorExecutor in project xwiki-platform by xwiki.
the class ExplicitlyAllowedValuesDBListQueryBuilderTest method buildWithScriptRight.
@Test
public void buildWithScriptRight() throws Exception {
DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
when(this.authorizationManager.hasAccess(Right.SCRIPT, authorReference, dbListClass.getReference())).thenReturn(true);
AuthorExecutor authorExector = this.mocker.getInstance(AuthorExecutor.class);
String evaluatedStatement = "test";
when(authorExector.call(any(), eq(authorReference))).thenReturn(evaluatedStatement);
Query query = mock(Query.class);
when(this.secureQueryManager.createQuery(evaluatedStatement, Query.HQL)).thenReturn(query);
assertSame(query, this.mocker.getComponentUnderTest().build(this.dbListClass));
}
use of org.xwiki.security.authorization.AuthorExecutor in project xwiki-platform by xwiki.
the class DBListClass method getDBList.
public List<ListItem> getDBList(XWikiContext context) {
List<ListItem> list = getCachedDBList(context);
if (list == null) {
try {
DefaultParameterizedType dbListQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, DBListClass.class);
QueryBuilder<DBListClass> dbListQueryBuilder = Utils.getComponent(dbListQueryBuilderType);
// Execute the query with the rights of the class last author.
AuthorExecutor authorExecutor = Utils.getComponent(AuthorExecutor.class);
list = makeList(authorExecutor.call(() -> {
return dbListQueryBuilder.build(this).execute();
}, getOwnerDocument().getAuthorReference()));
} catch (Exception e) {
LOGGER.warn("Failed to get the Database List values. Root cause is [{}].", ExceptionUtils.getRootCauseMessage(e));
list = new ArrayList<>();
}
setCachedDBList(list, context);
}
return list;
}
Aggregations