Statistics
| Branch: | Tag: | Revision:

root / utils / decorators.py @ fb5ebbe2

History | View | Annotate | Download (1.4 kB)

1 9f54980a Leonidas Poulopoulos
# -*- coding: utf-8 -*- vim:fileencoding=utf-8:
2 afe2813b Leonidas Poulopoulos
# vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
3 afe2813b Leonidas Poulopoulos
4 afe2813b Leonidas Poulopoulos
# Copyright © 2011-2014 Greek Research and Technology Network (GRNET S.A.)
5 afe2813b Leonidas Poulopoulos
# Copyright © 2011-2014 Leonidas Poulopoulos (@leopoul)
6 afe2813b Leonidas Poulopoulos
# 
7 afe2813b Leonidas Poulopoulos
# Permission to use, copy, modify, and/or distribute this software for any
8 afe2813b Leonidas Poulopoulos
# purpose with or without fee is hereby granted, provided that the above
9 afe2813b Leonidas Poulopoulos
# copyright notice and this permission notice appear in all copies.
10 afe2813b Leonidas Poulopoulos
# 
11 afe2813b Leonidas Poulopoulos
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12 afe2813b Leonidas Poulopoulos
# TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13 afe2813b Leonidas Poulopoulos
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14 afe2813b Leonidas Poulopoulos
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
15 afe2813b Leonidas Poulopoulos
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
16 afe2813b Leonidas Poulopoulos
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
17 afe2813b Leonidas Poulopoulos
# SOFTWARE.
18 9f54980a Leonidas Poulopoulos
19 97e42c7d Leonidas Poulopoulos
from django.http import HttpResponseRedirect
20 97e42c7d Leonidas Poulopoulos
from django.core.urlresolvers import reverse
21 97e42c7d Leonidas Poulopoulos
22 97e42c7d Leonidas Poulopoulos
23 97e42c7d Leonidas Poulopoulos
def shib_required(f):
24 97e42c7d Leonidas Poulopoulos
    def wrap(request, *args, **kwargs):
25 97e42c7d Leonidas Poulopoulos
        if 'HTTP_SHIB_SESSION_ID' not in request.META or not request.META['HTTP_SHIB_SESSION_ID']:
26 97e42c7d Leonidas Poulopoulos
            return HttpResponseRedirect(reverse('login'))
27 97e42c7d Leonidas Poulopoulos
        return f(request, *args, **kwargs)
28 97e42c7d Leonidas Poulopoulos
29 97e42c7d Leonidas Poulopoulos
    wrap.__doc__=f.__doc__
30 97e42c7d Leonidas Poulopoulos
    wrap.__name__=f.__name__
31 97e42c7d Leonidas Poulopoulos
    return wrap