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

File DefaultXWikiBridge.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

12
23
4
1
107
67
12
0.52
5.75
4
3

Classes

Class Line # Actions
DefaultXWikiBridge 42 23 0% 12 10
0.7435897674.4%
 

Contributing tests

This file is covered by 20 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.security.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.model.reference.DocumentReferenceResolver;
29    import org.xwiki.model.reference.WikiReference;
30    import org.xwiki.security.authorization.Right;
31   
32    import com.xpn.xwiki.XWikiContext;
33   
34    /**
35    * Temporary implementation of the (@link XWikiBridge} interface to access xwiki information.
36    *
37    * @version $Id: 1a69058b20cd5e9205406e747195ca556723832e $
38    * @since 4.0M2
39    */
40    @Component
41    @Singleton
 
42    public class DefaultXWikiBridge implements XWikiBridge
43    {
44    /** Document reference resolver for user and group. */
45    @Inject
46    @Named("user")
47    private DocumentReferenceResolver<String> resolver;
48   
49    @Inject
50    private Provider<XWikiContext> xcontextProvider;
51   
52    /** Cached main wiki reference. */
53    private WikiReference mainWikiReference;
54   
 
55  80 toggle @Override
56    public WikiReference getMainWikiReference()
57    {
58  80 if (mainWikiReference == null) {
59  80 mainWikiReference = new WikiReference(xcontextProvider.get().getMainXWiki());
60    }
61  80 return mainWikiReference;
62    }
63   
 
64  16324 toggle @Override
65    public boolean isWikiReadOnly()
66    {
67  16324 return xcontextProvider.get().getWiki().isReadOnly();
68    }
69   
 
70  6448 toggle @Override
71    public boolean needsAuthentication(Right right)
72    {
73  6448 XWikiContext context = xcontextProvider.get();
74  6448 String prefName = "authenticate_" + right.getName();
75   
76  6448 String value = context.getWiki().getXWikiPreference(prefName, "", context);
77  6448 Boolean result = checkNeedsAuthValue(value);
78  6448 if (result != null) {
79  0 return result;
80    }
81   
82  6448 value = context.getWiki().getSpacePreference(prefName, "", context).toLowerCase();
83  6449 result = checkNeedsAuthValue(value);
84  6449 if (result != null) {
85  0 return result;
86    }
87   
88  6449 return false;
89    }
90   
 
91  12897 toggle private Boolean checkNeedsAuthValue(String value)
92    {
93  12898 if (value != null && !value.equals("")) {
94  50 if (value.toLowerCase().equals("yes")) {
95  0 return true;
96    }
97  50 try {
98  0 if (Integer.parseInt(value) > 0) {
99  0 return true;
100    }
101    } catch (NumberFormatException e) {
102  50 return null;
103    }
104    }
105  12847 return null;
106    }
107    }