Search in sources :

Example 1 with EntityType

use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.

the class AbstractExtensionValidator method checkAccess.

protected void checkAccess(Right entityRight, String namespaceString, Request request) throws AccessDeniedException {
    Namespace namespace = NamespaceUtils.toNamespace(namespaceString);
    // Root namespace
    if (namespace == null) {
        checkRootRight(entityRight, request);
        return;
    }
    if (namespace.getType() != null) {
        // User
        if (namespace.getType().equals("user")) {
            EntityReference reference = this.resolver.resolve(namespace.getValue(), EntityType.DOCUMENT);
            checkUserRight(reference, request);
            return;
        }
        // Entity
        EntityType entityType = EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase());
        if (entityType != null) {
            EntityReference reference = this.resolver.resolve(namespace.getValue(), entityType);
            checkAccess(reference, entityRight, request);
            return;
        }
    }
    // Unknown namespace
    checkNamespaceRight(namespace, Right.PROGRAM, request);
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference) Namespace(org.xwiki.component.namespace.Namespace)

Example 2 with EntityType

use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.

the class CompactStringEntityReferenceSerializer method serialize.

@Override
public String serialize(EntityReference reference, Object... parameters) {
    if (reference == null) {
        return null;
    }
    StringBuilder representation = new StringBuilder();
    List<EntityReference> references = reference.getReversedReferenceChain();
    for (int i = 0; i < references.size(); ) {
        EntityReference currentReference = references.get(i);
        EntityType currentType = currentReference.getType();
        // Move to last element of the same type
        while (++i < references.size() && references.get(i).getType() == currentType) {
            currentReference = references.get(i);
        }
        if (shouldSerialize(currentReference, representation, currentReference == reference, parameters)) {
            serializeEntityReferenceType(currentReference, representation, currentReference == reference);
        }
    }
    return representation.toString();
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference)

Example 3 with EntityType

use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.

the class AbstractEntityJob method visitDocumentNodes.

private void visitDocumentNodes(EntityReferenceTreeNode node, Visitor<DocumentReference> visitor) {
    if (node != null) {
        EntityReference nodeReference = node.getReference();
        EntityType nodeType = nodeReference != null ? nodeReference.getType() : null;
        if (nodeType == EntityType.SPACE || nodeType == EntityType.WIKI || nodeType == null) {
            // A node that corresponds to an entity that can contain documents.
            visitDocumentAncestor(node, visitor);
        } else if (nodeType == EntityType.DOCUMENT) {
            visitor.visit((DocumentReference) node.getReference());
        }
    }
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 4 with EntityType

use of org.xwiki.model.EntityType 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 5 with EntityType

use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.

the class AbstractEntityResourceReferenceResolver method buildEntityReference.

/**
 * Normalize the extracted space/page to resolve empty/null values and replace them with default values.
 *
 * @param wikiReference the wiki reference as extracted from the URL
 * @param spaceNames the space names as extracted from the URL (can be empty or null)
 * @param pageName the page name as extracted from the URL (can be empty or null)
 * @param attachmentName the attachment name as extracted from the URL (can be empty or null)
 * @return the absolute Entity Reference
 */
private EntityReference buildEntityReference(WikiReference wikiReference, List<String> spaceNames, String pageName, String attachmentName) {
    EntityReference reference = wikiReference;
    EntityType entityType = EntityType.DOCUMENT;
    if (spaceNames != null && !spaceNames.isEmpty()) {
        EntityReference parent = reference;
        for (String spaceName : spaceNames) {
            if (!StringUtils.isEmpty(spaceName)) {
                reference = new EntityReference(spaceName, EntityType.SPACE, parent);
                parent = reference;
            }
        }
    }
    if (!StringUtils.isEmpty(pageName)) {
        reference = new EntityReference(pageName, EntityType.DOCUMENT, reference);
    }
    if (!StringUtils.isEmpty(attachmentName)) {
        reference = new EntityReference(attachmentName, EntityType.ATTACHMENT, reference);
        entityType = EntityType.ATTACHMENT;
    }
    return this.defaultReferenceEntityReferenceResolver.resolve(reference, entityType);
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference)

Aggregations

EntityType (org.xwiki.model.EntityType)16 EntityReference (org.xwiki.model.reference.EntityReference)11 Namespace (org.xwiki.component.namespace.Namespace)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SolrDocument (org.apache.solr.common.SolrDocument)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 InvalidEntityReferenceException (org.xwiki.model.reference.InvalidEntityReferenceException)1 CreateResourceReferenceException (org.xwiki.resource.CreateResourceReferenceException)1 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)1 SolrIndexerException (org.xwiki.search.solr.internal.api.SolrIndexerException)1 Right (org.xwiki.security.authorization.Right)1 DefaultTestAccessRule (org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestAccessRule)1