|
Lines 40-50
BEGIN {
Link Here
|
| 40 |
my $context = C4::Context->new() or die 'C4::Context->new failed'; |
40 |
my $context = C4::Context->new() or die 'C4::Context->new failed'; |
| 41 |
my $defaultcasserver; |
41 |
my $defaultcasserver; |
| 42 |
my $casservers; |
42 |
my $casservers; |
|
|
43 |
my $yamlauthfile = "../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 (-e qq($FindBin::Bin/../C4/Auth_cas_servers.yaml)) { |
47 |
if (multipleAuth()) { |
| 47 |
($defaultcasserver, $casservers) = YAML::LoadFile(qq($FindBin::Bin/../C4/Auth_cas_servers.yaml)); |
48 |
($defaultcasserver, $casservers) = YAML::LoadFile(qq($FindBin::Bin/$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 52-57
if (-e qq($FindBin::Bin/../C4/Auth_cas_servers.yaml)) {
Link Here
|
| 52 |
$casservers = { 'default' => C4::Context->preference('casServerUrl') }; |
53 |
$casservers = { 'default' => C4::Context->preference('casServerUrl') }; |
| 53 |
} |
54 |
} |
| 54 |
|
55 |
|
|
|
56 |
# Is there a configuration file for multiple cas servers? |
| 57 |
sub multipleAuth { |
| 58 |
return (-e qq($FindBin::Bin/$yamlauthfile)); |
| 59 |
} |
| 60 |
|
| 61 |
# Returns configured CAS servers' list if multiple authentication is enabled |
| 62 |
sub getMultipleAuth { |
| 63 |
return $casservers; |
| 64 |
} |
| 65 |
|
| 55 |
# Logout from CAS |
66 |
# Logout from CAS |
| 56 |
sub logout_cas { |
67 |
sub logout_cas { |
| 57 |
my ($query) = @_; |
68 |
my ($query) = @_; |
|
Lines 71-77
sub login_cas {
Link Here
|
| 71 |
my $casparam = $query->param('cas'); |
82 |
my $casparam = $query->param('cas'); |
| 72 |
# FIXME: This should be more generic and handle whatever parameters there might be |
83 |
# FIXME: This should be more generic and handle whatever parameters there might be |
| 73 |
$uri .= "?cas=" . $casparam if (defined $casparam); |
84 |
$uri .= "?cas=" . $casparam if (defined $casparam); |
| 74 |
warn $defaultcasserver; |
|
|
| 75 |
$casparam = $defaultcasserver if (not defined $casparam); |
85 |
$casparam = $defaultcasserver if (not defined $casparam); |
| 76 |
my $cas = Authen::CAS::Client->new($casservers->{$casparam}); |
86 |
my $cas = Authen::CAS::Client->new($casservers->{$casparam}); |
| 77 |
print $query->redirect( $cas->login_url($uri)); |
87 |
print $query->redirect( $cas->login_url($uri)); |
|
Lines 79-91
sub login_cas {
Link Here
|
| 79 |
|
89 |
|
| 80 |
# Returns CAS login URL with callback to the requesting URL |
90 |
# Returns CAS login URL with callback to the requesting URL |
| 81 |
sub login_cas_url { |
91 |
sub login_cas_url { |
| 82 |
my ($query) = @_; |
92 |
|
|
|
93 |
my ($query, $key) = @_; |
| 83 |
my $uri = $ENV{'SCRIPT_URI'}; |
94 |
my $uri = $ENV{'SCRIPT_URI'}; |
| 84 |
my $casparam = $query->param('cas'); |
95 |
my $casparam = $query->param('cas'); |
| 85 |
# FIXME: This should be more generic and handle whatever parameters there might be |
96 |
# FIXME: This should be more generic and handle whatever parameters there might be |
| 86 |
$uri .= "?cas=" . $casparam if (defined $casparam); |
97 |
$uri .= "?cas=" . $casparam if (defined $casparam); |
| 87 |
$casparam = $defaultcasserver if (not defined $casparam); |
98 |
$casparam = $defaultcasserver if (not defined $casparam); |
| 88 |
warn $defaultcasserver; |
99 |
$casparam = $key if (defined $key); |
| 89 |
my $cas = Authen::CAS::Client->new($casservers->{$casparam}); |
100 |
my $cas = Authen::CAS::Client->new($casservers->{$casparam}); |
| 90 |
return $cas->login_url($uri); |
101 |
return $cas->login_url($uri); |
| 91 |
} |
102 |
} |