Statistics
| Branch: | Tag: | Revision:

root / aai / shibboleth.py @ 73dbfbf5

History | View | Annotate | Download (1.7 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_GIVEN_NAME = "shib_inetorgperson_givenname"
11
    SIB_SN = "shib_person_surname"
12
    SIB_CN = "cn"
13
    SIB_DISPLAY_NAME = "displayName"
14
    SIB_EDU_PERSON_PRINCIPAL_NAME = "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

    
19
class NoUniqueToken(object):
20

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

    
26
class NoRealName(object):
27

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

    
31
    pass
32

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

    
40
    if Tokens.SIB_GIVEN_NAME in tokens:
41
        realname = tokens[Tokens.SIB_GIVEN_NAME]
42

    
43
    if Tokens.SIB_DISPLAY_NAME in tokens:
44
        realname = tokens[Tokens.SIB_DISPLAY_NAME]
45

    
46
    is_student = Tokens.SIB_SCHAC_PERSONAL_UNIQUE_CODE in tokens or \
47
                 Tokens.SIB_GR_EDU_PERSON_UNDERGRADUATE_BRANCH in tokens
48

    
49
    unq = tokens.get(Tokens.SIB_EDU_PERSON_PRINCIPAL_NAME)
50

    
51
    if unq is None:
52
        raise NoUniqueToken("Authentication does not return a unique token")
53

    
54
    if realname is None:
55
        raise NoRealName("Authentication does not return the user's name")
56

    
57
    if is_student:
58
        users.register_student(realname, '' ,unq)
59
    else:
60
        users.register_professor(realname, '' ,unq)
61

    
62
    return True