use C4::Members::Messaging;
use Carp;
use CGI;
+use List::MoreUtils qw(any);
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
my $config = _get_shib_config();
my $matchAttribute = $config->{mapping}->{ $config->{matchpoint} }->{is};
- $debug and warn $matchAttribute . " value: " . $ENV{$matchAttribute};
- return $ENV{$matchAttribute} || '';
+ if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
+ $debug and warn $matchAttribute . " value: " . $ENV{"HTTP_".uc($matchAttribute)};
+ return $ENV{"HTTP_".uc($matchAttribute)} || '';
+ } else {
+ $debug and warn $matchAttribute . " value: " . $ENV{$matchAttribute};
+ return $ENV{$matchAttribute} || '';
+ }
}
# Checks for password correctness
Koha::Database->new()->schema()->resultset('Borrower')
->find( { $config->{matchpoint} => $match } );
if ( defined($borrower) ) {
+ if ($config->{'sync'}) {
+ _sync($borrower->borrowernumber, $config, $match);
+ }
return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') );
}
my %borrower = ( $config->{matchpoint} => $match );
while ( my ( $key, $entry ) = each %{$config->{'mapping'}} ) {
- $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
+ if ( any { /(^psgi|^plack)/i } keys %ENV ) {
+ $borrower{$key} = ( $entry->{'is'} && $ENV{"HTTP_" . uc($entry->{'is'}) } ) || $entry->{'content'} || '';
+ } else {
+ $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
+ }
}
my $patron = Koha::Patron->new( \%borrower )->store;
return ( 1, $patron->cardnumber, $patron->userid );
}
+sub _sync {
+ my ($borrowernumber, $config, $match ) = @_;
+ my %borrower;
+ $borrower{'borrowernumber'} = $borrowernumber;
+ while ( my ( $key, $entry ) = each %{$config->{'mapping'}} ) {
+ if ( any { /(^psgi|^plack)/i } keys %ENV ) {
+ $borrower{$key} = ( $entry->{'is'} && $ENV{"HTTP_" . uc($entry->{'is'}) } ) || $entry->{'content'} || '';
+ } else {
+ $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
+ }
+ }
+ my $patron = Koha::Patrons->find( $borrowernumber );
+ $patron->set(\%borrower)->store;
+}
+
sub _get_uri {
my $protocol = "https://";
my $config = C4::Context->config('shibboleth');
if ( !$config ) {
- carp 'shibboleth config not defined';
+ carp 'shibboleth config not defined' if $debug;
return 0;
}
Tell apache that we wish to allow koha to authenticate via shibboleth.
-This is as simple as adding the below to your virtualhost config:
+This is as simple as adding the below to your virtualhost config (for CGI running):
+
+ <Location />
+ AuthType shibboleth
+ Require shibboleth
+ </Location>
+
+Or (for Plack running):
<Location />
AuthType shibboleth
Require shibboleth
+ ShibUseEnvironment Off
+ ShibUseHeaders On
</Location>
+IMPORTANT: Please note, if you are running in the plack configuration you should consult https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPSpoofChecking for security advice regarding header spoof checking settings. (See also bug 17776 on Bugzilla about enabling ShibUseHeaders.)
+
=item 5.
Configure koha to listen for shibboleth environment variables.