Search in sources :

Example 1 with XWikiRightServiceImpl

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());
}
Also used : Expectations(org.jmock.Expectations) ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Invocation(org.jmock.api.Invocation) CustomAction(org.jmock.lib.action.CustomAction) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Parser(org.xwiki.rendering.parser.Parser) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiRightService(com.xpn.xwiki.user.api.XWikiRightService) XWikiRightServiceImpl(com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiGroupService(com.xpn.xwiki.user.api.XWikiGroupService) Before(org.junit.Before)

Example 2 with XWikiRightServiceImpl

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();
}
Also used : XWikiCachingRightService(org.xwiki.security.authorization.internal.XWikiCachingRightService) XWikiRightServiceImpl(com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl) Before(org.junit.Before)

Example 3 with XWikiRightServiceImpl

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()));
}
Also used : XWikiCachingRightService(org.xwiki.security.authorization.internal.XWikiCachingRightService) XWikiRightServiceImpl(com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl) Test(org.junit.Test)

Example 4 with XWikiRightServiceImpl

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;
    }
}
Also used : XWikiRightService(com.xpn.xwiki.user.api.XWikiRightService) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) XWikiRightServiceImpl(com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Aggregations

XWikiRightServiceImpl (com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl)4 XWikiRightService (com.xpn.xwiki.user.api.XWikiRightService)2 Before (org.junit.Before)2 XWikiCachingRightService (org.xwiki.security.authorization.internal.XWikiCachingRightService)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 XWikiGroupService (com.xpn.xwiki.user.api.XWikiGroupService)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 NamingException (javax.naming.NamingException)1 URIException (org.apache.commons.httpclient.URIException)1 HibernateException (org.hibernate.HibernateException)1 Expectations (org.jmock.Expectations)1 Invocation (org.jmock.api.Invocation)1