| Line | |
|---|
| 1 |
# -*- coding: utf8 -*- |
|---|
| 2 |
# |
|---|
| 3 |
# Copyright (C) 2005 Matthew Good <trac@matt-good.net> |
|---|
| 4 |
# |
|---|
| 5 |
# "THE BEER-WARE LICENSE" (Revision 42): |
|---|
| 6 |
# <trac@matt-good.net> wrote this file. As long as you retain this notice you |
|---|
| 7 |
# can do whatever you want with this stuff. If we meet some day, and you think |
|---|
| 8 |
# this stuff is worth it, you can buy me a beer in return. Matthew Good |
|---|
| 9 |
# |
|---|
| 10 |
# Author: Matthew Good <trac@matt-good.net> |
|---|
| 11 |
|
|---|
| 12 |
from urllib2 import build_opener, HTTPBasicAuthHandler, \ |
|---|
| 13 |
HTTPDigestAuthHandler, HTTPPasswordMgrWithDefaultRealm |
|---|
| 14 |
|
|---|
| 15 |
from trac.core import * |
|---|
| 16 |
from trac.config import Option |
|---|
| 17 |
|
|---|
| 18 |
from api import IPasswordStore |
|---|
| 19 |
|
|---|
| 20 |
class HttpAuthStore(Component): |
|---|
| 21 |
implements(IPasswordStore) |
|---|
| 22 |
|
|---|
| 23 |
auth_url = Option('account-manager', 'authentication_url') |
|---|
| 24 |
|
|---|
| 25 |
def check_password(self, user, password): |
|---|
| 26 |
mgr = HTTPPasswordMgrWithDefaultRealm() |
|---|
| 27 |
mgr.add_password(None, self.auth_url, user, password) |
|---|
| 28 |
try: |
|---|
| 29 |
build_opener(HTTPBasicAuthHandler(mgr), |
|---|
| 30 |
HTTPDigestAuthHandler(mgr)).open(self.auth_url) |
|---|
| 31 |
except IOError: |
|---|
| 32 |
return False |
|---|
| 33 |
else: |
|---|
| 34 |
return True |
|---|