Authen-CAS-UserAgent

 view release on metacpan or  search on metacpan

lib/Authen/CAS/UserAgent.pm  view on Meta::CPAN

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
=cut
 
#method that will attach the cas server login handler
#       server            => the base CAS server uri to add a login handler for
#       username          => the username to use to login to the specified CAS server
#       password          => the password to use to login to the specified CAS server
#       pgt               => the pgt for a proxy login handler
#       proxy             => a boolean indicating this handler is a proxy login handler
#       restful           => a boolean indicating if the CAS server supports the RESTful API
#       callback          => a login callback to use for logging into CAS, it should return a ticket for the specified service
#       ticket_heuristics => an array of heuristic callbacks that are performed when searching for the service and ticket in a CAS response
#       strict            => only allow CAS login when the service is the same as the original url
sub attach_cas_handler($%) {
        my $self = shift;
        my (%opt) = @_;
 
        #short-circuit if required options aren't specified
        return if(!exists $opt{'server'});
        return if(!$opt{'proxy'} && !(exists $opt{'username'} && exists $opt{'password'}));
        return if($opt{'proxy'} && !$opt{'pgt'});
 
        #sanitize options
        $opt{'server'} = URI->new($opt{'server'} . ($opt{'server'} =~ /\/$/o ? '' : '/'))->canonical;
        my $callback =
                ref($opt{'callback'}) eq 'CODE' ? $opt{'callback'}    :
                $opt{'proxy'}                   ? $proxyLoginCallback :
                $opt{'restful'}                 ? $restLoginCallback  :
                $defaultLoginCallback;
 
        # process any default config values for bundled callbacks/heuristics, we do this here
        # instead of in the callbacks to make default values available to custom
        # callbacks
        $opt{'ticket_heuristics'} = [$opt{'ticket_heuristics'}] if(ref($opt{'ticket_heuristics'}) ne 'ARRAY');
        push @{$opt{'ticket_heuristics'}}, $defaultTicketHeuristic;
        @{$opt{'ticket_heuristics'}} = grep {ref($_) eq 'CODE'} @{$opt{'ticket_heuristics'}};
 
        $opt{'param_heuristics'} = [$opt{'param_heuristics'}] if(ref($opt{'param_heuristics'}) ne 'ARRAY');
        push @{$opt{'param_heuristics'}}, $defaultLoginParamsHeuristic;
        @{$opt{'param_heuristics'}} = grep {ref($_) eq 'CODE'} @{$opt{'param_heuristics'}};
 
        #remove any pre-existing login handler for the current CAS server
        $self->remove_cas_handlers($opt{'server'});



( run in 0.334 second using v1.01-cache-2.11-cpan-bf8d7bb2d05 )