This file is indexed.

/usr/share/perl5/Catalyst/Authentication/Store/DBIx/Class/User.pm is in libcatalyst-authentication-store-dbix-class-perl 0.1506-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
package Catalyst::Authentication::Store::DBIx::Class::User;

use Moose;
use namespace::autoclean;
extends 'Catalyst::Authentication::User';

use List::MoreUtils 'all';
use Try::Tiny;

has 'config'    => (is => 'rw');
has 'resultset' => (is => 'rw');
has '_user'     => (is => 'rw');
has '_roles'    => (is => 'rw');

sub new {
    my ( $class, $config, $c) = @_;

	$config->{user_model} = $config->{user_class}
        unless defined $config->{user_model};

    my $self = {
        resultset => $c->model($config->{'user_model'}),
        config => $config,
        _roles => undef,
        _user => undef
    };

    bless $self, $class;

    Catalyst::Exception->throw(
        "\$c->model('${ \$self->config->{user_model} }') did not return a resultset."
          . " Did you set user_model correctly?"
    ) unless $self->{resultset};

    $self->config->{'id_field'} = [$self->{'resultset'}->result_source->primary_columns]
        unless exists $self->config->{'id_field'};

    $self->config->{'id_field'} = [$self->config->{'id_field'}]
        unless ref $self->config->{'id_field'} eq 'ARRAY';

    Catalyst::Exception->throw(
        "id_field set to "
          . join(q{,} => @{ $self->config->{'id_field'} })
          . " but user table has no column by that name!"
    ) unless all { $self->{'resultset'}->result_source->has_column($_) } @{ $self->config->{'id_field'} };

    ## if we have lazyloading turned on - we should not query the DB unless something gets read.
    ## that's the idea anyway - still have to work out how to manage that - so for now we always force
    ## lazyload to off.
    $self->config->{lazyload} = 0;

#    if (!$self->config->{lazyload}) {
#        return $self->load_user($authinfo, $c);
#    } else {
#        ## what do we do with a lazyload?
#        ## presumably this is coming out of session storage.
#        ## use $authinfo to fill in the user in that case?
#    }

    return $self;
}


sub load {
    my ($self, $authinfo, $c) = @_;

    my $dbix_class_config = 0;

    if (exists($authinfo->{'dbix_class'})) {
        $authinfo = $authinfo->{'dbix_class'};
        $dbix_class_config = 1;
    }

    ## User can provide an arrayref containing the arguments to search on the user class.
    ## or even provide a prepared resultset, allowing maximum flexibility for user retrieval.
    ## these options are only available when using the dbix_class authinfo hash.
    if ($dbix_class_config && exists($authinfo->{'result'})) {
	$self->_user($authinfo->{'result'});
    } elsif ($dbix_class_config && exists($authinfo->{'resultset'})) {
        $self->_user($authinfo->{'resultset'}->first);
    } elsif ($dbix_class_config && exists($authinfo->{'searchargs'})) {
        $self->_user($self->resultset->search(@{$authinfo->{'searchargs'}})->first);
    } else {
        ## merge the ignore fields array into a hash - so we can do an easy check while building the query
        my %ignorefields = map { $_ => 1} @{$self->config->{'ignore_fields_in_find'}};
        my $searchargs = {};

        # now we walk all the fields passed in, and build up a search hash.
        foreach my $key (grep {!$ignorefields{$_}} keys %{$authinfo}) {
            if ($self->resultset->result_source->has_column($key)) {
                $searchargs->{$key} = $authinfo->{$key};
            }
        }
        if (keys %{$searchargs}) {
            $self->_user($self->resultset->search($searchargs)->first);
        } else {
            Catalyst::Exception->throw(
                "Failed to load user data.  You passed [" . join(',', keys %{$authinfo}) . "]"
                  . " to authenticate() but your user source (" .  $self->config->{'user_model'} . ")"
                  . " only has these columns: [" . join( ",", $self->resultset->result_source->columns ) . "]"
                  . "   Check your authenticate() call."
            );
        }
    }

    if ($self->get_object) {
        return $self;
    } else {
        return undef;
    }

}

