Weird Problems when using a Class::DBI subclass together with Apache::AuthCookie

[prev] [thread] [next] [Date index for 2004/08/21]

From: Sebastian Willert
Subject: Weird Problems when using a Class::DBI subclass together with Apache::AuthCookie
Date: 19:09 on 21 Aug 2004
Hi,

I've been struggling all day with a very strange phenomenon when using
Class::DBI in conjunction with mod_perl and Apache::AuthCookie.

I've included the relevant portions of my modules below, I hope it is
easier to understand what I am talking about this way.

The framework is quite simple: My::User is a Class::DBI object that is
used to identify an user from within a website. Now I thought I could
easily use this class from within Apache::AuthCookie for authentication,
but this lead to disaster: My::User got pulled in at server startup
through My::AuthCookieHandler and initializes its class data. Nothig bad
so far, My::User seems to keep working, but when My:AuthHandler tries to
use it (either through retrieve or retrieve_with_creds), the whole
process stalls and eats up 100% CPU.

I've found a temporary workaround for this: when I let My::AuthHandler
pull in My::User via require, right before I use it within the auth*
methods, everything seems to work okay. Needless to say that I am quite
unhappy with this solution...

Does this behavior ring some bells? Does anyone know whats happening
here and if there are any better solutions than mine?

I hope this description is sufficient for now. If anybody has further
questions I'd happily build a test case out of this, but deadlines are
lurking and I already have lost a day due to this :(

Regards,
  Sebastian 

---

package My::User;
use base qw(Class::DBI::mysql);

BEGIN {
  __PACKAGE__->set_up_table( 'Users' );
  __PACKAGE__->add_constructor
	 ( retrieve_with_creds => 'UserID = ? AND Password = password(?)')
		unless UNIVERSAL::can( __PACKAGE__, qw(retrieve_with_creds) );
}

package My::AuthCookieHandler;
use My::User;
use base qw(Apache::AuthCookie);

sub authen_cred ($$\@) {
  my ($self, $r, @creds) = @_;
  my $user = Slimnet::User->retrieve_with_creds( @creds );
  return $user ? join(":", @creds) : undef;
}

sub authen_ses_key ($$$) {
  my $self = shift;
  my $r = shift;
  my ( $user ) = Slimnet::User->retrieve_with_creds( split(/:/, shift,
2) );
  return $user ? $user->id : undef;
}

__DATA__

# Apache vhost config

PerlModule My::AuthCookieHandler

PerlSetVar MyAuthPath /
PerlSetVar MyAuthLoginScript /login.html

SetHandler perl-script
DefaultType text/html

PerlHandler My::Handler

AuthType My::AuthCookieHandler
AuthName MyAuth
PerlAuthenHandler My::AuthCookieHandler->authenticate
PerlAuthzHandler My::AuthCookieHandler->authorize
Require valid-user

<Files login>
  SetHandler perl-script
  AuthType My::AuthCookieHandler
  AuthName MyAuth
  PerlHandler My::AuthCookieHandler->login
</Files>


Weird Problems when using a Class::DBI subclass together with Apache::AuthCookie
Sebastian Willert 19:09 on 21 Aug 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52