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

File CurrentUserAndGroupEntityReferenceResolver.java

 

Coverage histogram

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

Code metrics

4
6
2
1
70
36
4
0.67
3
2
2

Classes

Class Line # Actions
CurrentUserAndGroupEntityReferenceResolver 44 6 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.authorization.internal.resolver;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.model.EntityType;
28    import org.xwiki.model.internal.reference.AbstractStringEntityReferenceResolver;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.EntityReferenceProvider;
31    import org.xwiki.security.internal.XWikiConstants;
32   
33    /**
34    * Resolve a String representing an user or group Entity Reference into an
35    * {@link org.xwiki.model.reference.EntityReference} object. The difference with
36    * {@link com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceValueProvider} is that the default space is
37    * always {@link XWikiConstants#XWIKI_SPACE}.
38    *
39    * @version $Id: 6b9ef566a1c9c8b5d841e2107f496aaea2e4ebc6 $
40    * @since 6.2M1
41    */
42    @Component(hints = {"user/current", "group/current"})
43    @Singleton
 
44    public class CurrentUserAndGroupEntityReferenceResolver extends AbstractStringEntityReferenceResolver
45    {
46    @Inject
47    @Named("current")
48    private EntityReferenceProvider provider;
49   
 
50  60 toggle @Override
51    public EntityReference resolve(String entityReferenceRepresentation, EntityType type, Object... parameters)
52    {
53    // Special case: if null is passed then consider it's the guest user and return null.
54  60 if (entityReferenceRepresentation == null) {
55  1 return null;
56    } else {
57  59 return super.resolve(entityReferenceRepresentation, type, parameters);
58    }
59    }
60   
 
61  41 toggle @Override
62    protected EntityReference getDefaultReference(EntityType type, Object... parameters)
63    {
64  41 if (type == EntityType.SPACE) {
65  2 return XWikiConstants.XWIKI_SPACE_REFERENCE;
66    } else {
67  39 return this.provider.getDefaultReference(type);
68    }
69    }
70    }