3 package Catalyst::Plugin::Authentication;
5 use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
8 __PACKAGE__->mk_accessors(qw/user/);
9 __PACKAGE__->mk_classdata(qw/default_auth_store/);
15 sub set_authenticated {
16 my ( $c, $user ) = @_;
20 if ( $c->isa("Catalyst::Plugin::Session")
21 and $c->config->{authentication}{use_session} )
23 $c->session->{__user} = $user->for_session
24 if $user->supperts("session");
25 $c->session->{__user_class} = ref $user;
34 if ( $c->isa("Catalyst::Plugin::Session")
35 and $c->config->{authentication}{use_session} )
37 delete @{ $c->session }{qw/__user __user_class/};
44 if ( my $store = $c->default_auth_store ) {
45 return $store->get_user($uid);
48 Catalyst::Exception->throw(
49 "The user id $uid was passed to an authentication "
50 . "plugin, but no default store was specified" );
55 my $c = shift->NEXT::prepare(@_);
57 if ( $c->isa("Catalyst::Plugin::Session")
58 and $c->config->{authentication}{use_session}
61 if ( $c->sessionid and my $user = $c->session->{__user} ) {
62 $c->user( $c->session->{__user_class}->from_session( $c, $user ) );
72 my $cfg = $c->config->{authentication};
90 Catalyst::Plugin::Authentication -
96 Authentication::Store::Foo
97 Authentication::Credential::Password
102 The authentication plugin is used by the various authentication and
103 authorization plugins in catalyst.
105 It defines the notion of a logged in user, and provides integration with the
113 Delete the currently logged in user from C<user> and the session.
117 Returns the currently logged user or undef if there is none.
121 Delegate C<get_user> to the default store.
123 =item default_auth_store
125 Returns C<< $c->config->{authentication}{store} >>.
129 =head1 INTERNAL METHODS
133 =item set_authenticated $user
135 Marks a user as authenticated. Should be called from a
136 C<Catalyst::Plugin::Authentication::Credential> plugin after successful
139 This involves setting C<user> and the internal data in C<session> if
140 L<Catalyst::Plugin::Session> is loaded.
144 Revives a user from the session object if there is one.
148 Sets the default configuration parameters.
160 Whether or not to store the user's logged in state in the session, if the
161 application is also using the L<Catalyst::Plugin::Authentication> plugin.