From 9b92ce4cd173e8249b02a6b62ad3b95aea1d6c5f Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Wed, 2 Apr 2014 15:53:03 +0000 Subject: [PATCH] Bug 12026: Adds auto-provisioning to shibboleth - Adds the option to map shibboleth attributes to koha user columns and allows mapping to auto create non-existant users Signed-off-by: Mirko Tietgen Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Olli-Antti Kivilahti Signed-off-by: Kyle M Hall --- C4/Auth_with_shibboleth.pm | 29 ++++++++++++++++++++++++----- C4/Members.pm | 19 +++++++++++++++++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/C4/Auth_with_shibboleth.pm b/C4/Auth_with_shibboleth.pm index cde0ede08b..ce2942ebb2 100644 --- a/C4/Auth_with_shibboleth.pm +++ b/C4/Auth_with_shibboleth.pm @@ -23,6 +23,8 @@ use C4::Debug; use C4::Context; use Koha::AuthUtils qw(get_script_name); use Koha::Database; +use C4::Members qw( AddMember_Auto ); +use C4::Members::Messaging; use Carp; use CGI; @@ -102,11 +104,28 @@ sub checkpw_shib { return ( 1, $borrower->get_column('cardnumber'), $borrower->get_column('userid') ); } - # If we reach this point, the user is not a valid koha user - $debug - and warn - "User with $config->{matchpoint} of $match is not a valid Koha user"; - return 0; + if ( $shib->{'autocreate'} ) { + return _autocreate( $dbh, $shib, $userid ); + } else { + # If we reach this point, the user is not a valid koha user + $debug and warn "User $userid is not a valid Koha user"; + return 0; + } +} + +sub _autocreate { + my ( $dbh, $shib, $userid ) = @_; + + my %borrower = ( userid => $userid ); + + while ( my ( $key, $entry ) = each %{$shib->{'mapping'}} ) { + $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; + } + + %borrower = AddMember_Auto( %borrower ); + C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower{'borrowernumber'}, categorycode => $borrower{'categorycode'} } ); + + return ( 1, $borrower{'cardnumber'}, $borrower{'userid'} ); } sub _get_uri { diff --git a/C4/Members.pm b/C4/Members.pm index 8e73872894..abdffb4d97 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -88,6 +88,7 @@ BEGIN { #Insert data push @EXPORT, qw( &AddMember + &AddMember_Auto &AddMember_Opac ); @@ -1261,6 +1262,20 @@ sub GetBorrowersWithEmail { return @result; } +=head2 AddMember_Auto + +=cut + +sub AddMember_Auto { + my ( %borrower ) = @_; + + $borrower{'cardnumber'} ||= fixup_cardnumber(); + + $borrower{'borrowernumber'} = AddMember(%borrower); + + return ( %borrower ); +} + =head2 AddMember_Opac =cut @@ -1278,9 +1293,9 @@ sub AddMember_Opac { $borrower{'cardnumber'} = fixup_cardnumber( $borrower{'cardnumber'} ); - my $borrowernumber = AddMember(%borrower); + %borrower = AddMember_Auto(%borrower); - return ( $borrowernumber, $borrower{'password'} ); + return ( $borrower{'borrowernumber'}, $borrower{'password'} ); } =head2 DeleteExpiredOpacRegistrations -- 2.39.5