Skip to main content

Disallow access to a folder and its children if user is anonymous

Project description

What is iw.rejectanonymous ?

This package is made to reject unconditionnally anonymous users from a plone site; they should get redirected by plone to login form. The basic use case is an extranet, where all visitors must be authenticated.

How to use iw.rejectanonymous ?

By default an anonymous user can browse portal:

>>> portal_url = self.portal.absolute_url()
>>> browser.open(portal_url)
>>> browser.url == portal_url
True
>>> browser.headers['status']
'200 OK'

We mark the portal with IPrivateSite; this can be achieved by code or in the ZMI using “Interfaces” tab on the portal object. Now Anonymous will get Unauthorized exception. In a plone site this should results in a redirect to login form.

>>> from zope.interface import alsoProvides
>>> from iw.rejectanonymous import IPrivateSite
>>> alsoProvides(self.portal, IPrivateSite)
>>> browser.open(portal_url)
Traceback (most recent call last):
...
Unauthorized: ...

Login form and some styles ressources are still accessible:

>>> login_form_url = self.portal.login_form.absolute_url()
>>> browser.open(login_form_url)
>>> browser.url == login_form_url
True
>>> require_login_url = self.portal.require_login.absolute_url()
>>> browser.open(require_login_url)
>>> browser.url == require_login_url
True
>>> cooked_css = self.portal.portal_css.getCookedResources()[0]
>>> cooked_css_url = '%s/portal_css/%s' % (portal_url, cooked_css.getId())
>>> browser.open(cooked_css_url)
>>> browser.url == cooked_css_url
True
>>> cooked_js = self.portal.portal_javascripts.getCookedResources()[0]
>>> cooked_js_url = '%s/portal_javascripts/%s' % (portal_url, cooked_js.getId())
>>> browser.open(cooked_js_url)
>>> browser.url == cooked_js_url
True
>>> logo_id = self.portal.base_properties.getProperty('logoName')
>>> logo_url = self.portal[logo_id].absolute_url()
>>> browser.open(logo_url)
>>> browser.url == logo_url
True

Then we log in, and we will be authorized to browse the portal

>>> from Products.PloneTestCase.setup import default_user, default_password
>>> browser.addHeader('Authorization',
...                   'Basic %s:%s' % (default_user, default_password))
>>> browser.open(portal_url)
>>> browser.url == portal_url
True
>>> browser.headers['status']
'200 OK'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iw.rejectanonymous-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iw.rejectanonymous-1.0.0-py2.4.egg (10.9 kB view details)

Uploaded Egg

File details

Details for the file iw.rejectanonymous-1.0.0.tar.gz.

File metadata

File hashes

Hashes for iw.rejectanonymous-1.0.0.tar.gz
Algorithm Hash digest
SHA256 87c8017949266dac18418a7c2cc00c209371a6c9f5a0bdcceffa89fee0384c4e
MD5 41d38708c544b28abb20643ab00ae9b4
BLAKE2b-256 83914e0a2f3319c2c2eb870d03d47466d72365e44456b781ca8ec0f7ac357f7d

See more details on using hashes here.

File details

Details for the file iw.rejectanonymous-1.0.0-py2.4.egg.

File metadata

File hashes

Hashes for iw.rejectanonymous-1.0.0-py2.4.egg
Algorithm Hash digest
SHA256 d3a400767a739e17130b6b8a00f59041c3fcf65156d623375512f1bfc12bc03d
MD5 872afdb62fdf972445bd184758bf798f
BLAKE2b-256 83997879c44dde52868f19cee9224ad852178cf648b35356219b3e895d11f55a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page