Commit | Line | Data |
5c5af345 |
1 | package Catalyst::Authentication::User; |
06675d2e |
2 | |
3 | use strict; |
4 | use warnings; |
45c7644b |
5 | use base qw/Class::Accessor::Fast/; |
06675d2e |
6 | |
45c7644b |
7 | ## auth_realm is the realm this user came from. |
8 | BEGIN { |
815ee585 |
9 | __PACKAGE__->mk_accessors(qw/auth_realm store/); |
45c7644b |
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. |
06675d2e |
14 | |
54c8dc06 |
15 | ## chances are you want to override this. |
16 | sub id { shift->get('id'); } |
17 | |
649de93b |
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. |
6c8b6e5e |
21 | sub supports { |
22 | my ( $self, @spec ) = @_; |
23 | |
649de93b |
24 | my $cursor = undef; |
25 | if ($self->can('supported_features')) { |
26 | $cursor = $self->supported_features; |
6c8b6e5e |
27 | |
649de93b |
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"; |
6c8b6e5e |
32 | |
649de93b |
33 | $cursor = $cursor->{$_}; |
34 | } |
35 | } |
6c8b6e5e |
36 | |
37 | return $cursor; |
38 | } |
06675d2e |
39 | |
54c8dc06 |
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. |
46 | sub get { |
47 | my ($self, $field) = @_; |
48 | |
49 | my $object; |
52eebd31 |
50 | if ($object = $self->get_object and $object->can($field)) { |
54c8dc06 |
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. |
63 | sub get_object { |
64 | return shift; |
65 | } |
66 | |
54c8dc06 |
67 | ## Backwards Compatibility |
68 | ## you probably want auth_realm, in fact. but this does work for backwards compatibility. |
815ee585 |
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 | ##} |
54c8dc06 |
74 | |
06675d2e |
75 | __PACKAGE__; |
76 | |
77 | __END__ |
78 | |
79 | =pod |
80 | |
81 | =head1 NAME |
82 | |
5c5af345 |
83 | Catalyst::Authentication::User - Base class for user objects. |
06675d2e |
84 | |
85 | =head1 SYNOPSIS |
86 | |
87 | package MyStore::User; |
5c5af345 |
88 | use base qw/Catalyst::Authentication::User/; |
06675d2e |
89 | |
90 | =head1 DESCRIPTION |
91 | |
92 | This is the base class for authenticated |
93 | |
94 | =head1 METHODS |
95 | |
5afc0dde |
96 | =head2 id( ) |
06675d2e |
97 | |
98 | A unique ID by which a user can be retrieved from the store. |
99 | |
5afc0dde |
100 | =head2 store( ) |
06675d2e |
101 | |
102 | Should return a class name that can be used to refetch the user using it's |
103 | ID. |
104 | |
5afc0dde |
105 | =head2 supports( ) |
06675d2e |
106 | |
107 | An introspection method used to determine what features a user object has, to support credential and authorization plugins. |
108 | |
078c2289 |
109 | =head2 get( ) |
110 | |
111 | =head2 get_object( ) |
112 | |
06675d2e |
113 | =cut |
114 | |