Search in sources :

Example 1 with AuthorExecutor

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));
}
Also used : Query(org.xwiki.query.Query) AuthorExecutor(org.xwiki.security.authorization.AuthorExecutor) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with AuthorExecutor

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;
}
Also used : AuthorExecutor(org.xwiki.security.authorization.AuthorExecutor) ArrayList(java.util.ArrayList) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Aggregations

AuthorExecutor (org.xwiki.security.authorization.AuthorExecutor)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 Query (org.xwiki.query.Query)1