use Tie::RefHash;
use Class::Inspector;
-use Catalyst::Plugin::Authentication::Realm;
+use Catalyst::Authentication::Realm;
# this optimization breaks under Template::Toolkit
# use user_exists instead
# constant->import(have_want => eval { require Want });
#}
-our $VERSION = "0.10003";
+our $VERSION = "0.10005";
sub set_authenticated {
my ( $c, $user, $realmname ) = @_;
}
if ( $c->isa("Catalyst::Plugin::Session")
- and $c->config->{authentication}{use_session}
+ and $c->config->{'Plugin::Authentication'}{'use_session'}
and $user->supports("session") )
{
$realm->save_user_in_session($c, $user);
if (
$c->isa("Catalyst::Plugin::Session")
- and $c->config->{authentication}{use_session}
+ and $c->config->{'Plugin::Authentication'}{'use_session'}
and $c->session_is_valid
) {
delete @{ $c->session }{qw/__user __user_realm/};
return unless
$c->isa("Catalyst::Plugin::Session")
- and $c->config->{authentication}{use_session}
+ and $c->config->{'Plugin::Authentication'}{'use_session'}
and $c->session_is_valid;
return $c->session->{__user};
## make classdata where it is used.
$app->mk_classdata( '_auth_realms' => {});
- my $cfg = $app->config->{'authentication'} ||= {};
+ my $cfg = $app->config->{'Plugin::Authentication'};
+ if (!defined($cfg)) {
+ if (exists($app->config->{'authentication'})) {
+ $cfg = $app->config->{'authentication'};
+ $app->config->{'Plugin::Authentication'} = $app->config->{'authentication'};
+ } else {
+ $cfg = {};
+ }
+ }
- $cfg->{use_session} = 1;
+ # old default was to force use_session on. This must remain for that
+ # reason - but if use_session is already in the config, we respect it's setting.
+ if (!exists($cfg->{'use_session'})) {
+ $cfg->{'use_session'} = 1;
+ }
if (exists($cfg->{'realms'})) {
foreach my $realm (keys %{$cfg->{'realms'}}) {
sub setup_auth_realm {
my ($app, $realmname, $config) = @_;
- my $realmclass = 'Catalyst::Plugin::Authentication::Realm';
- if (defined($config->{'class'})) {
- $realmclass = $config->{'class'};
- Catalyst::Utils::ensure_class_loaded( $realmclass );
+ my $realmclass = $config->{class};
+
+ if( !$realmclass ) {
+ $realmclass = 'Catalyst::Authentication::Realm';
+ } elsif ($realmclass !~ /^\+(.*)$/ ) {
+ $realmclass = "Catalyst::Authentication::Realm::${realmclass}";
+ } else {
+ $realmclass = $1;
}
+
+ Catalyst::Utils::ensure_class_loaded( $realmclass );
+
my $realm = $realmclass->new($realmname, $config, $app);
if ($realm) {
$app->auth_realms->{$realmname} = $realm;
my $realm = $self->get_auth_realm('default');
if (!$realm) {
- $realm = $self->setup_auth_realm('default', { class => "Catalyst::Plugin::Authentication::Realm::Compatibility" });
+ $realm = $self->setup_auth_realm('default', { class => 'Compatibility' });
}
if ( my $new = shift ) {
$realm->store($new);
Authentication
/;
- __PACKAGE__->config->{authentication} =
+ __PACKAGE__->config->{'Plugin::Authentication'} =
{
default_realm => 'members',
realms => {
user, it must have come from the realm specified.)
The above example is somewhat similar to role based access control.
-L<Catalyst::Plugin::Authentication::Store::Minimal> treats the roles field as
+L<Catalyst::Authentication::Store::Minimal> treats the roles field as
an array of role names. Let's leverage this. Add the role authorization
plugin:
You can accomplish this simply by installing the DBIx::Class Store and
changing your config:
- __PACKAGE__->config->{authentication} =
+ __PACKAGE__->config->{'Plugin::Authentication'} =
{
default_realm => 'members',
realms => {
=head1 CONFIGURATION
-=over 4
-
# example
- __PACKAGE__->config->{authentication} =
+ __PACKAGE__->config->{'Plugin::Authentication'} =
{
default_realm => 'members',
realms => {
}
};
+=over 4
+
=item use_session
Whether or not to store the user's logged in state in the session, if the
The only rule here is that there must be at least one. A realm consists of a
name, which is used to reference the realm, a credential and a store.
-You can also specify as realm class to instantiate instead of the default
-L<Catalyst::Plugin::Authentication::Realm> class.
+You can also specify a realm class to instantiate instead of the default
+L<Catalyst::Authentication::Realm> class using the 'class' element within the
+realm config.
Each realm config contains two hashes, one called 'credential' and one called
'store', each of which provide configuration details to the respective modules.
specification. If a class is prefixed with a +, it is assumed to be a complete
class name. Otherwise it is considered to be a portion of the class name. For
credentials, the classname 'B<Password>', for example, is expanded to
-Catalyst::Plugin::Authentication::Credential::B<Password>. For stores, the
+Catalyst::Authentication::Credential::B<Password>. For stores, the
classname 'B<storename>' is expanded to:
-Catalyst::Plugin::Authentication::Store::B<storename>.
+Catalyst::Authentication::Store::B<storename>.
=back
=head2 Realms
-L<Catalyst::Plugin::Authentication::Realm>
+L<Catalyst::Authentication::Realm>
=head2 User Storage Backends
-L<Catalyst::Plugin::Authentication::Store::Minimal>,
-L<Catalyst::Plugin::Authentication::Store::DBIx::Class>,
+L<Catalyst::Authentication::Store::Minimal>,
+L<Catalyst::Authentication::Store::DBIx::Class>,
=head2 Credential verification
-L<Catalyst::Plugin::Authentication::Credential::Password>,
+L<Catalyst::Authentication::Credential::Password>,
=head2 Authorization
Return the store whose name is 'default'.
-This is set to C<< $c->config->{authentication}{store} >> if that value exists,
+This is set to C<< $c->config->{'Plugin::Authentication'}{store} >> if that value exists,
or by using a Store plugin:
# load the Minimal authentication store.
Register stores into the application.
+=head2 auth_store_names( )
+
+=head2 get_user( )
+
+=head2 setup( )
+
+=head2 setup_auth_realm( )
+
=head1 AUTHORS
Yuval Kogman, C<nothingmuch@woobling.org>