Search in sources :

Example 96 with EntityReference

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

the class TestGroupUserFactory method getNewInstance.

@Override
TestGroup getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes) throws SAXException {
    EntityReference reference = parser.getResolver().resolve(attributes.getValue("name"), parent.getType(), parent.getReference());
    TestEntity entity = parser.getWikis().searchEntity(reference);
    if (entity == null) {
        throw new SAXException(parser.getLocatedMessage("User/Group [%s] is undefined.", reference));
    }
    new DefaultTestGroup(parser.getSerializer().serialize(parent.getReference()), parent.getReference(), entity);
    return null;
}
Also used : TestEntity(org.xwiki.security.authorization.testwikis.TestEntity) DefaultTestGroup(org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestGroup) EntityReference(org.xwiki.model.reference.EntityReference) SAXException(org.xml.sax.SAXException)

Example 97 with EntityReference

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

the class TestSpaceFactory method getNewInstance.

@Override
TestSpace getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes) {
    EntityReference reference = parser.getResolver().resolve(attributes.getValue("name"), DefaultTestSpace.TYPE, parent.getReference());
    TestSpace space = (TestSpace) parent.getEntity(reference);
    if (space == null) {
        space = new DefaultTestSpace(reference, attributes.getValue("alt"), parent);
    }
    return space;
}
Also used : DefaultTestSpace(org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestSpace) EntityReference(org.xwiki.model.reference.EntityReference) TestSpace(org.xwiki.security.authorization.testwikis.TestSpace) DefaultTestSpace(org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestSpace)

Example 98 with EntityReference

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

the class SheetDocumentDisplayer method display.

@Override
public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) {
    XDOM xdom = null;
    if (isSheetExpected(document, parameters)) {
        Map<String, Object> backupObjects = null;
        EntityReference currentWikiReference = null;
        try {
            // it's not already there.
            if (!modelBridge.isCurrentDocument(document)) {
                backupObjects = modelBridge.pushDocumentInContext(document);
                currentWikiReference = modelContext.getCurrentEntityReference();
                modelContext.setCurrentEntityReference(document.getDocumentReference().getWikiReference());
            }
            xdom = maybeDisplayWithSheet(document, parameters);
        } finally {
            if (backupObjects != null) {
                documentAccessBridge.popDocumentFromContext(backupObjects);
                modelContext.setCurrentEntityReference(currentWikiReference);
            }
        }
    }
    // isolating the execution context is needed due to the way #isSheetExpected() checks for current document.
    return xdom != null ? xdom : documentDisplayer.display(document, parameters);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) EntityReference(org.xwiki.model.reference.EntityReference)

Example 99 with EntityReference

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

the class TestAccessRuleFactory method getNewInstance.

@Override
TestAccessRule getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes) {
    EntityReference userRef = parser.getResolver().resolve(attributes.getValue("name"), DefaultTestDocument.TYPE, new EntityReference(XWikiConstants.XWIKI_SPACE, EntityType.SPACE, parent.getReference().getRoot()));
    Boolean allow = name.startsWith("allow");
    String type = attributes.getValue("type");
    String user = parser.getSerializer().serialize(userRef);
    Boolean isUser = name.endsWith("User");
    if (type != null) {
        Right right = Right.toRight(type);
        new DefaultTestAccessRule(user, userRef, right, allow, isUser, parent);
    } else {
        EntityType parentType = parent.getType();
        if (parentType == EntityType.WIKI && ((TestWiki) parent).isMainWiki()) {
            // Null here means root (or farm)
            parentType = null;
        }
        for (Right right : Right.getEnabledRights(parentType)) {
            if (right != Right.CREATOR) {
                new DefaultTestAccessRule(user, userRef, right, allow, isUser, parent);
            }
        }
    }
    return null;
}
Also used : EntityType(org.xwiki.model.EntityType) DefaultTestAccessRule(org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestAccessRule) EntityReference(org.xwiki.model.reference.EntityReference) Right(org.xwiki.security.authorization.Right)

Example 100 with EntityReference

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

the class StandardExtendedURLResourceTypeResolver method registerEntityResourceReferenceResolver.

private void registerEntityResourceReferenceResolver(String registrationHint, Class<? extends ResourceReferenceResolver<ExtendedURL>> registrationImplementation, String wikiExtractorHint) throws InitializationException {
    DefaultComponentDescriptor<ResourceReferenceResolver<ExtendedURL>> resolverDescriptor = new DefaultComponentDescriptor<>();
    resolverDescriptor.setImplementation(registrationImplementation);
    resolverDescriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON);
    String hint = computeHint(registrationHint);
    resolverDescriptor.setRoleHint(hint);
    resolverDescriptor.setRoleType(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class));
    // Register dependencies
    DefaultComponentDependency<WikiReferenceExtractor> wikiReferenceExtractorDependency = new DefaultComponentDependency<>();
    wikiReferenceExtractorDependency.setRoleType(WikiReferenceExtractor.class);
    wikiReferenceExtractorDependency.setRoleHint(wikiExtractorHint);
    wikiReferenceExtractorDependency.setName("wikiExtractor");
    resolverDescriptor.addComponentDependency(wikiReferenceExtractorDependency);
    DefaultComponentDependency<EntityReferenceResolver<EntityReference>> entityReferenceResolverDependency = new DefaultComponentDependency<>();
    entityReferenceResolverDependency.setRoleType(new DefaultParameterizedType(null, EntityReferenceResolver.class, EntityReference.class));
    entityReferenceResolverDependency.setName("defaultReferenceEntityReferenceResolver");
    resolverDescriptor.addComponentDependency(entityReferenceResolverDependency);
    DefaultComponentDependency<StandardURLConfiguration> standardURLConfigurationDependency = new DefaultComponentDependency<>();
    standardURLConfigurationDependency.setRoleType(StandardURLConfiguration.class);
    standardURLConfigurationDependency.setName("configuration");
    resolverDescriptor.addComponentDependency(standardURLConfigurationDependency);
    DefaultComponentDependency<EntityResourceActionLister> entityResourceActionListerDependency = new DefaultComponentDependency<>();
    entityResourceActionListerDependency.setRoleType(EntityResourceActionLister.class);
    entityResourceActionListerDependency.setName("entityResourceActionLister");
    resolverDescriptor.addComponentDependency(entityResourceActionListerDependency);
    try {
        this.rootComponentManager.registerComponent(resolverDescriptor);
    } catch (ComponentRepositoryException e) {
        throw new InitializationException(String.format("Failed to dynamically register Resource Reference Resolver for hint [%s]", hint), e);
    }
}
Also used : DefaultComponentDependency(org.xwiki.component.descriptor.DefaultComponentDependency) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) BinEntityResourceReferenceResolver(org.xwiki.url.internal.standard.entity.BinEntityResourceReferenceResolver) ResourceReferenceResolver(org.xwiki.resource.ResourceReferenceResolver) WikiEntityResourceReferenceResolver(org.xwiki.url.internal.standard.entity.WikiEntityResourceReferenceResolver) ComponentRepositoryException(org.xwiki.component.manager.ComponentRepositoryException) ExtendedURL(org.xwiki.url.ExtendedURL) InitializationException(org.xwiki.component.phase.InitializationException) EntityResourceActionLister(org.xwiki.resource.internal.entity.EntityResourceActionLister) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) EntityReference(org.xwiki.model.reference.EntityReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Aggregations

EntityReference (org.xwiki.model.reference.EntityReference)338 Test (org.junit.Test)157 DocumentReference (org.xwiki.model.reference.DocumentReference)107 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)39 BaseObject (com.xpn.xwiki.objects.BaseObject)38 ArrayList (java.util.ArrayList)27 XWikiContext (com.xpn.xwiki.XWikiContext)24 WikiReference (org.xwiki.model.reference.WikiReference)24 SpaceReference (org.xwiki.model.reference.SpaceReference)23 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)18 XWikiException (com.xpn.xwiki.XWikiException)17 EntityType (org.xwiki.model.EntityType)11 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)10 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 XDOM (org.xwiki.rendering.block.XDOM)8 URL (java.net.URL)7 AttachmentReference (org.xwiki.model.reference.AttachmentReference)7 HashMap (java.util.HashMap)6 Before (org.junit.Before)6