use of org.xwiki.security.authorization.AccessDeniedException in project xwiki-platform by xwiki.
the class NotificationPreferenceScriptServiceTest method saveNotificationPreferencesWithoutRight.
@Test
public void saveNotificationPreferencesWithoutRight() throws Exception {
DocumentReference userDoc = new DocumentReference("wikiA", "SpaceA", "UserA");
AccessDeniedException e = mock(AccessDeniedException.class);
doThrow(e).when(authorizationManager).checkAccess(Right.EDIT, userDoc);
String json = "";
Exception caughtException = null;
try {
mocker.getComponentUnderTest().saveNotificationPreferences(json, userDoc);
} catch (Exception ex) {
caughtException = ex;
}
assertNotNull(caughtException);
assertEquals(e, caughtException);
}
use of org.xwiki.security.authorization.AccessDeniedException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method currentScriptHasNotAdminRight.
/**
* Mocks the components to simulate that a non admin user have saved the current script.
*
* @return the exception expected when the current script has the not the admin right
*/
private Exception currentScriptHasNotAdminRight() throws AccessDeniedException {
DocumentReference authorDocRef = new DocumentReference("mainWiki", "XWiki", "NonAdmin");
when(currentDoc.getAuthorReference()).thenReturn(authorDocRef);
DocumentReference currentDocRef = new DocumentReference("subwiki", "Space", "PageToTest");
when(currentDoc.getDocumentReference()).thenReturn(currentDocRef);
Exception exception = new AccessDeniedException(Right.ADMIN, authorDocRef, currentDocRef);
doThrow(exception).when(authorizationManager).checkAccess(Right.ADMIN, authorDocRef, currentDocRef);
return exception;
}
use of org.xwiki.security.authorization.AccessDeniedException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method currentUserHasNotAdminRight.
/**
* Mocks the components to simulate that the current user is not an admin.
*
* @return the exception expected when the current user has the not the admin right
*/
private Exception currentUserHasNotAdminRight() throws AccessDeniedException {
WikiReference wiki = new WikiReference("subwiki");
Exception exception = new AccessDeniedException(Right.ADMIN, userDocRef, wiki);
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.ADMIN), eq(userDocRef), eq(wiki));
return exception;
}
use of org.xwiki.security.authorization.AccessDeniedException in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method currentUserHasNotCreateWikiRight.
/**
* @return the exception expected when the current user has the not the 'create wiki' right
*/
private Exception currentUserHasNotCreateWikiRight() throws AccessDeniedException {
WikiReference wiki = new WikiReference("mainWiki");
Exception exception = new AccessDeniedException(Right.CREATE_WIKI, currentUserRef, wiki);
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.CREATE_WIKI), eq(currentUserRef), eq(wiki));
return exception;
}
use of org.xwiki.security.authorization.AccessDeniedException in project xwiki-platform by xwiki.
the class WikiCreationJobScriptServices method createWiki.
/**
* Asynchronously create a wiki.
*
* @param request creation wiki request containing all information about the wiki to create
* @return the creationjob that creates the wiki
*/
public Job createWiki(WikiCreationRequest request) {
try {
// Verify that the user has the CREATE_WIKI right
XWikiContext xcontext = xcontextProvider.get();
WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId());
authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference);
// Verify that if an extension id is provided, this extension is authorized.
if (request.getExtensionId() != null) {
if (!isAuthorizedExtension(request.getExtensionId())) {
throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId()));
}
}
return wikiCreator.createWiki(request);
} catch (WikiCreationException e) {
setLastError(e);
logger.warn("Failed to create a new wiki.", e);
} catch (AccessDeniedException e) {
setLastError(e);
}
return null;
}
Aggregations