Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / login.py @ 64b6bc45

History | View | Annotate | Download (2.3 kB)

1 2e662088 Antony Chazapis
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 0a8bf8fb Antony Chazapis
# 
3 0a8bf8fb Antony Chazapis
# Redistribution and use in source and binary forms, with or
4 0a8bf8fb Antony Chazapis
# without modification, are permitted provided that the following
5 0a8bf8fb Antony Chazapis
# conditions are met:
6 0a8bf8fb Antony Chazapis
# 
7 0a8bf8fb Antony Chazapis
#   1. Redistributions of source code must retain the above
8 0a8bf8fb Antony Chazapis
#      copyright notice, this list of conditions and the following
9 0a8bf8fb Antony Chazapis
#      disclaimer.
10 0a8bf8fb Antony Chazapis
# 
11 0a8bf8fb Antony Chazapis
#   2. Redistributions in binary form must reproduce the above
12 0a8bf8fb Antony Chazapis
#      copyright notice, this list of conditions and the following
13 0a8bf8fb Antony Chazapis
#      disclaimer in the documentation and/or other materials
14 0a8bf8fb Antony Chazapis
#      provided with the distribution.
15 0a8bf8fb Antony Chazapis
# 
16 0a8bf8fb Antony Chazapis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 0a8bf8fb Antony Chazapis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 0a8bf8fb Antony Chazapis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 0a8bf8fb Antony Chazapis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 0a8bf8fb Antony Chazapis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 0a8bf8fb Antony Chazapis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 0a8bf8fb Antony Chazapis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 0a8bf8fb Antony Chazapis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 0a8bf8fb Antony Chazapis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 0a8bf8fb Antony Chazapis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 0a8bf8fb Antony Chazapis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 0a8bf8fb Antony Chazapis
# POSSIBILITY OF SUCH DAMAGE.
28 0a8bf8fb Antony Chazapis
# 
29 0a8bf8fb Antony Chazapis
# The views and conclusions contained in the software and
30 0a8bf8fb Antony Chazapis
# documentation are those of the authors and should not be
31 0a8bf8fb Antony Chazapis
# interpreted as representing official policies, either expressed
32 0a8bf8fb Antony Chazapis
# or implied, of GRNET S.A.
33 0a8bf8fb Antony Chazapis
34 0a8bf8fb Antony Chazapis
import logging
35 0a8bf8fb Antony Chazapis
36 a49baffa Antony Chazapis
from urlparse import urlparse
37 a49baffa Antony Chazapis
38 0a8bf8fb Antony Chazapis
from django.http import HttpResponseNotFound, HttpResponseRedirect
39 a903e505 Antony Chazapis
from django.utils.http import urlencode
40 a49baffa Antony Chazapis
41 a49baffa Antony Chazapis
from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS
42 0a8bf8fb Antony Chazapis
43 0a8bf8fb Antony Chazapis
44 0a8bf8fb Antony Chazapis
logger = logging.getLogger(__name__)
45 0a8bf8fb Antony Chazapis
46 0a8bf8fb Antony Chazapis
47 0a8bf8fb Antony Chazapis
def redirect_to_login_service(request):
48 a49baffa Antony Chazapis
    url = AUTHENTICATION_URL
49 a49baffa Antony Chazapis
    users = AUTHENTICATION_USERS
50 a49baffa Antony Chazapis
    if users or not url:
51 4732ed31 Antony Chazapis
        return HttpResponseNotFound()
52 0a8bf8fb Antony Chazapis
    
53 a49baffa Antony Chazapis
    p = urlparse(url)
54 0a8bf8fb Antony Chazapis
    if request.is_secure():
55 4732ed31 Antony Chazapis
        proto = 'https://'
56 0a8bf8fb Antony Chazapis
    else:
57 4732ed31 Antony Chazapis
        proto = 'http://'
58 4732ed31 Antony Chazapis
    next = request.GET.get('next', '')
59 4732ed31 Antony Chazapis
    params = {'next': next}
60 4732ed31 Antony Chazapis
    renew = 'renew' in request.GET
61 4732ed31 Antony Chazapis
    if renew:
62 4732ed31 Antony Chazapis
        params['renew'] = True
63 a49baffa Antony Chazapis
    uri = proto + p.netloc + '/login?' + urlencode(params)
64 4732ed31 Antony Chazapis
    return HttpResponseRedirect(uri)