Catalyst-Plugin-Authentication
view release on metacpan or search on metacpan
lib/Catalyst/Authentication/Realm.pm view on Meta::CPAN
$self->setup_credential($app);
return $self;
}
sub setup_store {
my ($self, $app) = @_;
my $config = $self->config;
my $realmname = $self->name;
# use the Null store as a default - Don't complain if the realm class is being overridden,
# as the new realm may behave differently.
if( ! exists($config->{store}{class}) ) {
$config->{store}{class} = '+Catalyst::Authentication::Store::Null';
if (! exists($config->{class})) {
$app->log->debug( qq(No Store specified for realm "$realmname", using the Null store.) );
}
}
my $storeclass = $config->{'store'}{'class'};
## follow catalyst class naming - a + prefix means a fully qualified class, otherwise it's
## taken to mean C::P::A::Store::(specifiedclass)
$storeclass = String::RewritePrefix->rewrite({
'' => 'Catalyst::Authentication::Store::',
'+' => '',
}, $storeclass);
try {
Catalyst::Utils::ensure_class_loaded( $storeclass );
}
catch {
# If the file is missing, then try the old-style fallback,
# but re-throw anything else for the user to deal with.
die $_ unless /^Can't locate/;
$app->log->warn( qq(Store class "$storeclass" not found, trying deprecated ::Plugin:: style naming. ) );
my $origstoreclass = $storeclass;
$storeclass =~ s/Catalyst::Authentication/Catalyst::Plugin::Authentication/;
try { Catalyst::Utils::ensure_class_loaded( $storeclass ); }
catch {
# Likewise this croak is useful if the second exception is also "not found",
# but would be confusing if it's anything else.
die $_ unless /^Can't locate/;
Carp::croak "Unable to load store class, " . $origstoreclass . " OR " . $storeclass .
" in realm " . $self->name;
};
};
# BACKWARDS COMPATIBILITY - if the store class does not define find_user, we define it in terms
# of get_user and add it to the class. this is because the auth routines use find_user,
# and rely on it being present. (this avoids per-call checks)
if (!$storeclass->can('find_user')) {
no strict 'refs';
*{"${storeclass}::find_user"} = sub {
my ($self, $info) = @_;
my @rest = @{$info->{rest}} if exists($info->{rest});
$self->get_user($info->{id}, @rest);
};
}
## a little cruft to stay compatible with some poorly written stores / credentials
## we'll remove this soon.
if ($storeclass->can('new')) {
$self->store($storeclass->new($config->{'store'}, $app, $self));
}
else {
$app->log->error("THIS IS DEPRECATED: $storeclass has no new() method - Attempting to use uninstantiated");
$self->store($storeclass);
}
return;
}
sub setup_credential {
my ($self, $app) = @_;
my $config = $self->config;
# a little niceness - since most systems seem to use the password credential class,
# if no credential class is specified we use password.
$config->{credential}{class} ||= '+Catalyst::Authentication::Credential::Password';
my $credentialclass = $config->{'credential'}{'class'};
## follow catalyst class naming - a + prefix means a fully qualified class, otherwise it's
## taken to mean C::A::Credential::(specifiedclass)
$credentialclass = String::RewritePrefix->rewrite({
'' => 'Catalyst::Authentication::Credential::',
'+' => '',
}, $credentialclass);
# if we made it here - we have what we need to load the classes
### BACKWARDS COMPATIBILITY - DEPRECATION WARNING:
### we must eval the ensure_class_loaded - because we might need to try the old-style
### ::Plugin:: module naming if the standard method fails.
## Note to self - catch second exception and bitch in detail?
try {
Catalyst::Utils::ensure_class_loaded( $credentialclass );
}
catch {
# If the file is missing, then try the old-style fallback,
# but re-throw anything else for the user to deal with.
die $_ unless /^Can't locate/;
$app->log->warn( qq(Credential class "$credentialclass" not found, trying deprecated ::Plugin:: style naming. ) );
my $origcredentialclass = $credentialclass;
$credentialclass =~ s/Catalyst::Authentication/Catalyst::Plugin::Authentication/;
try { Catalyst::Utils::ensure_class_loaded( $credentialclass ); }
catch {
# Likewise this croak is useful if the second exception is also "not found",
# but would be confusing if it's anything else.
die $_ unless /^Can't locate/;
Carp::croak "Unable to load credential class, " . $origcredentialclass . " OR " . $credentialclass .
" in realm " . $self->name;
};
};
if ($credentialclass->can('new')) {
$self->credential($credentialclass->new($config->{'credential'}, $app, $self));
( run in 0.710 second using v1.01-cache-2.11-cpan-bbc515a03b3 )