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());
}
}
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);
}
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);
}
Aggregations