View | Details | Raw Unified | Return to bug 11219
Collapse All | Expand All

(-)a/C4/Auth.pm (+1 lines)
Lines 1531-1536 sub checkpw { Link Here
1531
        $debug and print STDERR "## checkpw - checking CAS\n";
1531
        $debug and print STDERR "## checkpw - checking CAS\n";
1532
    # In case of a CAS authentication, we use the ticket instead of the password
1532
    # In case of a CAS authentication, we use the ticket instead of the password
1533
        my $ticket = $query->param('ticket');
1533
        my $ticket = $query->param('ticket');
1534
        $query->delete('ticket'); # remove ticket to come back to original URL
1534
        my ($retval,$retcard,$retuserid) = checkpw_cas($dbh, $ticket, $query);    # EXTERNAL AUTH
1535
        my ($retval,$retcard,$retuserid) = checkpw_cas($dbh, $ticket, $query);    # EXTERNAL AUTH
1535
        ($retval) and return ($retval,$retcard,$retuserid);
1536
        ($retval) and return ($retval,$retcard,$retuserid);
1536
        return 0;
1537
        return 0;
(-)a/C4/Auth_with_cas.pm (-32 / +22 lines)
Lines 65-100 sub getMultipleAuth { Link Here
65
# Logout from CAS
65
# Logout from CAS
66
sub logout_cas {
66
sub logout_cas {
67
    my ($query) = @_;
67
    my ($query) = @_;
68
    my $uri = C4::Context->preference('OPACBaseURL') . $query->script_name();
68
    my ( $cas, $uri ) = _get_cas_and_service($query);
69
    my $casparam = $query->param('cas');
70
    # FIXME: This should be more generic and handle whatever parameters there might be
71
    $uri .= "?cas=" . $casparam if (defined $casparam);
72
    $casparam = $defaultcasserver if (not defined $casparam);
73
    my $cas = Authen::CAS::Client->new($casservers->{$casparam});
74
    print $query->redirect( $cas->logout_url($uri));
69
    print $query->redirect( $cas->logout_url($uri));
75
}
70
}
76
71
77
# Login to CAS
72
# Login to CAS
78
sub login_cas {
73
sub login_cas {
79
    my ($query) = @_;
74
    my ($query) = @_;
80
    my $uri = C4::Context->preference('OPACBaseURL') . $query->script_name();
75
    my ( $cas, $uri ) = _get_cas_and_service($query);
81
    my $casparam = $query->param('cas');
82
    # FIXME: This should be more generic and handle whatever parameters there might be
83
    $uri .= "?cas=" . $casparam if (defined $casparam);
84
    $casparam = $defaultcasserver if (not defined $casparam);
85
    my $cas = Authen::CAS::Client->new($casservers->{$casparam});
86
    print $query->redirect( $cas->login_url($uri));
76
    print $query->redirect( $cas->login_url($uri));
87
}
77
}
88
78
89
# Returns CAS login URL with callback to the requesting URL
79
# Returns CAS login URL with callback to the requesting URL
90
sub login_cas_url {
80
sub login_cas_url {
91
81
    my ( $query, $key ) = @_;
92
    my ($query, $key) = @_;
82
    my ( $cas, $uri ) = _get_cas_and_service( $query, $key );
93
    my $uri = C4::Context->preference('OPACBaseURL') . $query->url( -absolute => 1, -query => 1 );
94
    my $casparam = $query->param('cas');
95
    $casparam = $defaultcasserver if (not defined $casparam);
96
    $casparam = $key if (defined $key);
97
    my $cas = Authen::CAS::Client->new($casservers->{$casparam});
98
    return $cas->login_url($uri);
83
    return $cas->login_url($uri);
99
}
84
}
100
85
Lines 104-115 sub checkpw_cas { Link Here
104
    $debug and warn "checkpw_cas";
89
    $debug and warn "checkpw_cas";
105
    my ($dbh, $ticket, $query) = @_;
90
    my ($dbh, $ticket, $query) = @_;
106
    my $retnumber;
91
    my $retnumber;
107
    my $uri = C4::Context->preference('OPACBaseURL') . $query->script_name();
92
    my ( $cas, $uri ) = _get_cas_and_service($query);
108
    my $casparam = $query->param('cas');
109
    # FIXME: This should be more generic and handle whatever parameters there might be
110
    $uri .= "?cas=" . $casparam if (defined $casparam);
111
    $casparam = $defaultcasserver if (not defined $casparam);
112
    my $cas = Authen::CAS::Client->new($casservers->{$casparam});
113
93
114
    # If we got a ticket
94
    # If we got a ticket
115
    if ($ticket) {
95
    if ($ticket) {
Lines 157-171 sub check_api_auth_cas { Link Here
157
    $debug and warn "check_api_auth_cas";
137
    $debug and warn "check_api_auth_cas";
158
    my ($dbh, $PT, $query) = @_;
138
    my ($dbh, $PT, $query) = @_;
159
    my $retnumber;
139
    my $retnumber;
160
    my $url = C4::Context->preference('OPACBaseURL') . $query->script_name();
140
    my ( $cas, $uri ) = _get_cas_and_service($query);
161
162
    my $casparam = $query->param('cas');
163
    $casparam = $defaultcasserver if (not defined $casparam);
164
    my $cas = Authen::CAS::Client->new($casservers->{$casparam});
165
141
166
    # If we have a Proxy Ticket
142
    # If we have a Proxy Ticket
167
    if ($PT) {
143
    if ($PT) {
168
        my $r = $cas->proxy_validate( $url, $PT );
144
        my $r = $cas->proxy_validate( $uri, $PT );
169
145
170
        # If the PT is valid
146
        # If the PT is valid
171
        if ( $r->is_success ) {
147
        if ( $r->is_success ) {
Lines 203-208 sub check_api_auth_cas { Link Here
203
    return 0;
179
    return 0;
204
}
180
}
205
181
182
# Get CAS handler and service URI
183
sub _get_cas_and_service {
184
    my $query = shift;
185
    my $key   = shift;    # optional
186
187
    my $uri = C4::Context->preference('OPACBaseURL'); # server address
188
    $uri .= $query->url( -absolute => 1, -query => 1 ); # page with params
189
190
    my $casparam = $defaultcasserver;
191
    $casparam = $query->param('cas') if defined $query->param('cas');
192
    $casparam = $key if defined $key;
193
    my $cas = Authen::CAS::Client->new( $casservers->{$casparam} );
194
195
    return ( $cas, $uri );
196
}
206
197
207
1;
198
1;
208
__END__
199
__END__
209
- 

Return to bug 11219