use of com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
getMockery().checking(new Expectations() {
{
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(new CustomAction("WikiDescriptorManager#getCurrentWikiId") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return getContext().getWikiId();
}
});
}
});
final ContextualAuthorizationManager mockCam = getContextualAuthorizationManager();
final XWiki mockXWiki = getMockery().mock(XWiki.class);
final XWikiGroupService mockXWikiGroupService = getMockery().mock(XWikiGroupService.class);
getContext().setWiki(mockXWiki);
this.xwiki20Parser = getComponentManager().getInstance(Parser.class, "xwiki/2.0");
this.wikiMacroDocumentReference = new DocumentReference(getContext().getWikiId(), "space", "macroPage");
this.wikiMacroManager = getComponentManager().getInstance(WikiMacroManager.class);
this.wikiMacroDocument = new XWikiDocument(wikiMacroDocumentReference);
final XWikiRightService rightService = new XWikiRightServiceImpl();
this.user = new XWikiDocument(new DocumentReference(getContext().getWikiId(), "XWiki", "user"));
this.user.setNew(false);
BaseObject userObject = new BaseObject();
userObject.setXClassReference(new DocumentReference(getContext().getWikiId(), "XWiki", "XWikiusers"));
this.user.addXObject(userObject);
this.wikiMacroDocument.setCreatorReference(this.user.getAuthorReference());
this.wikiMacroDocument.setAuthorReference(this.user.getAuthorReference());
this.wikiMacroDocument.setContentAuthorReference(this.user.getAuthorReference());
// Setup an XWikiPreferences document granting programming rights to user
final XWikiDocument prefs = new XWikiDocument(new DocumentReference(getContext().getWikiId(), "XWiki", "XWikiPreferences"));
final BaseObject mockGlobalRightObj = getMockery().mock(BaseObject.class);
getMockery().checking(new Expectations() {
{
allowing(mockCam).hasAccess(Right.PROGRAM);
will(returnValue(true));
allowing(mockXWiki).getDocument(with(equal(wikiMacroDocumentReference)), with(any(XWikiContext.class)));
will(returnValue(wikiMacroDocument));
allowing(mockXWiki).isReadOnly();
will(returnValue(false));
allowing(mockXWiki).getLanguagePreference(with(any(XWikiContext.class)));
will(returnValue(null));
allowing(mockXWiki).getRightService();
will(returnValue(rightService));
allowing(mockXWiki).getGroupService(with(any(XWikiContext.class)));
will(returnValue(mockXWikiGroupService));
allowing(mockXWikiGroupService).getAllGroupsReferencesForMember(with(any(DocumentReference.class)), with(any(int.class)), with(any(int.class)), with(any(XWikiContext.class)));
will(returnValue(Collections.EMPTY_LIST));
allowing(mockXWiki).getDocument(with(equal(XWIKIPREFERENCES_REFERENCE)), with(any(XWikiContext.class)));
will(returnValue(prefs));
allowing(mockGlobalRightObj).getStringValue("levels");
will(returnValue("programming"));
allowing(mockGlobalRightObj).getStringValue("users");
will(returnValue(user.getFullName()));
allowing(mockGlobalRightObj).getIntValue("allow");
will(returnValue(1));
allowing(mockGlobalRightObj).setNumber(with(any(int.class)));
allowing(mockGlobalRightObj).setDocumentReference(with(any(DocumentReference.class)));
allowing(mockGlobalRightObj).setOwnerDocument(with(any(XWikiDocument.class)));
}
});
prefs.addObject("XWiki.XWikiGlobalRights", mockGlobalRightObj);
getContext().setUserReference(this.user.getDocumentReference());
}
use of com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl in project xwiki-platform by xwiki.
the class AbstractLegacyWikiTestCase method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
this.legacyImpl = new XWikiRightServiceImpl();
this.cachingImpl = new XWikiCachingRightService();
}
use of com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl in project xwiki-platform by xwiki.
the class TestLegacyTestWiki method testLegacyWikiBuilding.
@Test
public void testLegacyWikiBuilding() throws Exception {
LegacyTestWiki testWiki = new LegacyTestWiki(getMockery(), getComponentManager(), "test.xml", true);
XWikiRightServiceImpl legacyImpl = new XWikiRightServiceImpl();
testWiki.getXWikiContext().setWikiId("xwiki");
Assert.assertTrue(legacyImpl.hasAccessLevel("view", "AllanSvensson", "Main.WebHome", testWiki.getXWikiContext()));
XWikiCachingRightService cachingImpl = new XWikiCachingRightService();
Assert.assertTrue(cachingImpl.hasAccessLevel("view", "AllanSvensson", "Main.WebHome", testWiki.getXWikiContext()));
}
use of com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl in project xwiki-platform by xwiki.
the class XWiki method getRightService.
public XWikiRightService getRightService() {
synchronized (this.RIGHT_SERVICE_LOCK) {
if (this.rightService == null) {
LOGGER.info("Initializing RightService...");
String rightsClass = getConfiguration().getProperty("xwiki.authentication.rightsclass");
if (rightsClass != null && !rightsClass.equals(DEFAULT_RIGHT_SERVICE_CLASS)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Using custom Right Service [{}].", rightsClass);
}
} else {
rightsClass = DEFAULT_RIGHT_SERVICE_CLASS;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Using default Right Service [{}].", rightsClass);
}
}
try {
this.rightService = (XWikiRightService) Class.forName(rightsClass).newInstance();
LOGGER.debug("Initialized RightService using Reflection.");
} catch (Exception e) {
Exception lastException = e;
if (!rightsClass.equals(DEFAULT_RIGHT_SERVICE_CLASS)) {
LOGGER.warn(String.format("Failed to initialize custom RightService [%s]" + " by Reflection, using default implementation [%s].", rightsClass, DEFAULT_RIGHT_SERVICE_CLASS), e);
rightsClass = DEFAULT_RIGHT_SERVICE_CLASS;
try {
this.rightService = (XWikiRightService) Class.forName(rightsClass).newInstance();
LOGGER.debug("Initialized default RightService using Reflection.");
} catch (Exception e1) {
lastException = e1;
}
}
if (this.rightService == null) {
LOGGER.warn(String.format("Failed to initialize RightService [%s]" + " by Reflection, using OLD implementation [%s] with 'new'.", rightsClass, XWikiRightServiceImpl.class.getCanonicalName()), lastException);
this.rightService = new XWikiRightServiceImpl();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Initialized old RightService implementation " + this.rightService.getClass().getName() + " using 'new'.");
}
}
}
}
return this.rightService;
}
}
Aggregations