Catalyst-Plugin-Authentication
view release on metacpan or search on metacpan
lib/Catalyst/Authentication/Realm.pm view on Meta::CPAN
package Catalyst::Authentication::Realm;
use Moose;
use namespace::autoclean;
with 'MooseX::Emulate::Class::Accessor::Fast';
use String::RewritePrefix;
use Try::Tiny qw/ try catch /;
__PACKAGE__->mk_accessors(qw/store credential name config/);
## Add use_session config item to realm.
sub new {
my ($class, $realmname, $config, $app) = @_;
my $self = { config => $config };
bless $self, $class;
$self->name($realmname);
if (!exists($self->config->{'use_session'})) {
if (exists($app->config->{'Plugin::Authentication'}{'use_session'})) {
$self->config->{'use_session'} = $app->config->{'Plugin::Authentication'}{'use_session'};
} else {
$self->config->{'use_session'} = 1;
}
}
$app->log->debug("Setting up auth realm $realmname") if $app->debug;
# 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);
# 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?
( run in 2.759 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )