1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.query.internal

File SecureQueryExecutorManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
7
2
1
75
39
4
0.57
3.5
2
2

Classes

Class Line # Actions
SecureQueryExecutorManager 48 7 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.query.internal;
21   
22    import java.util.List;
23    import java.util.Set;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.query.Query;
31    import org.xwiki.query.QueryException;
32    import org.xwiki.query.QueryExecutorManager;
33    import org.xwiki.query.SecureQuery;
34    import org.xwiki.security.authorization.ContextualAuthorizationManager;
35    import org.xwiki.security.authorization.Right;
36   
37    /**
38    * {@link QueryExecutorManager} with access rights checking.
39    *
40    * @version $Id: 0235c94dfc04045b6f2c16f348655f23cb1cd6b7 $
41    */
42    // Note that we force the Component annotation so that this component is only registered as a QueryExecutorManager
43    // and not a QueryExecutor too since we don't want this manager to be visible to users as a valid QueryExecutor
44    // component.
45    @Component(roles = { QueryExecutorManager.class })
46    @Named("secure")
47    @Singleton
 
48    public class SecureQueryExecutorManager implements QueryExecutorManager
49    {
50    @Inject
51    private QueryExecutorManager defaultQueryExecutorManager;
52   
53    @Inject
54    private ContextualAuthorizationManager authorization;
55   
 
56  399 toggle @Override
57    public <T> List<T> execute(Query query) throws QueryException
58    {
59  399 if (query instanceof SecureQuery) {
60  397 SecureQuery secureQuery = (SecureQuery) query;
61    // Force checking current author rights
62  397 secureQuery.checkCurrentAuthor(true);
63  2 } else if (!this.authorization.hasAccess(Right.PROGRAM)) {
64  1 throw new QueryException("Unsecure query require programming right", query, null);
65    }
66   
67  398 return this.defaultQueryExecutorManager.execute(query);
68    }
69   
 
70  422 toggle @Override
71    public Set<String> getLanguages()
72    {
73  422 return this.defaultQueryExecutorManager.getLanguages();
74    }
75    }