Lines 25-30
use C4::Context;
Link Here
|
25 |
use Authen::CAS::Client; |
25 |
use Authen::CAS::Client; |
26 |
use CGI; |
26 |
use CGI; |
27 |
use FindBin; |
27 |
use FindBin; |
|
|
28 |
use YAML; |
28 |
|
29 |
|
29 |
|
30 |
|
30 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug); |
31 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug); |
Lines 39-50
BEGIN {
Link Here
|
39 |
my $context = C4::Context->new() or die 'C4::Context->new failed'; |
40 |
my $context = C4::Context->new() or die 'C4::Context->new failed'; |
40 |
my $defaultcasserver; |
41 |
my $defaultcasserver; |
41 |
my $casservers; |
42 |
my $casservers; |
42 |
my $yamlauthfile = "../C4/Auth_cas_servers.yaml"; |
43 |
my $yamlauthfile = C4::Context->config('intranetdir') . "/C4/Auth_cas_servers.yaml"; |
43 |
|
44 |
|
44 |
|
45 |
|
45 |
# If there's a configuration for multiple cas servers, then we get it |
46 |
# If there's a configuration for multiple cas servers, then we get it |
46 |
if (multipleAuth()) { |
47 |
if (multipleAuth()) { |
47 |
($defaultcasserver, $casservers) = YAML::LoadFile(qq($FindBin::Bin/$yamlauthfile)); |
48 |
($defaultcasserver, $casservers) = YAML::LoadFile($yamlauthfile); |
48 |
$defaultcasserver = $defaultcasserver->{'default'}; |
49 |
$defaultcasserver = $defaultcasserver->{'default'}; |
49 |
} else { |
50 |
} else { |
50 |
# Else, we fall back to casServerUrl syspref |
51 |
# Else, we fall back to casServerUrl syspref |
Lines 54-60
if (multipleAuth()) {
Link Here
|
54 |
|
55 |
|
55 |
# Is there a configuration file for multiple cas servers? |
56 |
# Is there a configuration file for multiple cas servers? |
56 |
sub multipleAuth { |
57 |
sub multipleAuth { |
57 |
return (-e qq($FindBin::Bin/$yamlauthfile)); |
58 |
return (-e qq($yamlauthfile)); |
58 |
} |
59 |
} |
59 |
|
60 |
|
60 |
# Returns configured CAS servers' list if multiple authentication is enabled |
61 |
# Returns configured CAS servers' list if multiple authentication is enabled |
Lines 64-86
sub getMultipleAuth {
Link Here
|
64 |
|
65 |
|
65 |
# Logout from CAS |
66 |
# Logout from CAS |
66 |
sub logout_cas { |
67 |
sub logout_cas { |
67 |
my ($query) = @_; |
68 |
my ($query, $type) = @_; |
68 |
my ( $cas, $uri ) = _get_cas_and_service($query); |
69 |
my ( $cas, $uri ) = _get_cas_and_service($query, undef, $type); |
69 |
print $query->redirect( $cas->logout_url($uri)); |
70 |
print $query->redirect( $cas->logout_url($uri)); |
70 |
print $query->redirect( $cas->logout_url(url => $uri)); |
71 |
print $query->redirect( $cas->logout_url(url => $uri)); |
71 |
} |
72 |
} |
72 |
|
73 |
|
73 |
# Login to CAS |
74 |
# Login to CAS |
74 |
sub login_cas { |
75 |
sub login_cas { |
75 |
my ($query) = @_; |
76 |
my ($query, $type) = @_; |
76 |
my ( $cas, $uri ) = _get_cas_and_service($query); |
77 |
my ( $cas, $uri ) = _get_cas_and_service($query, undef, $type); |
77 |
print $query->redirect( $cas->login_url($uri)); |
78 |
print $query->redirect( $cas->login_url($uri)); |
78 |
} |
79 |
} |
79 |
|
80 |
|
80 |
# Returns CAS login URL with callback to the requesting URL |
81 |
# Returns CAS login URL with callback to the requesting URL |
81 |
sub login_cas_url { |
82 |
sub login_cas_url { |
82 |
my ( $query, $key ) = @_; |
83 |
my ( $query, $key, $type ) = @_; |
83 |
my ( $cas, $uri ) = _get_cas_and_service( $query, $key ); |
84 |
my ( $cas, $uri ) = _get_cas_and_service( $query, $key, $type ); |
84 |
return $cas->login_url($uri); |
85 |
return $cas->login_url($uri); |
85 |
} |
86 |
} |
86 |
|
87 |
|
Lines 88-96
sub login_cas_url {
Link Here
|
88 |
# In our case : is there a ticket, is it valid and does it match one of our users ? |
89 |
# In our case : is there a ticket, is it valid and does it match one of our users ? |
89 |
sub checkpw_cas { |
90 |
sub checkpw_cas { |
90 |
$debug and warn "checkpw_cas"; |
91 |
$debug and warn "checkpw_cas"; |
91 |
my ($dbh, $ticket, $query) = @_; |
92 |
my ($dbh, $ticket, $query, $type) = @_; |
92 |
my $retnumber; |
93 |
my $retnumber; |
93 |
my ( $cas, $uri ) = _get_cas_and_service($query); |
94 |
my ( $cas, $uri ) = _get_cas_and_service($query, undef, $type); |
94 |
|
95 |
|
95 |
# If we got a ticket |
96 |
# If we got a ticket |
96 |
if ($ticket) { |
97 |
if ($ticket) { |
Lines 136-144
sub checkpw_cas {
Link Here
|
136 |
# Proxy CAS auth |
137 |
# Proxy CAS auth |
137 |
sub check_api_auth_cas { |
138 |
sub check_api_auth_cas { |
138 |
$debug and warn "check_api_auth_cas"; |
139 |
$debug and warn "check_api_auth_cas"; |
139 |
my ($dbh, $PT, $query) = @_; |
140 |
my ($dbh, $PT, $query, $type) = @_; |
140 |
my $retnumber; |
141 |
my $retnumber; |
141 |
my ( $cas, $uri ) = _get_cas_and_service($query); |
142 |
my ( $cas, $uri ) = _get_cas_and_service($query, undef, $type); |
142 |
|
143 |
|
143 |
# If we have a Proxy Ticket |
144 |
# If we have a Proxy Ticket |
144 |
if ($PT) { |
145 |
if ($PT) { |
Lines 184-191
sub check_api_auth_cas {
Link Here
|
184 |
sub _get_cas_and_service { |
185 |
sub _get_cas_and_service { |
185 |
my $query = shift; |
186 |
my $query = shift; |
186 |
my $key = shift; # optional |
187 |
my $key = shift; # optional |
|
|
188 |
my $type = shift; |
187 |
|
189 |
|
188 |
my $uri = _url_with_get_params($query); |
190 |
my $uri = _url_with_get_params($query, $type); |
189 |
|
191 |
|
190 |
my $casparam = $defaultcasserver; |
192 |
my $casparam = $defaultcasserver; |
191 |
$casparam = $query->param('cas') if defined $query->param('cas'); |
193 |
$casparam = $query->param('cas') if defined $query->param('cas'); |
Lines 199-206
sub _get_cas_and_service {
Link Here
|
199 |
# This method replaces $query->url() which will give both GET and POST params |
201 |
# This method replaces $query->url() which will give both GET and POST params |
200 |
sub _url_with_get_params { |
202 |
sub _url_with_get_params { |
201 |
my $query = shift; |
203 |
my $query = shift; |
|
|
204 |
my $type = shift; |
205 |
|
206 |
my $uri_base_part = ($type eq 'opac') ? |
207 |
C4::Context->preference('OPACBaseURL') . $query->script_name(): |
208 |
C4::Context->preference('staffClientBaseURL'); |
202 |
|
209 |
|
203 |
my $uri_base_part = C4::Context->preference('OPACBaseURL') . $query->script_name(); |
|
|
204 |
my $uri_params_part = ''; |
210 |
my $uri_params_part = ''; |
205 |
foreach ( $query->url_param() ) { |
211 |
foreach ( $query->url_param() ) { |
206 |
# url_param() always returns parameters that were deleted by delete() |
212 |
# url_param() always returns parameters that were deleted by delete() |