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

(-)a/C4/Auth_with_shibboleth.pm (-9 / +45 lines)
Lines 38-43 use List::MoreUtils qw( any ); Link Here
38
38
39
use Koha::Logger;
39
use Koha::Logger;
40
use Koha::Auth::Identity::Providers;
40
use Koha::Auth::Identity::Providers;
41
use Koha::Patron::Attribute;
42
use Koha::Patron::Attributes;
41
43
42
# Check that shib config is not malformed
44
# Check that shib config is not malformed
43
45
Lines 99-105 sub checkpw_shib { Link Here
99
    my $config = _get_shib_config();
101
    my $config = _get_shib_config();
100
102
101
    # Does the given shibboleth attribute value ($match) match a valid koha user ?
103
    # Does the given shibboleth attribute value ($match) match a valid koha user ?
102
    my $borrowers = Koha::Patrons->search( { $config->{matchpoint} => $match } );
104
    my $borrowers;
105
    if ( $config->{matchpoint} =~ /^patron_attribute:(.+)$/ ) {
106
        my $code = $1;
107
        $borrowers = Koha::Patrons->search(
108
            { 'borrower_attributes.code' => $code, 'borrower_attributes.attribute' => $match },
109
            { join                       => 'borrower_attributes' }
110
        );
111
    } else {
112
        $borrowers = Koha::Patrons->search( { $config->{matchpoint} => $match } );
113
    }
103
    if ( $borrowers->count > 1 ) {
114
    if ( $borrowers->count > 1 ) {
104
115
105
        # If we have more than 1 borrower the matchpoint is not unique
116
        # If we have more than 1 borrower the matchpoint is not unique
Lines 129-145 sub checkpw_shib { Link Here
129
sub _autocreate {
140
sub _autocreate {
130
    my ( $config, $match ) = @_;
141
    my ( $config, $match ) = @_;
131
142
132
    my %borrower = ( $config->{matchpoint} => $match );
143
    my ( %borrower, %patron_attrs );
144
145
    if ( $config->{matchpoint} =~ /^patron_attribute:(.+)$/ ) {
146
        $patron_attrs{$1} = $match;
147
    } else {
148
        $borrower{ $config->{matchpoint} } = $match;
149
    }
133
150
134
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
151
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
135
        if ( C4::Context->psgi_env ) {
152
        my $value =
136
            $borrower{$key} = ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || '';
153
            C4::Context->psgi_env
154
            ? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || ''
155
            : ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
156
        if ( $key =~ /^patron_attribute:(.+)$/ ) {
157
            $patron_attrs{$1} = $value;
137
        } else {
158
        } else {
138
            $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
159
            $borrower{$key} = $value;
139
        }
160
        }
140
    }
161
    }
141
162
142
    my $patron = Koha::Patron->new( \%borrower )->store;
163
    my $patron = Koha::Patron->new( \%borrower )->store;
164
165
    for my $code ( keys %patron_attrs ) {
166
        Koha::Patron::Attribute->new(
167
            { borrowernumber => $patron->borrowernumber, code => $code, attribute => $patron_attrs{$code} } )->store;
168
    }
143
    $patron->discard_changes;
169
    $patron->discard_changes;
144
170
145
    C4::Members::Messaging::SetMessagingPreferencesFromDefaults(
171
    C4::Members::Messaging::SetMessagingPreferencesFromDefaults(
Lines 184-200 sub _autocreate { Link Here
184
210
185
sub _sync {
211
sub _sync {
186
    my ( $borrowernumber, $config, $match ) = @_;
212
    my ( $borrowernumber, $config, $match ) = @_;
187
    my %borrower;
213
    my ( %borrower, %patron_attrs );
188
    $borrower{'borrowernumber'} = $borrowernumber;
214
    $borrower{'borrowernumber'} = $borrowernumber;
189
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
215
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
190
        if ( C4::Context->psgi_env ) {
216
        my $value =
191
            $borrower{$key} = ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || '';
217
            C4::Context->psgi_env
218
            ? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || ''
219
            : ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
220
        if ( $key =~ /^patron_attribute:(.+)$/ ) {
221
            $patron_attrs{$1} = $value;
192
        } else {
222
        } else {
193
            $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
223
            $borrower{$key} = $value;
194
        }
224
        }
195
    }
225
    }
196
    my $patron = Koha::Patrons->find($borrowernumber);
226
    my $patron = Koha::Patrons->find($borrowernumber);
197
    $patron->set( \%borrower )->store;
227
    $patron->set( \%borrower )->store;
228
    for my $code ( keys %patron_attrs ) {
229
        my $existing = Koha::Patron::Attributes->search( { borrowernumber => $borrowernumber, code => $code } );
230
        $existing->delete;
231
        Koha::Patron::Attribute->new(
232
            { borrowernumber => $borrowernumber, code => $code, attribute => $patron_attrs{$code} } )->store;
233
    }
198
}
234
}
199
235
200
sub _get_uri {
236
sub _get_uri {
(-)a/Koha/Auth/Client.pm (-1 / +21 lines)
Lines 23-28 use C4::Context; Link Here
23
23
24
use Koha::Exceptions::Auth;
24
use Koha::Exceptions::Auth;
25
use Koha::Auth::Identity::Providers;
25
use Koha::Auth::Identity::Providers;
26
use Koha::Patron::Attribute;
27
use Koha::Patron::Attributes;
26
28
27
=head1 NAME
29
=head1 NAME
28
30
Lines 87-93 sub get_user { Link Here
87
    $patron      = $args->{'patron'};
89
    $patron      = $args->{'patron'};
88
    $domain      = $args->{'domain'};
90
    $domain      = $args->{'domain'};
89
91
90
    $patron->set($mapped_data)->store if $patron && $domain->update_on_auth;
92
    if ( $patron && $domain->update_on_auth ) {
93
        my ( %patron_attrs, %borrower_data );
94
        for my $key ( keys %$mapped_data ) {
95
            if ( $key =~ /^patron_attribute:(.+)$/ ) {
96
                $patron_attrs{$1} = $mapped_data->{$key};
97
            } else {
98
                $borrower_data{$key} = $mapped_data->{$key};
99
            }
100
        }
101
        $patron->set( \%borrower_data )->store;
102
        for my $code ( keys %patron_attrs ) {
103
            my $existing =
104
                Koha::Patron::Attributes->search( { borrowernumber => $patron->borrowernumber, code => $code } );
105
            $existing->delete;
106
            Koha::Patron::Attribute->new(
107
                { borrowernumber => $patron->borrowernumber, code => $code, attribute => $patron_attrs{$code} } )
108
                ->store;
109
        }
110
    }
91
111
92
    $mapped_data->{categorycode} = $domain->default_category_id;
112
    $mapped_data->{categorycode} = $domain->default_category_id;
93
    $mapped_data->{branchcode}   = $domain->default_library_id;
113
    $mapped_data->{branchcode}   = $domain->default_library_id;
(-)a/Koha/Auth/Client/OAuth.pm (-2 / +11 lines)
Lines 124-132 sub _find_patron_by_matchpoint { Link Here
124
124
125
    return unless defined $value;
125
    return unless defined $value;
126
126
127
    my $matchpoint_rs = Koha::Patrons->search( { $matchpoint => $value } );
127
    my $patron_rs;
128
    if ( $matchpoint =~ /^patron_attribute:(.+)$/ ) {
129
        my $code = $1;
130
        $patron_rs = Koha::Patrons->search(
131
            { 'borrower_attributes.code' => $code, 'borrower_attributes.attribute' => $value },
132
            { join                       => 'borrower_attributes' }
133
        );
134
    } else {
135
        $patron_rs = Koha::Patrons->search( { $matchpoint => $value } );
136
    }
128
137
129
    return $matchpoint_rs->count ? $matchpoint_rs->next : undef;
138
    return $patron_rs->count ? $patron_rs->next : undef;
130
}
139
}
131
140
132
1;
141
1;
(-)a/Koha/REST/Plugin/Auth/IdP.pm (-2 / +16 lines)
Lines 23-28 use Mojo::Base 'Mojolicious::Plugin'; Link Here
23
23
24
use Koha::Exceptions;
24
use Koha::Exceptions;
25
use Koha::Exceptions::Auth;
25
use Koha::Exceptions::Auth;
26
use Koha::Patron::Attribute;
26
use Koha::Patrons;
27
use Koha::Patrons;
27
28
28
use C4::Auth qw(create_basic_session);
29
use C4::Auth qw(create_basic_session);
Lines 89-95 if other values or none are passed. Link Here
89
                Koha::Exceptions::Auth::Unauthorized->throw( code => 401 );
90
                Koha::Exceptions::Auth::Unauthorized->throw( code => 401 );
90
            }
91
            }
91
92
92
            return Koha::Patron->new($data)->store;
93
            my ( %patron_attrs, %borrower_data );
94
            for my $key ( keys %$data ) {
95
                if ( $key =~ /^patron_attribute:(.+)$/ ) {
96
                    $patron_attrs{$1} = $data->{$key};
97
                } else {
98
                    $borrower_data{$key} = $data->{$key};
99
                }
100
            }
101
            my $patron = Koha::Patron->new( \%borrower_data )->store;
102
            for my $code ( keys %patron_attrs ) {
103
                Koha::Patron::Attribute->new(
104
                    { borrowernumber => $patron->borrowernumber, code => $code, attribute => $patron_attrs{$code} } )
105
                    ->store;
106
            }
107
            return $patron;
93
        }
108
        }
94
    );
109
    );
95
110
96
- 

Return to bug 39224