Search in sources :

Example 91 with EntityReference

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

the class AuthorizationManagerTest method testRightOnTopLevel.

@Test
public void testRightOnTopLevel() throws Exception {
    LegacyTestWiki testWiki = new LegacyTestWiki(getMockery(), getComponentManager(), "empty.xml", false);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    DocumentReference user = new DocumentReference("wiki", "XWiki", "user");
    EntityReference document = null;
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.LOGIN, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.VIEW, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.EDIT, user, document, ctx);
    assertAccessFalse("User from global wiki should have the same rights on empty subwiki", Right.DELETE, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.REGISTER, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.COMMENT, user, document, ctx);
    assertAccessFalse("User from global wiki should have the same rights on empty subwiki", Right.PROGRAM, user, document, ctx);
    assertAccessFalse("User from global wiki should have the same rights on empty subwiki", Right.ADMIN, user, document, ctx);
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) EntityReference(org.xwiki.model.reference.EntityReference) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 92 with EntityReference

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

the class AuthorizationManagerTest method testPublicAccess.

@Test
public void testPublicAccess() throws Exception {
    LegacyTestWiki testWiki = new LegacyTestWiki(getMockery(), getComponentManager(), "empty.xml", false);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    DocumentReference user = null;
    EntityReference document = new DocumentReference("wiki", "Space", "Page");
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.LOGIN, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.VIEW, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.EDIT, user, document, ctx);
    assertAccessFalse("User from global wiki should have the same rights on empty subwiki", Right.DELETE, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.REGISTER, user, document, ctx);
    assertAccessTrue("User from global wiki should have the same rights on empty subwiki", Right.COMMENT, user, document, ctx);
    assertAccessFalse("User from global wiki should have the same rights on empty subwiki", Right.PROGRAM, user, document, ctx);
    assertAccessFalse("User from global wiki should have the same rights on empty subwiki", Right.ADMIN, user, document, ctx);
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) EntityReference(org.xwiki.model.reference.EntityReference) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 93 with EntityReference

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

the class DefaultContextualAuthorizationManager method checkAccess.

@Override
public void checkAccess(Right right) throws AccessDeniedException {
    if (CONTENT_AUTHOR_RIGHTS.contains(right)) {
        EntityReference entity;
        if (right == Right.PROGRAM) {
            // Defaults to the main wiki reference.
            entity = null;
        } else {
            entity = getCurrentEntity();
        }
        checkAccess(right, getCurrentUser(right, null), entity);
    } else {
        checkAccess(right, getCurrentEntity());
    }
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference)

Example 94 with EntityReference

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

the class TestDocumentFactory method getNewInstance.

@Override
TestDocument getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes) {
    EntityReference reference = parser.getResolver().resolve(attributes.getValue("name"), DefaultTestDocument.TYPE, parent.getReference());
    String creatorString = attributes.getValue("creator");
    EntityReference creator = (creatorString) != null ? parser.getResolver().resolve(creatorString, DefaultTestDocument.TYPE, new EntityReference(XWikiConstants.XWIKI_SPACE, EntityType.SPACE, reference.getRoot())) : null;
    return new DefaultTestDocument(reference, creator, attributes.getValue("alt"), parent);
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) DefaultTestDocument(org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestDocument)

Example 95 with EntityReference

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

the class TestGroupFactory method getNewInstance.

@Override
TestDocument getNewInstance(ElementParser parser, String name, TestEntity parent, Attributes attributes) {
    EntityReference reference = parser.getResolver().resolve(attributes.getValue("name"), DefaultTestDocument.TYPE, parent.getReference());
    EntityReference creator = parser.getResolver().resolve(attributes.getValue("creator"), DefaultTestDocument.TYPE, new EntityReference(XWikiConstants.XWIKI_SPACE, EntityType.SPACE, reference.getRoot()));
    return new DefaultTestGroupDocument(reference, creator, attributes.getValue("alt"), parent);
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) DefaultTestGroupDocument(org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestGroupDocument)

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