Esempio n. 1
0
    def test_define_and_undefineChecker(self):
        class SomeClass(object):
            pass
        obj = SomeClass()

        checker = NamesChecker()
        from zope.security.checker import _defaultChecker, selectChecker
        self.assert_(selectChecker(obj) is _defaultChecker)
        defineChecker(SomeClass, checker)
        self.assert_(selectChecker(obj) is checker)
        undefineChecker(SomeClass)
        self.assert_(selectChecker(obj) is _defaultChecker)
    def test_define_and_undefineChecker(self):
        class SomeClass(object):
            pass

        obj = SomeClass()

        checker = NamesChecker()
        from zope.security.checker import _defaultChecker, selectChecker
        self.assert_(selectChecker(obj) is _defaultChecker)
        defineChecker(SomeClass, checker)
        self.assert_(selectChecker(obj) is checker)
        undefineChecker(SomeClass)
        self.assert_(selectChecker(obj) is _defaultChecker)
Esempio n. 3
0
def register_service(_context,
                     configuration,
                     content,
                     method,
                     layer,
                     default_permission,
                     name=''):
    logger.debug(configuration)
    factory = configuration['factory']
    if isinstance(factory, str):
        factory = import_class(factory)

    if factory is None:
        raise TypeError('Factory not defined {0:s} '.format(
            configuration['factory']))
    if getCheckerForInstancesOf(factory):
        # in case already exist remove old checker
        undefineChecker(factory)
    if 'permission' in configuration:
        permission = configuration['permission']
    else:
        permission = default_permission
    required = {}
    for n in ('__call__', 'publishTraverse'):
        required[n] = permission

    # prevent circular import
    from plone.server.security import ViewPermissionChecker
    from plone.server import app_settings

    defineChecker(factory, ViewPermissionChecker(required))
    logger.debug('Defining adapter for '  # noqa
                 '{0:s} {1:s} {2:s} to {3:s} name {4:s}'.format(
                     content.__identifier__,
                     app_settings['http_methods'][method].__identifier__,
                     layer.__identifier__, str(factory), name))
    adapter(_context,
            factory=(factory, ),
            provides=app_settings['http_methods'][method],
            for_=(content, layer),
            name=name)
Esempio n. 4
0
def register_service(_context, configuration, content, method, layer,
                     default_permission, name=''):
    logger.debug(configuration)
    factory = configuration['factory']
    if isinstance(factory, str):
        factory = import_class(factory)

    if factory is None:
        raise TypeError(
            'Factory not defined {0:s} '.format(configuration['factory']))
    if getCheckerForInstancesOf(factory):
        # in case already exist remove old checker
        undefineChecker(factory)
    if 'permission' in configuration:
        permission = configuration['permission']
    else:
        permission = default_permission
    required = {}
    for n in ('__call__', 'publishTraverse'):
        required[n] = permission

    # prevent circular import
    from plone.server.auth.checker import ViewPermissionChecker
    from plone.server import app_settings

    defineChecker(factory, ViewPermissionChecker(required))
    logger.debug('Defining adapter for '  # noqa
                 '{0:s} {1:s} {2:s} to {3:s} name {4:s}'.format(
        content.__identifier__,
        app_settings['http_methods'][method].__identifier__,
        layer.__identifier__,
        str(factory),
        name))
    adapter(
        _context,
        factory=(factory,),
        provides=app_settings['http_methods'][method],
        for_=(content, layer),
        name=name
    )
Esempio n. 5
0
 def tearDown(self):
     undefineChecker(MyObj)
     cleanUp()
Esempio n. 6
0
 def tearDown(self):
     functional.BrowserTestCase.tearDown(self)
     undefineChecker(MyObj)
Esempio n. 7
0
 def tearDown(self):
     undefineChecker(MyObj)
     undefineChecker(RootFolder)
     undefineChecker(Folder)
     cleanUp()
 def tearDown(self):
     undefineChecker(MyObj)
     cleanUp()