Major modifications
[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 {
11 __PACKAGE__->mk_accessors(qw/auth_realm/);
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;
52 if ($object = $self->get_object && $object->can($field)) {
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.
71sub store {
72 my ($self) = @_;
73 return $self->auth_realm->{store};
74}
75
06675d2e 76__PACKAGE__;
77
78__END__
79
80=pod
81
82=head1 NAME
83
84Catalyst::Plugin::Authentication::User - Base class for user objects.
85
86=head1 SYNOPSIS
87
88 package MyStore::User;
89 use base qw/Catalyst::Plugin::Authentication::User/;
90
91=head1 DESCRIPTION
92
93This is the base class for authenticated
94
95=head1 METHODS
96
97=over 4
98
99=item id
100
101A unique ID by which a user can be retrieved from the store.
102
103=item store
104
105Should return a class name that can be used to refetch the user using it's
106ID.
107
108=item supports
109
110An introspection method used to determine what features a user object has, to support credential and authorization plugins.
111
112=item
113
114=back
115
116=cut
117
118