| 107 | == Virtual Host Configuration, Multiple Projects and Pythonic Authentication == |
| 108 | |
| 109 | {{{ |
| 110 | <VirtualHost *> |
| 111 | ServerName projects.example.com |
| 112 | |
| 113 | <Directory /> |
| 114 | SetHandler mod_python |
| 115 | PythonHandler trac.web.modpython_frontend |
| 116 | PythonOption TracEnvParentDir .../tracs |
| 117 | PythonOption TracUriRoot / |
| 118 | </Directory> |
| 119 | |
| 120 | <LocationMatch "/[^/]+/login"> |
| 121 | AuthType Basic |
| 122 | AuthName "Projects Trac Server" |
| 123 | PythonAuthenHandler trac.projects |
| 124 | Require valid-user |
| 125 | </LocationMatch> |
| 126 | </VirtualHost> |
| 127 | }}} |
| 128 | |
| 129 | The `PythonAuthenHandler` introduces an object that will handle the actual authentication process, in this case `trac.projects` is the name of a module to import (and thus must be located somewhere in the Python load path). |
| 130 | In this example, I created `.../site-packages/trac/projects` that contains this little script called `__init__.py`: |
| 131 | |
| 132 | {{{ |
| 133 | from mod_python import apache |
| 134 | |
| 135 | def authenhandler(req): |
| 136 | pw = req.get_basic_auth_pw() |
| 137 | user = req.user |
| 138 | if user == "admin" and pw == "trac": |
| 139 | return apache.OK |
| 140 | else: |
| 141 | return apache.HTTP_UNAUTHORIZED |
| 142 | }}} |
| 143 | |
| 144 | that of course is just a sample. The name `authenhandler` comes from the default behaviour of mod_python, but you may specify a different one using the syntax `trac.projects::my_own_handler`. |
| 145 | |