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