skip to navigation
skip to content

Not Logged In

django-mithril 0.0.9

IP Whitelisting for Django

# Mithril

````

          ,--.  ,--.  ,--.            ,--.,--.
,--,--,--.`--',-'  '-.|  ,---. ,--.--.`--'|  |
|        |,--.'-.  .-'|  .-.  ||  .--',--.|  |
|  |  |  ||  |  |  |  |  | |  ||  |   |  ||  |
`--`--`--'`--'  `--'  `--' `--'`--'   `--'`--'

````

A Django application providing decorators, middleware, and authentication
backends for IP whitelisting.

> ### WARNING
>
> We grab IP address information from `request.META` -- which is potentially
> spoofable. Make sure your gateway servers don't allow rewriting of the headers
> you're targeting.

## Getting Started

Mithril works by providing two new models -- `Whitelist` and `Range` -- that you
make a foreign key to from your objects. You define a `mithril.strategy.Strategy`
subclass to describe to mithril how you would like to obtain a `Whitelist` from
a request.

````python
# myapp/models.py
from django.db import models
from django.contrib.sites.models import Site
from mithril.models import Whitelist

class SiteACL(models.Model):
    site = models.OneToOneField(Site)
    whitelist = models.ForeignKey(Whitelist, related_name='site_acl')

# myapp/strategy.py
from mithril.strategy import Strategy
from django.conf import settings
from myapp.models import SiteACL

class MyStrategy(Strategy):
    # a tuple of `method name` -> `lookup to apply`.
    # if the method does not exist, or returns None, it
    # continues to the next tuple.
    actions = (
        ('view_on_site', 'site_acl__pk')
    )

    def view_on_site(self, request, view, *view_args, **view_kwargs):
        try:
            site_acl = SiteACL.objects.get(site__pk=settings.SITE_ID)
            return site_acl.pk
        except SiteACL.DoesNotExist:
            pass

# settings.py

MITHRIL_STRATEGY = 'myapp.strategy.MyStrategy'
MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) + ['mithril.middleware.WhitelistMiddleware']
INSTALLED_APPS = list(INSTALLED_APPS) + ['mithril']

````
 
  • Downloads (All Versions):
  • 0 downloads in the last day
  • 0 downloads in the last week
  • 0 downloads in the last month
  • Author: Chris Dickinson
  • Home Page: http://urbanairship.github.com/django-mithril/
  • License:
    Copyright (c) 2012, Urban Airship
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in the
          documentation and/or other materials provided with the distribution.
        * Neither the name of Django-Mithril nor the
          names of its contributors may be used to endorse or promote products
          derived from this software without specific prior written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL URBAN AIRSHIP BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • Categories
  • Package Index Owner: gmcquillan
  • DOAP record: django-mithril-0.0.9.xml