Search in sources :

Example 11 with AuthorizationManager

use of org.xwiki.security.authorization.AuthorizationManager in project xwiki-platform by xwiki.

the class CascadingVfsPermissionCheckerTest method checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed.

@Test
public void checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("customscheme:whatever"), "whatever");
    AuthorizationManager authorizationManager = this.mocker.registerMockComponent(AuthorizationManager.class);
    when(authorizationManager.hasAccess(Right.PROGRAM, this.contextUser, null)).thenReturn(false);
    try {
        this.mocker.getComponentUnderTest().checkPermission(reference);
        fail("Should have raised exception");
    } catch (VfsException expected) {
        assertEquals("Current logged-in user ([" + this.contextUser + "]) needs to have Programming Rights to use the [customscheme] VFS", expected.getMessage());
    }
}
Also used : VfsException(org.xwiki.vfs.VfsException) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Test(org.junit.Test)

Example 12 with AuthorizationManager

use of org.xwiki.security.authorization.AuthorizationManager in project xwiki-platform by xwiki.

the class CascadingVfsPermissionCheckerTest method checkPermissionWhenNoSpecificSchemeCheckerAndAllowed.

@Test
public void checkPermissionWhenNoSpecificSchemeCheckerAndAllowed() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("customscheme:whatever"), "whatever");
    AuthorizationManager authorizationManager = this.mocker.registerMockComponent(AuthorizationManager.class);
    when(authorizationManager.hasAccess(Right.PROGRAM, this.contextUser, null)).thenReturn(true);
    this.mocker.getComponentUnderTest().checkPermission(reference);
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Test(org.junit.Test)

Example 13 with AuthorizationManager

use of org.xwiki.security.authorization.AuthorizationManager in project xwiki-platform by xwiki.

the class CurrentColorThemeGetterTest method setUp.

@Before
public void setUp() throws Exception {
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, String.class));
    entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
    request = mock(XWikiRequest.class);
    when(xcontext.getRequest()).thenReturn(request);
    DocumentReference colorThemeReference = new DocumentReference("wikiId", "XWiki", "MyColorTheme");
    WikiReference mainWikiReference = new WikiReference("wikiId");
    when(documentReferenceResolver.resolve(eq("myColorTheme"), eq(mainWikiReference))).thenReturn(colorThemeReference);
    when(entityReferenceSerializer.serialize(colorThemeReference)).thenReturn("wikiId:ColorTheme.MyColorTheme");
    when(xwiki.exists(colorThemeReference, xcontext)).thenReturn(true);
    DocumentReference currentUser = new DocumentReference("xwiki", "XWiki", "CurrentUser");
    when(xcontext.getUserReference()).thenReturn(currentUser);
    when(authorizationManager.hasAccess(eq(Right.VIEW), any(DocumentReference.class), any(DocumentReference.class))).thenReturn(true);
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Aggregations

AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)13 DocumentReference (org.xwiki.model.reference.DocumentReference)10 Before (org.junit.Before)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 Execution (org.xwiki.context.Execution)5 ExecutionContext (org.xwiki.context.ExecutionContext)5 Test (org.junit.Test)4 XWiki (com.xpn.xwiki.XWiki)3 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)3 WikiReference (org.xwiki.model.reference.WikiReference)3 Date (java.util.Date)2 List (java.util.List)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 ModelContext (org.xwiki.model.ModelContext)2 QueryManager (org.xwiki.query.QueryManager)2 XDOM (org.xwiki.rendering.block.XDOM)2 Parser (org.xwiki.rendering.parser.Parser)2