Attachment 'cas.pep8.patch'
Download 1 --- cas_old.py 2009-09-01 08:34:30.000000000 +0000
2 +++ cas.py 2009-09-01 08:19:27.000000000 +0000
3 @@ -30,7 +30,7 @@
4 'validate_path': '/validate',
5 }
6 self.paths.update(kwords)
7 -
8 +
9 def login_url(self, service):
10 """Return the login URL for the given service."""
11 base = self.url + self.paths['login_path'] + '?service=' + urllib.quote_plus(service)
12 @@ -60,25 +60,35 @@
13 user = f.readline().strip()
14
15 return (valid, user)
16 -
17 +
18 +
19 class CASAuth(BaseAuth):
20 """ handle login from CAS """
21 name = 'CAS'
22 logout_possible = True
23 + login_inputs = ['username', 'password']
24
25 - def __init__(self, auth_server, login_path = "/login", logout_path = "/logout", validate_path = "/validate"):
26 + def __init__(self, auth_server, login_path="/login", logout_path="/logout", validate_path="/validate"):
27 BaseAuth.__init__(self)
28 self.auth_server = auth_server
29 self.login_path = login_path
30 self.logout_path = logout_path
31 self.validate_path = validate_path
32
33 + paths = {
34 + 'login_path': self.login_path,
35 + 'logout_path': self.logout_path,
36 + 'validate_path': self.validate_path,
37 + }
38 +
39 + self.cas = PyCAS(self.auth_server, **paths)
40 +
41 def request(self, request, user_obj, **kw):
42 ticket = request.args.get('ticket')
43 action = request.args.get("action", [])
44 logoutRequest = request.args.get('logoutRequest', [])
45 url = request.getBaseURL() + urllib.quote_plus(request.getPathinfo().encode('utf-8'))
46 -
47 +
48 # # handle logout request from CAS
49 # if logoutRequest:
50 # logoutRequestMatch = re.search("<samlp:SessionIndex>(.*)</samlp:SessionIndex>", logoutRequest[0])
51 @@ -86,15 +96,15 @@
52 # if service_ticket:
53 # # TODO: logout
54 # return self.logout(request, user_obj)
55 -
56 +
57 # authenticated user
58 if user_obj and user_obj.valid:
59 return user_obj, True
60 -
61 +
62 # anonymous
63 if not ticket and not "login" in action:
64 return user_obj, True
65 -
66 +
67 # valid ticket on CAS
68 if ticket:
69 valid, username = self.cas.validate_ticket(url, ticket[0])
70 @@ -104,28 +114,17 @@
71 # auto create user
72 u.create_or_update(True)
73 return u, True
74 -
75 +
76 # login
77 request.http_redirect(self.cas.login_url(url))
78 -
79 +
80 return user_obj, True
81 -
82 +
83 def logout(self, request, user_obj, **kw):
84 if self.name and user_obj and user_obj.auth_method == self.name:
85 url = request.getBaseURL() + urllib.quote_plus(request.getPathinfo().encode('utf-8'))
86 request.http_redirect(self.cas.logout_url(url))
87 -
88 +
89 user_obj.valid = False
90 -
91 +
92 return user_obj, True
93 -
94 - def _cas(self):
95 - paths = {
96 - 'login_path': self.login_path,
97 - 'logout_path': self.logout_path,
98 - 'validate_path': self.validate_path,
99 - }
100 -
101 - return PyCAS(self.auth_server, **paths)
102 - cas = property(_cas)
103 -
104
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.