Skip to content

Commit a8a2557

Browse files
authored
XWIKI-23647: Remove use of deprecate DocumentAccessBridge#hasProgrammingRights (#4718)
1 parent c3f7e05 commit a8a2557

File tree

16 files changed

+329
-81
lines changed

16 files changed

+329
-81
lines changed

xwiki-platform-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@
149149
</differences>
150150
</revapi.differences>
151151
-->
152+
153+
<revapi.differences>
154+
<differences>
155+
<item>
156+
<ignore>true</ignore>
157+
<code>java.method.removed</code>
158+
<old>method boolean org.xwiki.bridge.DocumentAccessBridge::hasProgrammingRights()</old>
159+
<justification>Not a breakage, method was moved to legacy</justification>
160+
<criticality>allowed</criticality>
161+
</item>
162+
</differences>
163+
</revapi.differences>
152164

153165
</analysisConfiguration>
154166
</configuration>

xwiki-platform-core/xwiki-platform-bridge/src/main/java/org/xwiki/bridge/DocumentAccessBridge.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,15 +760,6 @@ default String getDocumentURL(EntityReference entityReference, String action, St
760760
@Deprecated
761761
boolean isDocumentEditable(DocumentReference documentReference);
762762

763-
/**
764-
* @return true if the current document's author has programming rights.
765-
* @deprecated since 6.1RC1, use
766-
* {@link org.xwiki.security.authorization.ContextualAuthorizationManager#hasAccess(org.xwiki.security.authorization.Right)}
767-
* instead
768-
*/
769-
@Deprecated
770-
boolean hasProgrammingRights();
771-
772763
/**
773764
* Utility method to retrieve the current user.
774765
*

xwiki-platform-core/xwiki-platform-component/xwiki-platform-component-script/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</dependency>
4848
<dependency>
4949
<groupId>org.xwiki.platform</groupId>
50-
<artifactId>xwiki-platform-bridge</artifactId>
50+
<artifactId>xwiki-platform-security-authorization-api</artifactId>
5151
<version>${project.version}</version>
5252
</dependency>
5353

xwiki-platform-core/xwiki-platform-component/xwiki-platform-component-script/src/main/java/org/xwiki/component/script/ComponentScriptService.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
import javax.inject.Provider;
2727
import javax.inject.Singleton;
2828

29-
import org.xwiki.bridge.DocumentAccessBridge;
3029
import org.xwiki.component.annotation.Component;
3130
import org.xwiki.component.internal.multi.ComponentManagerManager;
3231
import org.xwiki.component.manager.ComponentLookupException;
3332
import org.xwiki.component.manager.ComponentManager;
3433
import org.xwiki.context.Execution;
3534
import org.xwiki.script.service.ScriptService;
35+
import org.xwiki.security.authorization.ContextualAuthorizationManager;
36+
37+
import static org.xwiki.security.authorization.Right.PROGRAM;
3638

3739
/**
3840
* Provides Component-specific Scripting APIs.
@@ -69,29 +71,27 @@ public class ComponentScriptService implements ScriptService
6971
@Inject
7072
private ComponentManagerManager componentManagerManager;
7173

72-
/**
73-
* Used to check for Programming Rights.
74-
*/
75-
@Inject
76-
private DocumentAccessBridge bridge;
77-
7874
/**
7975
* Provides access to the current context.
8076
*/
8177
@Inject
8278
private Execution execution;
8379

80+
@Inject
81+
private ContextualAuthorizationManager contextualAuthorizationManager;
82+
8483
/**
8584
* A Component Manager which read in contextual Component Manager and write in root component manager.
86-
*
85+
*
8786
* @return the Component Manager if the document has Programming Rights or null otherwise
8887
* @deprecated since 6.4.1, 6.2.6, use {@link #getContextComponentManager()} or
8988
* {@link #getContextComponentManager()} instead
9089
*/
9190
@Deprecated
9291
public ComponentManager getComponentManager()
9392
{
94-
return this.bridge.hasProgrammingRights() ? this.contextrootComponentManagerProvider.get() : null;
93+
return this.contextualAuthorizationManager.hasAccess(PROGRAM) ? this.contextrootComponentManagerProvider.get()
94+
: null;
9595
}
9696

9797
/**
@@ -101,7 +101,8 @@ public ComponentManager getComponentManager()
101101
*/
102102
public ComponentManager getContextComponentManager()
103103
{
104-
return this.bridge.hasProgrammingRights() ? this.contextComponentManagerProvider.get() : null;
104+
return this.contextualAuthorizationManager.hasAccess(PROGRAM) ? this.contextComponentManagerProvider.get()
105+
: null;
105106
}
106107

107108
/**
@@ -123,13 +124,14 @@ public ComponentManager getRootComponentManager()
123124
* specific document has access to the components registered specifically for that document or for any of its
124125
* namespace ancestors (space, wiki, root). The root (top level) component manager is returned if you pass
125126
* {@code null}.
126-
*
127+
*
127128
* @param namespace a namespace or {@code null} for the root {@link ComponentManager}
128129
* @return the component manager associated with the specified namespace, if any, {@code null otherwise}
129130
*/
130131
public ComponentManager getComponentManager(String namespace)
131132
{
132-
return this.bridge.hasProgrammingRights() ? this.componentManagerManager.getComponentManager(namespace, false)
133+
return this.contextualAuthorizationManager.hasAccess(PROGRAM)
134+
? this.componentManagerManager.getComponentManager(namespace, false)
133135
: null;
134136
}
135137

xwiki-platform-core/xwiki-platform-component/xwiki-platform-component-script/src/test/java/org/xwiki/component/script/ComponentScriptServiceTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
26-
import org.xwiki.bridge.DocumentAccessBridge;
2726
import org.xwiki.component.internal.multi.ComponentManagerManager;
2827
import org.xwiki.component.manager.ComponentLookupException;
2928
import org.xwiki.component.manager.ComponentManager;
3029
import org.xwiki.context.Execution;
3130
import org.xwiki.context.ExecutionContext;
31+
import org.xwiki.security.authorization.ContextualAuthorizationManager;
3232
import org.xwiki.test.junit5.mockito.ComponentTest;
3333
import org.xwiki.test.junit5.mockito.InjectMockComponents;
3434
import org.xwiki.test.junit5.mockito.MockComponent;
@@ -42,6 +42,7 @@
4242
import static org.mockito.Mockito.never;
4343
import static org.mockito.Mockito.verify;
4444
import static org.mockito.Mockito.when;
45+
import static org.xwiki.security.authorization.Right.PROGRAM;
4546

4647
/**
4748
* Unit tests for {@link ComponentScriptService}.
@@ -66,7 +67,7 @@ private interface SomeRole
6667
* Used to check programming rights.
6768
*/
6869
@MockComponent
69-
private DocumentAccessBridge documentAccessBridge;
70+
private ContextualAuthorizationManager contextualAuthorizationManager;
7071

7172
/**
7273
* The mock component manager used by the script service under test.
@@ -98,55 +99,55 @@ void setUp()
9899
@Test
99100
void getComponentManagerWhenNoProgrammingRights()
100101
{
101-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
102+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);
102103

103104
assertNull(this.componentScriptService.getComponentManager());
104105
}
105106

106107
@Test
107108
void getRootComponentManagerWhenNoProgrammingRights()
108109
{
109-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
110+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);
110111

111112
assertNull(this.componentScriptService.getRootComponentManager());
112113
}
113114

114115
@Test
115116
void getContextComponentManagerWhenNoProgrammingRights()
116117
{
117-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
118+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);
118119

119120
assertNull(this.componentScriptService.getContextComponentManager());
120121
}
121122

122123
@Test
123124
void getComponentManagerWhenProgrammingRights()
124125
{
125-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
126+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
126127

127128
assertSame(this.contextrootComponentManager, this.componentScriptService.getComponentManager());
128129
}
129130

130131
@Test
131132
void getRootComponentManagerWhenProgrammingRights()
132133
{
133-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
134+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
134135

135136
assertSame(this.rootComponentManager, this.componentScriptService.getRootComponentManager());
136137
}
137138

138139
@Test
139140
void getContextComponentManagerWhenProgrammingRights()
140141
{
141-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
142+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
142143

143144
assertSame(this.contextComponentManager, this.componentScriptService.getContextComponentManager());
144145
}
145146

146147
@Test
147148
void getComponentManagerForNamespaceWhenNoProgrammingRights()
148149
{
149-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
150+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);
150151

151152
assertNull(this.componentScriptService.getComponentManager("wiki:xwiki"));
152153

@@ -156,7 +157,7 @@ void getComponentManagerForNamespaceWhenNoProgrammingRights()
156157
@Test
157158
void getComponentManagerForNamespaceWhenProgrammingRights()
158159
{
159-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
160+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
160161

161162
ComponentManager wikiComponentManager = mock(ComponentManager.class);
162163
when(this.componentManagerManager.getComponentManager("wiki:chess", false)).thenReturn(wikiComponentManager);
@@ -167,7 +168,7 @@ void getComponentManagerForNamespaceWhenProgrammingRights()
167168
@Test
168169
void getComponentInstanceWithNoHintWhenNoProgrammingRights() throws Exception
169170
{
170-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
171+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);
171172

172173
assertNull(this.componentScriptService.getInstance(SomeRole.class));
173174

@@ -177,7 +178,7 @@ void getComponentInstanceWithNoHintWhenNoProgrammingRights() throws Exception
177178
@Test
178179
void getComponentInstanceWithNoHintWhenProgrammingRights() throws Exception
179180
{
180-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
181+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
181182

182183
SomeRole instance = mock(SomeRole.class);
183184
when(this.contextComponentManager.getInstance(SomeRole.class)).thenReturn(instance);
@@ -188,7 +189,7 @@ void getComponentInstanceWithNoHintWhenProgrammingRights() throws Exception
188189
@Test
189190
void getComponentInstanceWithHintWhenNoProgrammingRights() throws Exception
190191
{
191-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
192+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);
192193

193194
assertNull(this.componentScriptService.getInstance(SomeRole.class, "hint"));
194195

@@ -198,7 +199,7 @@ void getComponentInstanceWithHintWhenNoProgrammingRights() throws Exception
198199
@Test
199200
void getComponentInstanceWithHintWhenProgrammingRights() throws Exception
200201
{
201-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
202+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
202203

203204
SomeRole instance = mock(SomeRole.class);
204205
when(this.contextComponentManager.getInstance(SomeRole.class, "hint")).thenReturn(instance);
@@ -209,7 +210,7 @@ void getComponentInstanceWithHintWhenProgrammingRights() throws Exception
209210
@Test
210211
void getComponentInstanceWhenComponentDoesntExist() throws Exception
211212
{
212-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
213+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
213214
when(this.contextComponentManager.getInstance(SomeRole.class)).thenThrow(new ComponentLookupException("error"));
214215
ExecutionContext context = new ExecutionContext();
215216
when(this.execution.getContext()).thenReturn(context);
@@ -221,7 +222,7 @@ void getComponentInstanceWhenComponentDoesntExist() throws Exception
221222
@Test
222223
void getComponentInstanceWithHintWhenComponentDoesntExist() throws Exception
223224
{
224-
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
225+
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
225226
when(this.contextComponentManager.getInstance(SomeRole.class, "hint")).thenThrow(
226227
new ComponentLookupException("error"));
227228
ExecutionContext context = new ExecutionContext();

xwiki-platform-core/xwiki-platform-legacy/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<modules>
4141
<!-- Sorted Alphabetically -->
4242
<module>xwiki-platform-legacy-annotation</module>
43+
<module>xwiki-platform-legacy-bridge</module>
4344
<module>xwiki-platform-legacy-events-hibernate</module>
4445
<module>xwiki-platform-legacy-extension-handler-xar</module>
4546
<module>xwiki-platform-legacy-instance</module>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
-->
22+
23+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
<parent>
27+
<groupId>org.xwiki.platform</groupId>
28+
<artifactId>xwiki-platform-legacy</artifactId>
29+
<version>17.10.0-SNAPSHOT</version>
30+
</parent>
31+
<artifactId>xwiki-platform-legacy-bridge</artifactId>
32+
<name>XWiki Platform - Legacy - Bridge</name>
33+
<packaging>jar</packaging>
34+
<description>Legacy module for xwiki-platform-bridge</description>
35+
<properties>
36+
<xwiki.jacoco.instructionRatio>0.00</xwiki.jacoco.instructionRatio>
37+
<!-- The features provided by this module so that it's found when resolving extension -->
38+
<xwiki.extension.features>org.xwiki.platform:xwiki-platform-bridge</xwiki.extension.features>
39+
</properties>
40+
<dependencies>
41+
<!-- Trigger xwiki-platform-bridge dependencies (but without xwiki-platform-bridge jar itself) -->
42+
<dependency>
43+
<groupId>org.xwiki.platform</groupId>
44+
<artifactId>xwiki-platform-bridge</artifactId>
45+
<version>${project.version}</version>
46+
<type>pom</type>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.xwiki.platform</groupId>
50+
<artifactId>xwiki-platform-bridge</artifactId>
51+
<version>${project.version}</version>
52+
<!-- We don't want to draw this dependency since we're wrapping it. -->
53+
<scope>provided</scope>
54+
</dependency>
55+
<!-- Needed for backward compatibility Aspects -->
56+
<dependency>
57+
<groupId>org.aspectj</groupId>
58+
<artifactId>aspectjrt</artifactId>
59+
</dependency>
60+
</dependencies>
61+
<build>
62+
<plugins>
63+
<!-- Apply Backward compatibility Aspects using the strategy described at
64+
http://blogs.sonatype.com/john/2007/11/09/1194630418546.html -->
65+
<plugin>
66+
<groupId>org.codehaus.mojo</groupId>
67+
<artifactId>aspectj-maven-plugin</artifactId>
68+
<executions>
69+
<execution>
70+
<id>backward-compatibility-aspects</id>
71+
<goals>
72+
<goal>compile</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
<configuration>
77+
<weaveDependencies>
78+
<weaveDependency>
79+
<groupId>org.xwiki.platform</groupId>
80+
<artifactId>xwiki-platform-bridge</artifactId>
81+
</weaveDependency>
82+
</weaveDependencies>
83+
</configuration>
84+
</plugin>
85+
<!-- Exclude AspectJ's builddef.lst file form the generated JAR since it's not useful there. -->
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-jar-plugin</artifactId>
89+
<configuration>
90+
<excludes>
91+
<exclude>**/builddef.lst</exclude>
92+
</excludes>
93+
</configuration>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
</project>

0 commit comments

Comments
 (0)