Revision ef39e7ee
b/api/middleware.py | ||
---|---|---|
1 |
from django.conf import settings |
|
2 |
from django.http import HttpResponse, HttpResponseRedirect |
|
1 | 3 |
from synnefo.api.errors import Unauthorized |
2 | 4 |
from synnefo.db.models import SynnefoUser |
3 | 5 |
|
... | ... | |
8 | 10 |
auth_key = "X-Auth-Key" |
9 | 11 |
|
10 | 12 |
def process_request(self, request): |
13 |
|
|
11 | 14 |
if self.auth_token in request.META: |
12 |
#Retrieve user from DB |
|
13 |
user = SynnefoUser.objects.get(request.META.get(self.auth_token))
|
|
15 |
#Retrieve user from DB or other caching mechanism
|
|
16 |
user = SynnefoUser.objects.filter(auth_token = request.META[self.auth_token])
|
|
14 | 17 |
if user is None : |
15 |
return |
|
18 |
return HttpResponseAuthenticationRequired(content='Athentication Required')
|
|
16 | 19 |
request.user = user |
20 |
return |
|
17 | 21 |
|
18 | 22 |
#An authentication request |
19 | 23 |
if self.auth_user in request.META and 'X-Auth-Key' in request.META \ |
20 | 24 |
and '/v1.0' == request.path and 'GET' == request.method: |
21 |
#Do authenticate or redirect |
|
22 |
return |
|
25 |
# This is here merely for compatibility with the Openstack API. |
|
26 |
# All normal users should authenticate through Sibbolleth. Admin |
|
27 |
# users or other selected users could use this as a bypass |
|
28 |
# mechanism |
|
29 |
user = SynnefoUser.objects.filter(username = request.META[self.auth_user]) |
|
30 |
|
|
31 |
return HttpResponseRedirect(content= settings.SIBBOLLETH_HOST) |
|
32 |
|
|
33 |
return HttpResponseAuthenticationRequired(content='Athentication Required') |
|
23 | 34 |
|
24 |
raise Unauthorized |
|
35 |
#class HttpResponseAuthenticationRequired(HttpResponse): |
|
36 |
# status_code = 401 |
b/db/fixtures/initial_data.json | ||
---|---|---|
1 | 1 |
[ |
2 |
{ |
|
3 |
"model": "db.SynnefoUser", |
|
4 |
"pk": 1, |
|
5 |
"fields": { |
|
6 |
"name": "admin user", |
|
7 |
"created": "2011-02-06 00:00:00", |
|
8 |
"updated": "2011-02-06 00:00:00", |
|
9 |
"credit": 1 |
|
10 |
} |
|
11 |
} |
|
12 | 2 |
] |
b/db/models.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
from django.conf import settings |
4 | 4 |
from django.db import models |
5 |
from django.contrib.auth.models import User |
|
5 | 6 |
|
6 | 7 |
import datetime |
7 | 8 |
|
8 |
class SynnefoUser(models.Model):
|
|
9 |
class SynnefoUser(User):
|
|
9 | 10 |
name = models.CharField('Synnefo Username', max_length=255) |
10 | 11 |
credit = models.IntegerField('Credit Balance') |
12 |
auth_token = models.CharField('Authentication Token', max_length=32) |
|
11 | 13 |
created = models.DateTimeField('Time of creation', auto_now_add=True) |
12 | 14 |
updated = models.DateTimeField('Time of last update', auto_now=True) |
13 | 15 |
|
... | ... | |
15 | 17 |
verbose_name = u'Synnefo User' |
16 | 18 |
|
17 | 19 |
def __unicode__(self): |
18 |
return self.name
|
|
20 |
return self.name |
|
19 | 21 |
|
20 | 22 |
def get_limit(self, limit_name): |
21 | 23 |
"""Returns the limit value for the specified limit""" |
b/settings.py.dist | ||
---|---|---|
149 | 149 |
#maximum number of seconds, needed for server and images polling |
150 | 150 |
|
151 | 151 |
GANETI_ZMQ_PUBLISHER = "tcp://62.217.120.67:5801" |
152 |
|
|
153 |
SIBBOLLETH_HOST = "http://wayf.grnet.gr/" |
Also available in: Unified diff