Statistics
| Branch: | Tag: | Revision:

root / aai / shibboleth.py @ ac3c3a4b

History | View | Annotate | Download (1.8 kB)

1
#
2
# Business Logic for working with sibbolleth users
3
#
4
# Copyright 2010 Greek Research and Technology Network
5
#
6

    
7
from synnefo.logic import users
8

    
9
class Tokens:
10
    SIB_NAME = "Shib-InetOrgPerson-givenName"
11
    SIB_SURNAME = "Shib-Person-surname"
12
    SIB_CN = "Shib-Person-commonName"
13
    SIB_DISPLAY_NAME = "displayName"
14
    SIB_EPPN = "eppn"
15
    SIB_EDU_PERSON_AFFILIATION = "shib_ep_primaryaffiliation"
16
    SIB_SCHAC_PERSONAL_UNIQUE_CODE = "schacPersonalUniqueCode"
17
    SIB_GR_EDU_PERSON_UNDERGRADUATE_BRANCH = "grEduPersonUndergraduateBranch"
18
    SIB_SESSION_ID = "Shib-Session-ID"
19

    
20
class NoUniqueToken(object):
21

    
22
    def __init__(self, msg):
23
        self.msg = msg
24
    
25
    pass
26

    
27
class NoRealName(object):
28

    
29
    def __init__(self, msg):
30
        self.msg = msg
31

    
32
    pass
33

    
34
def register_shibboleth_user(tokens):
35
    """Registers a sibbolleth user using the input hash as a source for data.
36
       The token requirements are described in:
37
       http://aai.grnet.gr/policy
38
    """
39
    realname = None
40

    
41
    if Tokens.SIB_SURNAME in tokens:
42
        realname = tokens[Tokens.SIB_SURNAME]
43
    else:
44
        realname = ''
45

    
46
    if Tokens.SIB_NAME in tokens:
47
        realname = tokens[Tokens.SIB_NAME] + ' ' + realname
48

    
49
    if Tokens.SIB_CN in tokens:
50
        realname = tokens[Tokens.SIB_CN]
51

    
52
    is_student = Tokens.SIB_SCHAC_PERSONAL_UNIQUE_CODE in tokens or \
53
                 Tokens.SIB_GR_EDU_PERSON_UNDERGRADUATE_BRANCH in tokens
54

    
55
    unq = tokens.get(Tokens.SIB_EPPN)
56

    
57
    if unq is None:
58
        raise NoUniqueToken("Authentication does not return a unique token")
59

    
60
    if realname is None:
61
        raise NoRealName("Authentication does not return the user's name")
62

    
63
    if is_student:
64
        users.register_student(realname, '' ,unq)
65
    else:
66
        users.register_professor(realname, '' ,unq)
67

    
68
    return True