Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions xwiki-platform-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@
</differences>
</revapi.differences>
-->

<revapi.differences>
<differences>
<item>
<ignore>true</ignore>
<code>java.method.removed</code>
<old>method boolean org.xwiki.bridge.DocumentAccessBridge::hasProgrammingRights()</old>
<justification>Not a breakage, method was moved to legacy</justification>
<criticality>allowed</criticality>
</item>
</differences>
</revapi.differences>

</analysisConfiguration>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,15 +760,6 @@ default String getDocumentURL(EntityReference entityReference, String action, St
@Deprecated
boolean isDocumentEditable(DocumentReference documentReference);

/**
* @return true if the current document's author has programming rights.
* @deprecated since 6.1RC1, use
* {@link org.xwiki.security.authorization.ContextualAuthorizationManager#hasAccess(org.xwiki.security.authorization.Right)}
* instead
*/
@Deprecated
boolean hasProgrammingRights();

/**
* Utility method to retrieve the current user.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-bridge</artifactId>
<artifactId>xwiki-platform-security-authorization-api</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import javax.inject.Provider;
import javax.inject.Singleton;

import org.xwiki.bridge.DocumentAccessBridge;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.internal.multi.ComponentManagerManager;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.context.Execution;
import org.xwiki.script.service.ScriptService;
import org.xwiki.security.authorization.ContextualAuthorizationManager;

import static org.xwiki.security.authorization.Right.PROGRAM;

/**
* Provides Component-specific Scripting APIs.
Expand Down Expand Up @@ -69,29 +71,27 @@ public class ComponentScriptService implements ScriptService
@Inject
private ComponentManagerManager componentManagerManager;

/**
* Used to check for Programming Rights.
*/
@Inject
private DocumentAccessBridge bridge;

/**
* Provides access to the current context.
*/
@Inject
private Execution execution;

@Inject
private ContextualAuthorizationManager contextualAuthorizationManager;

/**
* A Component Manager which read in contextual Component Manager and write in root component manager.
*
*
* @return the Component Manager if the document has Programming Rights or null otherwise
* @deprecated since 6.4.1, 6.2.6, use {@link #getContextComponentManager()} or
* {@link #getContextComponentManager()} instead
*/
@Deprecated
public ComponentManager getComponentManager()
{
return this.bridge.hasProgrammingRights() ? this.contextrootComponentManagerProvider.get() : null;
return this.contextualAuthorizationManager.hasAccess(PROGRAM) ? this.contextrootComponentManagerProvider.get()
: null;
}

/**
Expand All @@ -101,7 +101,8 @@ public ComponentManager getComponentManager()
*/
public ComponentManager getContextComponentManager()
{
return this.bridge.hasProgrammingRights() ? this.contextComponentManagerProvider.get() : null;
return this.contextualAuthorizationManager.hasAccess(PROGRAM) ? this.contextComponentManagerProvider.get()
: null;
}

/**
Expand All @@ -123,13 +124,14 @@ public ComponentManager getRootComponentManager()
* specific document has access to the components registered specifically for that document or for any of its
* namespace ancestors (space, wiki, root). The root (top level) component manager is returned if you pass
* {@code null}.
*
*
* @param namespace a namespace or {@code null} for the root {@link ComponentManager}
* @return the component manager associated with the specified namespace, if any, {@code null otherwise}
*/
public ComponentManager getComponentManager(String namespace)
{
return this.bridge.hasProgrammingRights() ? this.componentManagerManager.getComponentManager(namespace, false)
return this.contextualAuthorizationManager.hasAccess(PROGRAM)
? this.componentManagerManager.getComponentManager(namespace, false)
: null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xwiki.bridge.DocumentAccessBridge;
import org.xwiki.component.internal.multi.ComponentManagerManager;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
import org.xwiki.security.authorization.ContextualAuthorizationManager;
import org.xwiki.test.junit5.mockito.ComponentTest;
import org.xwiki.test.junit5.mockito.InjectMockComponents;
import org.xwiki.test.junit5.mockito.MockComponent;
Expand All @@ -42,6 +42,7 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.xwiki.security.authorization.Right.PROGRAM;

/**
* Unit tests for {@link ComponentScriptService}.
Expand All @@ -66,7 +67,7 @@ private interface SomeRole
* Used to check programming rights.
*/
@MockComponent
private DocumentAccessBridge documentAccessBridge;
private ContextualAuthorizationManager contextualAuthorizationManager;

/**
* The mock component manager used by the script service under test.
Expand Down Expand Up @@ -98,55 +99,55 @@ void setUp()
@Test
void getComponentManagerWhenNoProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);

assertNull(this.componentScriptService.getComponentManager());
}

@Test
void getRootComponentManagerWhenNoProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);

assertNull(this.componentScriptService.getRootComponentManager());
}

@Test
void getContextComponentManagerWhenNoProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);

assertNull(this.componentScriptService.getContextComponentManager());
}

@Test
void getComponentManagerWhenProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);

assertSame(this.contextrootComponentManager, this.componentScriptService.getComponentManager());
}

@Test
void getRootComponentManagerWhenProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);

assertSame(this.rootComponentManager, this.componentScriptService.getRootComponentManager());
}

@Test
void getContextComponentManagerWhenProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);

assertSame(this.contextComponentManager, this.componentScriptService.getContextComponentManager());
}

@Test
void getComponentManagerForNamespaceWhenNoProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);

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

Expand All @@ -156,7 +157,7 @@ void getComponentManagerForNamespaceWhenNoProgrammingRights()
@Test
void getComponentManagerForNamespaceWhenProgrammingRights()
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);

ComponentManager wikiComponentManager = mock(ComponentManager.class);
when(this.componentManagerManager.getComponentManager("wiki:chess", false)).thenReturn(wikiComponentManager);
Expand All @@ -167,7 +168,7 @@ void getComponentManagerForNamespaceWhenProgrammingRights()
@Test
void getComponentInstanceWithNoHintWhenNoProgrammingRights() throws Exception
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);

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

Expand All @@ -177,7 +178,7 @@ void getComponentInstanceWithNoHintWhenNoProgrammingRights() throws Exception
@Test
void getComponentInstanceWithNoHintWhenProgrammingRights() throws Exception
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);

SomeRole instance = mock(SomeRole.class);
when(this.contextComponentManager.getInstance(SomeRole.class)).thenReturn(instance);
Expand All @@ -188,7 +189,7 @@ void getComponentInstanceWithNoHintWhenProgrammingRights() throws Exception
@Test
void getComponentInstanceWithHintWhenNoProgrammingRights() throws Exception
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(false);

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

Expand All @@ -198,7 +199,7 @@ void getComponentInstanceWithHintWhenNoProgrammingRights() throws Exception
@Test
void getComponentInstanceWithHintWhenProgrammingRights() throws Exception
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);

SomeRole instance = mock(SomeRole.class);
when(this.contextComponentManager.getInstance(SomeRole.class, "hint")).thenReturn(instance);
Expand All @@ -209,7 +210,7 @@ void getComponentInstanceWithHintWhenProgrammingRights() throws Exception
@Test
void getComponentInstanceWhenComponentDoesntExist() throws Exception
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
when(this.contextComponentManager.getInstance(SomeRole.class)).thenThrow(new ComponentLookupException("error"));
ExecutionContext context = new ExecutionContext();
when(this.execution.getContext()).thenReturn(context);
Expand All @@ -221,7 +222,7 @@ void getComponentInstanceWhenComponentDoesntExist() throws Exception
@Test
void getComponentInstanceWithHintWhenComponentDoesntExist() throws Exception
{
when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true);
when(this.contextualAuthorizationManager.hasAccess(PROGRAM)).thenReturn(true);
when(this.contextComponentManager.getInstance(SomeRole.class, "hint")).thenThrow(
new ComponentLookupException("error"));
ExecutionContext context = new ExecutionContext();
Expand Down
1 change: 1 addition & 0 deletions xwiki-platform-core/xwiki-platform-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<modules>
<!-- Sorted Alphabetically -->
<module>xwiki-platform-legacy-annotation</module>
<module>xwiki-platform-legacy-bridge</module>
<module>xwiki-platform-legacy-events-hibernate</module>
<module>xwiki-platform-legacy-extension-handler-xar</module>
<module>xwiki-platform-legacy-instance</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-legacy</artifactId>
<version>17.10.0-SNAPSHOT</version>
</parent>
<artifactId>xwiki-platform-legacy-bridge</artifactId>
<name>XWiki Platform - Legacy - Bridge</name>
<packaging>jar</packaging>
<description>Legacy module for xwiki-platform-bridge</description>
<properties>
<xwiki.jacoco.instructionRatio>0.00</xwiki.jacoco.instructionRatio>
<!-- The features provided by this module so that it's found when resolving extension -->
<xwiki.extension.features>org.xwiki.platform:xwiki-platform-bridge</xwiki.extension.features>
</properties>
<dependencies>
<!-- Trigger xwiki-platform-bridge dependencies (but without xwiki-platform-bridge jar itself) -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-bridge</artifactId>
<version>${project.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-bridge</artifactId>
<version>${project.version}</version>
<!-- We don't want to draw this dependency since we're wrapping it. -->
<scope>provided</scope>
</dependency>
<!-- Needed for backward compatibility Aspects -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Apply Backward compatibility Aspects using the strategy described at
http://blogs.sonatype.com/john/2007/11/09/1194630418546.html -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>backward-compatibility-aspects</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<weaveDependencies>
<weaveDependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-bridge</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>
<!-- Exclude AspectJ's builddef.lst file form the generated JAR since it's not useful there. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/builddef.lst</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading
Loading