[Zope] Re: Zope User in Apache Logs
Chris Withers
chris at simplistix.co.uk
Thu May 18 03:21:12 EDT 2006
Josef Meile wrote:
>> > If your Zope auth solution can put a header in the http response,
>> then > you can use a custom apache logging directive to put this in your
>> > Apache log in place of what it thinks the username is.
>> I put this on the "log" method of the medusa/http_server.py file:
>> self.response.setHeader('remote_user',name)
As you've found out, this is the wrong level to do this ;-)
>> and set my apache access log like this:
>> CustomLog /home/apache/httpd/logs/access_log combined
>>
>> The combined log is defined as follows:
>> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
>> \"%{User-Agent}i\"" combined
>>
>> There you see the %l and %u directives, which are the "Remote logname"
>> and the "Remote user".
Yeah, these aren't the ones you want to be using ;-)
>> But apache still doesn't get the zope authenticated user. So, Chris,
>> do you remember what header you set, where, and which method you used?
> Ok, Answering to this question. I guess I had to set the header inside the
> authenticate method of the BasicUserFolder class. Here is what I did:
>
> def authenticate(self, name, password, request):
> emergency = self._emergency_user
> user = None
> if name is None:
> pass
> else:
> if emergency and name==emergency.getUserName():
> user = emergency
> else:
> user = self.getUser(name)
> if user is not None and user.authenticate(password, request):
> pass
> else:
> user = None
> logUser = 'Anonymous'
> if (user != None):
> logUser = user.getUserName()
> request.response.setHeader('remote-user',logUser)
Well, I wouldn't use that header, try using X-MyUserName instead, and
then in the apache config you'd use %{X-MyUserName}o
hth,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope
mailing list