User Tools

Site Tools


doc:appunti:linux:sa:libapache2-mod-python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
doc:appunti:linux:sa:libapache2-mod-python [2016/03/03 22:17] – created niccolodoc:appunti:linux:sa:libapache2-mod-python [2016/03/03 22:22] (current) – [Autenticazione con PythonAuthenHandler] niccolo
Line 4: Line 4:
  
 <file> <file>
-    <Location /> +<Location /> 
-        SetHandler mod_python +    SetHandler mod_python 
-        PythonPath "sys.path+['/etc/apache2/']" +    PythonPath "sys.path+['/etc/apache2/']" 
-        #PythonHandler mod_python.testhandler +    #PythonHandler mod_python.testhandler 
-        PythonHandler mptest +    PythonHandler mptest 
-        PythonDebug On +    PythonDebug On 
-    </Location>+</Location>
 </file> </file>
  
Line 27: Line 27:
     req.write("Hello World!")     req.write("Hello World!")
     return apache.OK     return apache.OK
 +</code>
 +
 +===== Autenticazione con PythonAuthenHandler =====
 +
 +Per delegare l'autenticazione Basic di Apache ad una procedura Python è possibile usare queste direttive:
 +
 +<file>
 +<Location /pippo>
 +    AuthType Basic
 +    AuthName "Protetto con Python"
 +    AuthUserFile /dev/null
 +    AuthBasicAuthoritative Off
 +    PythonAuthenHandler authpippo
 +    Require valid-user
 +</Location>
 +</file>
 +
 +L'autenticazione su file **AuthUserFile** viene dichiarata non autoritativa, si aggiunge un handler Python che deve essere soddisfatto. Nell'esempio verrà eseguito il file **''authpippo.py''** cercato nella sys.path. Ecco un esempio:
 +
 +<code python>
 +from mod_python import apache
 +
 +def authenhandler(req):
 +    pw = req.get_basic_auth_pw()
 +    user = req.user
 +    if user == "pippo" and pw == "pippo":
 +        return apache.OK
 +    else:
 +        return apache.HTTP_UNAUTHORIZED
 </code> </code>
doc/appunti/linux/sa/libapache2-mod-python.1457039837.txt.gz · Last modified: 2016/03/03 22:17 by niccolo