-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauthenhandler
More file actions
30 lines (20 loc) · 790 Bytes
/
authenhandler
File metadata and controls
30 lines (20 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import base64, httplib, mod_python, urlparse
# Create HTTP connection from URL scheme, host, and port
def http_connection(url):
components = list(urlparse.urlparse(url))
if 'https' == components[0]:
return httplib.HTTPSConnection(components[1])
return httplib.HTTPConnection(components[1])
def authenhandler(r):
method = 'MKACTIVITY'
url = 'https://archivematica.googlecode.com/svn/'
headers = {
'Authorization': 'Basic ' + base64.b64encode(r.user + ':' + r.get_basic_auth_pw()) }
conn = http_connection(url)
conn.request(method, url, None, headers)
response = conn.getresponse()
if httplib.CONFLICT == response.status:
if '@' not in r.user:
r.user += '@gmail.com'
return mod_python.apache.OK
return mod_python.apache.HTTP_UNAUTHORIZED