root / pithos / im / target / shibboleth.py @ a7bdef13
History | View | Annotate | Download (3 kB)
1 | 93f046ab | Giorgos Verigakis | # Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 552ea518 | Antony Chazapis | #
|
3 | 93f046ab | Giorgos Verigakis | # Redistribution and use in source and binary forms, with or
|
4 | 93f046ab | Giorgos Verigakis | # without modification, are permitted provided that the following
|
5 | 93f046ab | Giorgos Verigakis | # conditions are met:
|
6 | 552ea518 | Antony Chazapis | #
|
7 | 93f046ab | Giorgos Verigakis | # 1. Redistributions of source code must retain the above
|
8 | 93f046ab | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
9 | 93f046ab | Giorgos Verigakis | # disclaimer.
|
10 | 552ea518 | Antony Chazapis | #
|
11 | 93f046ab | Giorgos Verigakis | # 2. Redistributions in binary form must reproduce the above
|
12 | 93f046ab | Giorgos Verigakis | # copyright notice, this list of conditions and the following
|
13 | 93f046ab | Giorgos Verigakis | # disclaimer in the documentation and/or other materials
|
14 | 93f046ab | Giorgos Verigakis | # provided with the distribution.
|
15 | 552ea518 | Antony Chazapis | #
|
16 | 93f046ab | Giorgos Verigakis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 93f046ab | Giorgos Verigakis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 93f046ab | Giorgos Verigakis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 93f046ab | Giorgos Verigakis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 93f046ab | Giorgos Verigakis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 93f046ab | Giorgos Verigakis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 93f046ab | Giorgos Verigakis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 93f046ab | Giorgos Verigakis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 93f046ab | Giorgos Verigakis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 93f046ab | Giorgos Verigakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 93f046ab | Giorgos Verigakis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 93f046ab | Giorgos Verigakis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 552ea518 | Antony Chazapis | #
|
29 | 93f046ab | Giorgos Verigakis | # The views and conclusions contained in the software and
|
30 | 93f046ab | Giorgos Verigakis | # documentation are those of the authors and should not be
|
31 | 93f046ab | Giorgos Verigakis | # interpreted as representing official policies, either expressed
|
32 | 93f046ab | Giorgos Verigakis | # or implied, of GRNET S.A.
|
33 | 93f046ab | Giorgos Verigakis | |
34 | 552ea518 | Antony Chazapis | from django.http import HttpResponseBadRequest |
35 | b4c241e6 | Sofia Papagiannaki | from django.core.urlresolvers import reverse |
36 | 93f046ab | Giorgos Verigakis | |
37 | 26986f1c | Antony Chazapis | from pithos.im.target.util import get_or_create_user, prepare_response |
38 | 93f046ab | Giorgos Verigakis | |
39 | 93f046ab | Giorgos Verigakis | |
40 | 552ea518 | Antony Chazapis | class Tokens: |
41 | 552ea518 | Antony Chazapis | # these are mapped by the Shibboleth SP software
|
42 | 552ea518 | Antony Chazapis | SHIB_EPPN = "HTTP_EPPN" # eduPersonPrincipalName |
43 | 552ea518 | Antony Chazapis | SHIB_NAME = "HTTP_SHIB_INETORGPERSON_GIVENNAME"
|
44 | 552ea518 | Antony Chazapis | SHIB_SURNAME = "HTTP_SHIB_PERSON_SURNAME"
|
45 | 552ea518 | Antony Chazapis | SHIB_CN = "HTTP_SHIB_PERSON_COMMONNAME"
|
46 | 552ea518 | Antony Chazapis | SHIB_DISPLAYNAME = "HTTP_SHIB_INETORGPERSON_DISPLAYNAME"
|
47 | 552ea518 | Antony Chazapis | SHIB_EP_AFFILIATION = "HTTP_SHIB_EP_AFFILIATION"
|
48 | 552ea518 | Antony Chazapis | SHIB_SESSION_ID = "HTTP_SHIB_SESSION_ID"
|
49 | 93f046ab | Giorgos Verigakis | |
50 | 93f046ab | Giorgos Verigakis | |
51 | 93f046ab | Giorgos Verigakis | def login(request): |
52 | 552ea518 | Antony Chazapis | tokens = request.META |
53 | 552ea518 | Antony Chazapis | |
54 | 93f046ab | Giorgos Verigakis | try:
|
55 | 552ea518 | Antony Chazapis | eppn = tokens[Tokens.SHIB_EPPN] |
56 | 552ea518 | Antony Chazapis | except KeyError: |
57 | 552ea518 | Antony Chazapis | return HttpResponseBadRequest("Missing unique token in request") |
58 | 93f046ab | Giorgos Verigakis | |
59 | 552ea518 | Antony Chazapis | if Tokens.SHIB_DISPLAYNAME in tokens: |
60 | 552ea518 | Antony Chazapis | realname = tokens[Tokens.SHIB_DISPLAYNAME] |
61 | 552ea518 | Antony Chazapis | elif Tokens.SHIB_CN in tokens: |
62 | 552ea518 | Antony Chazapis | realname = tokens[Tokens.SHIB_CN] |
63 | 552ea518 | Antony Chazapis | elif Tokens.SHIB_NAME in tokens and Tokens.SHIB_SURNAME in tokens: |
64 | 552ea518 | Antony Chazapis | realname = tokens[Tokens.SHIB_NAME] + ' ' + tokens[Tokens.SHIB_SURNAME]
|
65 | 552ea518 | Antony Chazapis | else:
|
66 | 552ea518 | Antony Chazapis | return HttpResponseBadRequest("Missing user name in request") |
67 | 93f046ab | Giorgos Verigakis | |
68 | 552ea518 | Antony Chazapis | affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
|
69 | 93f046ab | Giorgos Verigakis | |
70 | 91560b09 | Sofia Papagiannaki | return prepare_response(request,
|
71 | 0778f7e1 | Sofia Papagiannaki | get_or_create_user(eppn, realname, affiliation, 0),
|
72 | 0778f7e1 | Sofia Papagiannaki | request.GET.get('next'),
|
73 | 552ea518 | Antony Chazapis | 'renew' in request.GET) |