allow the realm to use session even if main auth module doesn't
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Authentication / User.pm
CommitLineData
e0499ed6 1package Catalyst::Authentication::User;
07e49bc7 2
3use strict;
4use warnings;
808fc188 5use base qw/Class::Accessor::Fast/;
07e49bc7 6
808fc188 7## auth_realm is the realm this user came from.
8BEGIN {
d0c5a54a 9 __PACKAGE__->mk_accessors(qw/auth_realm store/);
808fc188 10}
11
12## THIS IS NOT A COMPLETE CLASS! it is intended to provide base functionality only.
13## translation - it won't work if you try to use it directly.
07e49bc7 14
f869137d 15## chances are you want to override this.
16sub id { shift->get('id'); }
17
6229329e 18## this relies on 'supported_features' being implemented by the subclass..
19## but it is not an error if it is not. it just means you support nothing.
20## nihilist user objects are welcome here.
f1d5a035 21sub supports {
22 my ( $self, @spec ) = @_;
23
6229329e 24 my $cursor = undef;
25 if ($self->can('supported_features')) {
26 $cursor = $self->supported_features;
f1d5a035 27
6229329e 28 # traverse the feature list,
29 for (@spec) {
30 #die "bad feature spec: @spec" if ref($cursor) ne "HASH";
31 return if ref($cursor) ne "HASH";
f1d5a035 32
6229329e 33 $cursor = $cursor->{$_};
34 }
35 }
f1d5a035 36
37 return $cursor;
38}
07e49bc7 39
f869137d 40## REQUIRED.
41## get should return the value of the field specified as it's single argument from the underlying
42## user object. This is here to provide a simple, standard way of accessing individual elements of a user
43## object - ensuring no overlap between C::P::A::User methods and actual fieldnames.
44## this is not the most effecient method, since it uses introspection. If you have an underlying object
45## you most likely want to write this yourself.
46sub get {
47 my ($self, $field) = @_;
48
49 my $object;
502176fa 50 if ($object = $self->get_object and $object->can($field)) {
f869137d 51 return $object->$field();
52 } else {
53 return undef;
54 }
55}
56
57## REQUIRED.
58## get_object should return the underlying user object. This is for when more advanced uses of the
59## user is required. Modifications to the existing user, etc. Changes in the object returned
60## by this routine may not be reflected in the C::P::A::User object - if this is required, re-authenticating
61## the user is probably the best route to take.
62## note that it is perfectly acceptable to return $self in cases where there is no underlying object.
63sub get_object {
64 return shift;
65}
66
f869137d 67## Backwards Compatibility
68## you probably want auth_realm, in fact. but this does work for backwards compatibility.
d0c5a54a 69## store should be a read-write accessor - so it was moved to mk_accessors
70##sub store {
71## my ($self) = @_;
72## return $self->auth_realm->{store};
73##}
f869137d 74
07e49bc7 75__PACKAGE__;
76
77__END__
78
79=pod
80
81=head1 NAME
82
e0499ed6 83Catalyst::Authentication::User - Base class for user objects.
07e49bc7 84
85=head1 SYNOPSIS
86
87 package MyStore::User;
e0499ed6 88 use base qw/Catalyst::Authentication::User/;
07e49bc7 89
90=head1 DESCRIPTION
91
92This is the base class for authenticated
93
94=head1 METHODS
95
d2ca09b8 96=head2 id( )
07e49bc7 97
98A unique ID by which a user can be retrieved from the store.
99
d2ca09b8 100=head2 store( )
07e49bc7 101
102Should return a class name that can be used to refetch the user using it's
103ID.
104
d2ca09b8 105=head2 supports( )
07e49bc7 106
107An introspection method used to determine what features a user object has, to support credential and authorization plugins.
108
8bcf4f49 109=head2 get( )
110
111=head2 get_object( )
112
07e49bc7 113=cut
114