mod_python, user missing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KasiKuula

    mod_python, user missing

    apache conf
    <Directory /python-publisher/>
    SetHandler mod_python
    PythonHandler mod_python.publ isher
    </Directory>


    and this is in /python-publisher/index.py

    __auth_realm__ = 'VIP'

    def __auth__(req, user, passwd):
    if user == 'noppa' and passwd == 'potti':
    return True
    else:
    return False

    def __access__(req, user):
    if user == 'noppa':
    return True
    else:
    return False

    def index(req):
    req.get_basic_a uth_pw()
    user = req.user
    return 'user is %s' % (user)


    So problem is, how I get user in index function? That gives allways "None"

    --
    (8)
  • grahamd@dscpl.com.au

    #2
    Re: mod_python, user missing

    Good question, according to the documentation it should work, I'll
    push this onto the mod_python mailing list for discussion and get a
    bug report posted if necessary.

    In the meantime, you could use the following work around:

    def __auth__(req, user, passwd):
    req.user = user
    if user == 'noppa' and passwd == 'potti':
    return True
    else:
    return False

    Ie., explicitly set "req.user" in the __auth__ method.

    Comment

    • grahamd@dscpl.com.au

      #3
      Re: mod_python, user missing

      Okay, reason it doesn't work is that req.get_basic_a uth_pw() only
      applies when using Apache itself to perform the user authentication.
      Ie., where in Apache configuration files you have something like:

      AuthType Basic
      AuthName "VIP"
      AuthUserFile /tmp/pwdb
      Require user noppa

      It doesn't work when using mod_python.publ isher style authentication
      as that is done in mod_python and not by Apache. Thus, you would
      need to assign to req.user in the __auth__ method as I described to
      have it so it is accessible in the published method. You will not need
      to call the req.get_basic_a uth_pw() function.

      Comment

      • KasiKuula

        #4
        Re: mod_python, user missing

        So damn simple that i am embarrassed :D
        Now my news get added with user.
        Thanks :)

        --
        (8)


        grahamd@dscpl.c om.au wrote:
        [color=blue]
        > Good question, according to the documentation it should work, I'll
        > push this onto the mod_python mailing list for discussion and get a
        > bug report posted if necessary.
        >
        > In the meantime, you could use the following work around:
        >
        > def __auth__(req, user, passwd):
        > req.user = user
        > if user == 'noppa' and passwd == 'potti':
        > return True
        > else:
        > return False
        >
        > Ie., explicitly set "req.user" in the __auth__ method.
        >[/color]

        Comment

        Working...