sub supported_features {
    my $self = shift;

    return {
        session         => 1,
        roles           => 1,
    };
}


sub roles {
    my ( $self ) = shift;
    ## this used to load @wantedroles - but that doesn't seem to be used by the roles plugin, so I dropped it.

    ## shortcut if we have already retrieved them
    if (ref $self->_roles eq 'ARRAY') {
        return(@{$self->_roles});
    }

    my @roles = ();
    if (exists($self->config->{'role_column'})) {
        my $role_data = $self->get($self->config->{'role_column'});
        if ($role_data) {
            @roles = split /[\s,\|]+/, $self->get($self->config->{'role_column'});
        }
        $self->_roles(\@roles);
    } elsif (exists($self->config->{'role_relation'})) {
        my $relation = $self->config->{'role_relation'};
        if ($self->_user->$relation->result_source->has_column($self->config->{'role_field'})) {
            @roles = map {
                $_->get_column($self->config->{role_field})
            } $self->_user->$relation->search(undef, {
                columns => [ $self->config->{role_field} ]
            })->all;
            $self->_roles(\@roles);
        } else {
            Catalyst::Exception->throw("role table does not have a column called " . $self->config->{'role_field'});
        }
    } else {
        Catalyst::Exception->throw("user->roles accessed, but no role configuration found");
    }

    return @{$self->_roles};
}

sub for_session {
    my $self = shift;

    #return $self->get($self->config->{'id_field'});

    #my $frozenuser = $self->_user->result_source->schema->freeze( $self->_user );
    #return $frozenuser;

    my %userdata = $self->_user->get_columns();

    # If use_userdata_from_session is set, then store all of the columns of the user obj in the session
    if (exists($self->config->{'use_userdata_from_session'}) && $self->config->{'use_userdata_from_session'} != 0) {
        return \%userdata;
    } else { # Otherwise, we just need the PKs for load() to use.
        my %pk_fields = map { ($_ => $userdata{$_}) } @{ $self->config->{id_field} };
        return \%pk_fields;
    }
}

sub from_session {
    my ($self, $frozenuser, $c) = @_;

    #my $obj = $self->resultset->result_source->schema->thaw( $frozenuser );
    #$self->_user($obj);

    #if (!exists($self->config->{'use_userdata_from_session'}) || $self->config->{'use_userdata_from_session'} == 0) {
#        $self->_user->discard_changes();
#    }
#
#    return $self;
#
## if use_userdata_from_session is defined in the config, we fill in the user data from the session.
    if (exists($self->config->{'use_userdata_from_session'}) && $self->config->{'use_userdata_from_session'} != 0) {

        # We need to use inflate_result here since we -are- inflating a
        # result object from cached data, not creating a fresh one.
        # Components such as EncodedColumn wrap new() to ensure that a
        # provided password is hashed on the way in, and re-running the
        # hash function on data being restored is expensive and incorrect.

        my $class = $self->resultset->result_class;
        my $source = $self->resultset->result_source;
        my $obj = $class->inflate_result($source, { %$frozenuser });

        $obj->in_storage(1);
        $self->_user($obj);
        return $self;
    }

    if (ref $frozenuser eq 'HASH') {
        return $self->load({
            map { ($_ => $frozenuser->{$_}) }
            @{ $self->config->{id_field} }
        }, $c);
    }

    return $self->load( { $self->config->{'id_field'} => $frozenuser }, $c);
}

sub get {
    my ($self, $field) = @_;

    if (my $code = $self->_user->can($field)) {
        return $self->_user->$code;
    }
    elsif (my $accessor =
         try { $self->_user->result_source->column_info($field)->{accessor} }) {
        return $self->_user->$accessor;
    } else {
        # XXX this should probably throw
        return undef;
    }
}

sub get_object {
    my ($self, $force) = @_;

    if ($force) {
        $self->_user->discard_changes;
    }

    return $self->_user;
}

sub obj {
    my ($self, $force) = @_;

    return $self->get_object($force);
}

