Commit | Line | Data |
06675d2e |
1 | #!/usr/bin/perl |
2 | |
3 | package Catalyst::Plugin::Authentication::User; |
4 | |
5 | use strict; |
6 | use warnings; |
7 | |
06675d2e |
8 | |
54c8dc06 |
9 | ## chances are you want to override this. |
10 | sub id { shift->get('id'); } |
11 | |
12 | ## returns the realm the user came from - not a good idea to override this. |
13 | sub auth_realm { |
14 | my $self = shift; |
15 | $self->{'realm'}; |
16 | } |
17 | |
18 | |
06675d2e |
19 | |
6c8b6e5e |
20 | sub supports { |
21 | my ( $self, @spec ) = @_; |
22 | |
23 | my $cursor = $self->supported_features; |
24 | |
25 | # traverse the feature list, |
26 | for (@spec) { |
14f98cb2 |
27 | #die "bad feature spec: @spec" if ref($cursor) ne "HASH"; |
28 | return if ref($cursor) ne "HASH"; |
6c8b6e5e |
29 | |
30 | $cursor = $cursor->{$_}; |
31 | } |
32 | |
33 | return $cursor; |
34 | } |
06675d2e |
35 | |
54c8dc06 |
36 | ## REQUIRED. |
37 | ## get should return the value of the field specified as it's single argument from the underlying |
38 | ## user object. This is here to provide a simple, standard way of accessing individual elements of a user |
39 | ## object - ensuring no overlap between C::P::A::User methods and actual fieldnames. |
40 | ## this is not the most effecient method, since it uses introspection. If you have an underlying object |
41 | ## you most likely want to write this yourself. |
42 | sub get { |
43 | my ($self, $field) = @_; |
44 | |
45 | my $object; |
46 | if ($object = $self->get_object && $object->can($field)) { |
47 | return $object->$field(); |
48 | } else { |
49 | return undef; |
50 | } |
51 | } |
52 | |
53 | ## REQUIRED. |
54 | ## get_object should return the underlying user object. This is for when more advanced uses of the |
55 | ## user is required. Modifications to the existing user, etc. Changes in the object returned |
56 | ## by this routine may not be reflected in the C::P::A::User object - if this is required, re-authenticating |
57 | ## the user is probably the best route to take. |
58 | ## note that it is perfectly acceptable to return $self in cases where there is no underlying object. |
59 | sub get_object { |
60 | return shift; |
61 | } |
62 | |
63 | ## this is an internal routine. I suggest you don't rely on it's presence. |
64 | ## sets the realm the user came from. |
65 | sub _set_auth_realm { |
66 | my ($self, $realmname) = @_; |
67 | $self->{'realm'} = $realmname; |
68 | } |
69 | |
70 | ## Backwards Compatibility |
71 | ## you probably want auth_realm, in fact. but this does work for backwards compatibility. |
72 | sub store { |
73 | my ($self) = @_; |
74 | return $self->auth_realm->{store}; |
75 | } |
76 | |
06675d2e |
77 | __PACKAGE__; |
78 | |
79 | __END__ |
80 | |
81 | =pod |
82 | |
83 | =head1 NAME |
84 | |
85 | Catalyst::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 | |
94 | This is the base class for authenticated |
95 | |
96 | =head1 METHODS |
97 | |
98 | =over 4 |
99 | |
100 | =item id |
101 | |
102 | A unique ID by which a user can be retrieved from the store. |
103 | |
104 | =item store |
105 | |
106 | Should return a class name that can be used to refetch the user using it's |
107 | ID. |
108 | |
109 | =item supports |
110 | |
111 | An 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 | |