From e7ff28dd5c91bb0622dcb4da66ca5e6066ecdef6 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Wed, 2 Apr 2014 15:53:03 +0000 Subject: [PATCH] BUG12026: 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 --- C4/Auth_with_shibboleth.pm | 25 ++++++++++++++++++++++--- C4/Members.pm | 13 ++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/C4/Auth_with_shibboleth.pm b/C4/Auth_with_shibboleth.pm index fddbc9d..74bd633 100644 --- a/C4/Auth_with_shibboleth.pm +++ b/C4/Auth_with_shibboleth.pm @@ -22,6 +22,7 @@ use warnings; use C4::Debug; use C4::Context; +use C4::Members qw( AddMember_Auto ); use Carp; use CGI; @@ -99,9 +100,27 @@ sub checkpw_shib { return ( 1, $retnumber, $userid ); } - # 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; + 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 ); + + return ( 1, $borrower{'cardnumber'}, $borrower{'userid'} ); } 1; diff --git a/C4/Members.pm b/C4/Members.pm index 486a61d..31074b5 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -120,6 +120,7 @@ BEGIN { #Insert data push @EXPORT, qw( &AddMember + &AddMember_Auto &AddMember_Opac &MoveMemberToDeleted &ExtendMemberSubscriptionTo @@ -2388,6 +2389,16 @@ sub GetBorrowersWithEmail { return @result; } +sub AddMember_Auto { + my ( %borrower ) = @_; + + $borrower{'cardnumber'} ||= fixup_cardnumber(); + + $borrower{'borrowernumber'} = AddMember(%borrower); + + return ( %borrower ); +} + sub AddMember_Opac { my ( %borrower ) = @_; @@ -2400,7 +2411,7 @@ sub AddMember_Opac { $borrower{'cardnumber'} = fixup_cardnumber(); - my $borrowernumber = AddMember(%borrower); + %borrower = AddMember_Auto(%borrower); return ( $borrowernumber, $password ); } -- 1.7.10.4