sub auto_create {
    my $self = shift;
    $self->_user( $self->resultset->auto_create( @_ ) );
    return $self;
}

sub auto_update {
    my $self = shift;
    $self->_user->auto_update( @_ );
}

sub can {
    my $self = shift;
    return $self->SUPER::can(@_) || do {
        my ($method) = @_;
        if (not ref $self) {
            undef;
        } elsif (not $self->_user) {
            undef;
        } elsif (my $code = $self->_user->can($method)) {
            sub { shift->_user->$code(@_) }
        } elsif (my $accessor =
            try { $self->_user->result_source->column_info($method)->{accessor} }) {
            sub { shift->_user->$accessor }
        } else {
            undef;
        }
    };
}

sub AUTOLOAD {
    my $self = shift;
    (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
    return if $method eq "DESTROY";

    return unless ref $self;

    if (my $code = $self->_user->can($method)) {
        return $self->_user->$code(@_);
    }
    elsif (my $accessor =
         try { $self->_user->result_source->column_info($method)->{accessor} }) {
        return $self->_user->$accessor(@_);
    } else {
        # XXX this should also throw
        return undef;
    }
}

__PACKAGE__->meta->make_immutable(inline_constructor => 0);

1;
__END__

=head1 NAME

Catalyst::Authentication::Store::DBIx::Class::User - The backing user
class for the Catalyst::Authentication::Store::DBIx::Class storage
module.

=head1 VERSION

This documentation refers to version 0.1506.

=head1 SYNOPSIS

Internal - not used directly, please see
L<Catalyst::Authentication::Store::DBIx::Class> for details on how to
use this module. If you need more information than is present there, read the
source.



=head1 DESCRIPTION

The Catalyst::Authentication::Store::DBIx::Class::User class implements user storage
connected to an underlying DBIx::Class schema object.

=head1 SUBROUTINES / METHODS

=head2 new

Constructor.

=head2 load ( $authinfo, $c )

Retrieves a user from storage using the information provided in $authinfo.

=head2 supported_features

Indicates the features supported by this class.  These are currently Roles and Session.

=head2 roles

Returns an array of roles associated with this user, if roles are configured for this user class.

=head2 for_session

Returns a serialized user for storage in the session.

=head2 from_session

Revives a serialized user from storage in the session.

=head2 get ( $fieldname )

Returns the value of $fieldname for the user in question.  Roughly translates to a call to
the DBIx::Class::Row's get_column( $fieldname ) routine.

=head2 get_object

Retrieves the DBIx::Class object that corresponds to this user

=head2 obj (method)

Synonym for get_object

=head2 auto_create

This is called when the auto_create_user option is turned on in
Catalyst::Plugin::Authentication and a user matching the authinfo provided is not found.
By default, this will call the C<auto_create()> method of the resultset associated
with this object. It is up to you to implement that method.

=head2 auto_update

This is called when the auto_update_user option is turned on in
Catalyst::Plugin::Authentication. Note that by default the DBIx::Class store
uses every field in the authinfo hash to match the user. This means any
information you provide with the intent to update must be ignored during the
user search process. Otherwise the information will most likely cause the user
record to not be found. To ignore fields in the search process, you
have to add the fields you wish to update to the 'ignore_fields_in_find'
authinfo element.  Alternately, you can use one of the advanced row retrieval
methods (searchargs or resultset).

By default, auto_update will call the C<auto_update()> method of the
DBIx::Class::Row object associated with the user. It is up to you to implement
that method (probably in your schema file)

=head2 AUTOLOAD

Delegates method calls to the underlying user row.

=head2 can

Delegates handling of the C<< can >> method to the underlying user row.

=head1 BUGS AND LIMITATIONS

None known currently, please email the author if you find any.

=head1 AUTHOR

Jason Kuri (jayk@cpan.org)

=head1 CONTRIBUTORS

Matt S Trout (mst) <mst@shadowcat.co.uk>

(fixes wrt can/AUTOLOAD sponsored by L<http://reask.com/>)

=head1 LICENSE

Copyright (c) 2007-2010 the aforementioned authors. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

=cut