104 | | == Virtual Host Configuration, Multiple Projects and Pythonic Authentication == |
105 | | |
106 | | {{{ |
107 | | <VirtualHost *> |
108 | | ServerName projects.example.com |
109 | | |
110 | | <Directory /> |
111 | | SetHandler mod_python |
112 | | PythonHandler trac.web.modpython_frontend |
113 | | PythonOption TracEnvParentDir .../tracs |
114 | | PythonOption TracUriRoot / |
115 | | </Directory> |
116 | | |
117 | | <LocationMatch "/[^/]+/login"> |
118 | | AuthType Basic |
119 | | AuthName "Projects Trac Server" |
120 | | PythonAuthenHandler trac.projects |
121 | | Require valid-user |
122 | | </LocationMatch> |
123 | | </VirtualHost> |
124 | | }}} |
125 | | |
126 | | 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). |
127 | | In this example, I created `.../site-packages/trac/projects` that contains this little script called `__init__.py`: |
128 | | |
129 | | {{{ |
130 | | from mod_python import apache |
131 | | |
132 | | def authenhandler(req): |
133 | | pw = req.get_basic_auth_pw() |
134 | | user = req.user |
135 | | if user == "admin" and pw == "trac": |
136 | | return apache.OK |
137 | | else: |
138 | | return apache.HTTP_UNAUTHORIZED |
139 | | }}} |
140 | | |
141 | | 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`. |
142 | | |