Search in sources :

Example 86 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class SolrIndexScriptServiceTest method indexMultipleReferencesChecksRights.

@Test
public void indexMultipleReferencesChecksRights() throws Exception {
    EntityReference wikiReference = new WikiReference("someWiki");
    // Call
    // Note: Faking it. just using one reference but still calling the multiple references method (which is what we
    // wanted anyway)
    this.service.index(Arrays.asList(wikiReference));
    // Assert and verify
    // Actual rights check
    verify(this.mockAuthorization).hasAccess(Right.ADMIN, this.userReference, wikiReference);
    verify(this.mockAuthorization).hasAccess(Right.PROGRAM, this.contentAuthorReference, wikiReference);
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 87 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultSecurityCacheLoaderTest method setUp.

@Before
public void setUp() throws Exception {
    XWikiBridge bridge = mocker.registerMockComponent(XWikiBridge.class);
    when(bridge.getMainWikiReference()).thenReturn(new WikiReference("wiki"));
    securityReferenceFactory = mocker.getInstance(SecurityReferenceFactory.class);
    mocker.registerMockComponent(SecurityCache.class);
    mocker.registerMockComponent(SecurityCacheRulesInvalidator.class);
    mocker.registerMockComponent(SecurityEntryReader.class);
    mocker.registerMockComponent(UserBridge.class);
    mocker.registerMockComponent(AuthorizationSettler.class);
    securityCacheLoader = mocker.getInstance(SecurityCacheLoader.class);
}
Also used : DefaultSecurityReferenceFactory(org.xwiki.security.DefaultSecurityReferenceFactory) SecurityReferenceFactory(org.xwiki.security.SecurityReferenceFactory) XWikiBridge(org.xwiki.security.internal.XWikiBridge) WikiReference(org.xwiki.model.reference.WikiReference) SecurityCacheLoader(org.xwiki.security.authorization.cache.SecurityCacheLoader) Before(org.junit.Before)

Example 88 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultSecurityCacheTest method configure.

@Before
public void configure() throws Exception {
    if (cache == null) {
        cache = new TestCache<Object>();
        final CacheManager cacheManager = securityCacheMocker.getInstance(CacheManager.class);
        when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
    }
    XWikiBridge xwikiBridge = securityReferenceFactoryMocker.getInstance(XWikiBridge.class);
    when(xwikiBridge.getMainWikiReference()).thenReturn(new WikiReference("xwiki"));
    this.factory = securityReferenceFactoryMocker.getComponentUnderTest();
    this.securityCache = securityCacheMocker.getComponentUnderTest();
    aMissingParentRef = factory.newEntityReference(new SpaceReference("space", new WikiReference("missing")));
    aMissingEntityRef = factory.newEntityReference(new DocumentReference("missingPage", xspaceRef.getOriginalSpaceReference()));
    aMissingUserRef = factory.newUserReference(new DocumentReference("missingUser", xXWikiSpace.getOriginalSpaceReference()));
    aMissingGroupRef = factory.newGroupReference(new DocumentReference("missingGroup", xXWikiSpace.getOriginalSpaceReference()));
    aMissingWikiRef = factory.newEntityReference(new WikiReference("missingWiki"));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) CacheManager(org.xwiki.cache.CacheManager) XWikiBridge(org.xwiki.security.internal.XWikiBridge) WikiReference(org.xwiki.model.reference.WikiReference) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 89 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultSecurityCacheTest method AddAccessEntry.

private String AddAccessEntry(final SecurityAccessEntry entry) throws ParentEntryEvictedException, ConflictingInsertionException {
    WikiReference entityWiki = (WikiReference) entry.getReference().getOriginalReference().extractReference(EntityType.WIKI);
    WikiReference userWiki = entry.getUserReference().getOriginalReference().getWikiReference();
    if (entityWiki != userWiki) {
        if (entry.getUserReference().isGlobal()) {
            securityCache.add(entry, factory.newEntityReference(entityWiki));
            return cache.getLastInsertedKey();
        } else {
            return null;
        }
    } else {
        securityCache.add(entry);
        return cache.getLastInsertedKey();
    }
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference)

Example 90 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class SolrFieldStringEntityReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    EntityReferenceProvider currentEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class, "current");
    when(currentEntityReferenceProvider.getDefaultReference(EntityType.WIKI)).thenReturn(new WikiReference("test"));
    EntityReferenceResolver<String> resolver = mocker.getComponentUnderTest();
    DocumentReference documentReference = new DocumentReference("test", Arrays.asList("My App", "Code", "Model"), "A Class");
    assertEquals(new ClassPropertyReference("title", documentReference), new ClassPropertyReference(resolver.resolve("My App.Code.Model.A Class.title", EntityType.CLASS_PROPERTY)));
    documentReference = new DocumentReference("test", Arrays.asList("My.App", "Co.de"), "A.Class");
    assertEquals(new ClassPropertyReference("ti.tle", documentReference), new ClassPropertyReference(resolver.resolve("My..App.Co..de.A..Class.ti..tle", EntityType.CLASS_PROPERTY)));
    assertEquals(new SpaceReference("0.9", new SpaceReference("a..z", new WikiReference("test"))), new SpaceReference(resolver.resolve("a....z.0..9", EntityType.SPACE)));
    // Relative reference resolved based on the given parameters.
    assertEquals(new ClassPropertyReference("title", new DocumentReference("foo", Arrays.asList("Code", "Model"), "A Class")), new ClassPropertyReference(resolver.resolve("Code.Model.A Class.title", EntityType.CLASS_PROPERTY, new SpaceReference("My App", new WikiReference("foo")))));
    // Relative reference resolve based on the current entity.
    when(currentEntityReferenceProvider.getDefaultReference(EntityType.SPACE)).thenReturn(new EntityReference("Code", EntityType.SPACE, new EntityReference("My App", EntityType.SPACE, null)));
    assertEquals(new ClassPropertyReference("title", new DocumentReference("bar", Arrays.asList("My App", "Code"), "A Class")), new ClassPropertyReference(resolver.resolve("A Class.title", EntityType.CLASS_PROPERTY, new WikiReference("bar"))));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8