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

(-)a/C4/Auth_with_shibboleth.pm (-4 / +8 lines)
Lines 149-158 sub _autocreate { Link Here
149
    }
149
    }
150
150
151
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
151
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
152
        next unless $entry->{'sync_on_creation'};
152
        my $value =
153
        my $value =
153
            C4::Context->psgi_env
154
            C4::Context->psgi_env
154
            ? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || ''
155
            ? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) // $entry->{'content'} // ''
155
            : ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
156
            : ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) // $entry->{'content'} // '';
156
        if ( $key =~ /^patron_attribute:(.+)$/ ) {
157
        if ( $key =~ /^patron_attribute:(.+)$/ ) {
157
            $patron_attrs{$1} = $value;
158
            $patron_attrs{$1} = $value;
158
        } else {
159
        } else {
Lines 213-222 sub _sync { Link Here
213
    my ( %borrower, %patron_attrs );
214
    my ( %borrower, %patron_attrs );
214
    $borrower{'borrowernumber'} = $borrowernumber;
215
    $borrower{'borrowernumber'} = $borrowernumber;
215
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
216
    while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) {
217
        next unless $entry->{'sync_on_update'};
216
        my $value =
218
        my $value =
217
            C4::Context->psgi_env
219
            C4::Context->psgi_env
218
            ? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || ''
220
            ? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } )
219
            : ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
221
            : ( $entry->{'is'} && $ENV{ $entry->{'is'} } );
222
        next unless defined $value;
223
220
        if ( $key =~ /^patron_attribute:(.+)$/ ) {
224
        if ( $key =~ /^patron_attribute:(.+)$/ ) {
221
            $patron_attrs{$1} = $value;
225
            $patron_attrs{$1} = $value;
222
        } else {
226
        } else {
(-)a/Koha/Auth/Client.pm (-4 / +12 lines)
Lines 89-104 sub get_user { Link Here
89
    $patron      = $args->{'patron'};
89
    $patron      = $args->{'patron'};
90
    $domain      = $args->{'domain'};
90
    $domain      = $args->{'domain'};
91
91
92
    my $mapping = $provider->mappings->as_auth_mapping;
93
92
    if ( $patron && $domain->update_on_auth ) {
94
    if ( $patron && $domain->update_on_auth ) {
93
        my ( %patron_attrs, %borrower_data );
95
        my ( %patron_attrs, %borrower_data );
94
        for my $key ( keys %$mapped_data ) {
96
        for my $key ( keys %$mapping ) {
97
            next unless $mapping->{$key}->{sync_on_update};
98
            my $value = $mapped_data->{$key};
99
100
            # We don't use default_content on update, only what we got from IdP
101
            next unless defined $value;
102
95
            if ( $key =~ /^patron_attribute:(.+)$/ ) {
103
            if ( $key =~ /^patron_attribute:(.+)$/ ) {
96
                $patron_attrs{$1} = $mapped_data->{$key};
104
                $patron_attrs{$1} = $value;
97
            } else {
105
            } else {
98
                $borrower_data{$key} = $mapped_data->{$key};
106
                $borrower_data{$key} = $value;
99
            }
107
            }
100
        }
108
        }
101
        $patron->set( \%borrower_data )->store;
109
        $patron->set( \%borrower_data )->store if %borrower_data;
102
        for my $code ( keys %patron_attrs ) {
110
        for my $code ( keys %patron_attrs ) {
103
            my $existing =
111
            my $existing =
104
                Koha::Patron::Attributes->search( { borrowernumber => $patron->borrowernumber, code => $code } );
112
                Koha::Patron::Attributes->search( { borrowernumber => $patron->borrowernumber, code => $code } );
(-)a/Koha/Auth/Client/OAuth.pm (-4 / +8 lines)
Lines 74-82 sub _get_data_and_patron { Link Here
74
        my $claim = decode_json( decode_base64url($claims_part) );
74
        my $claim = decode_json( decode_base64url($claims_part) );
75
75
76
        foreach my $koha_field ( keys %$mapping ) {
76
        foreach my $koha_field ( keys %$mapping ) {
77
            my $pkey = $mapping->{$koha_field}{is};
77
            my $pkey  = $mapping->{$koha_field}{is};
78
            $mapped_data->{$koha_field} = $claim->{$pkey}
78
            my $value = defined $pkey ? $claim->{$pkey} : undef;
79
                if defined $pkey && defined $claim->{$pkey};
79
80
            # Note: We don't apply default here yet, because we need to know if it's a create or update.
81
            # But we should at least store what we got.
82
            $mapped_data->{$koha_field} = $value
83
                if defined $value;
80
        }
84
        }
81
85
82
        $patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} );
86
        $patron = $self->_find_patron_by_matchpoint( $matchpoint, $mapped_data->{$matchpoint} );
Lines 96-102 sub _get_data_and_patron { Link Here
96
100
97
        foreach my $koha_field ( keys %$mapping ) {
101
        foreach my $koha_field ( keys %$mapping ) {
98
            my $pkey  = $mapping->{$koha_field}{is};
102
            my $pkey  = $mapping->{$koha_field}{is};
99
            my $value = $self->_traverse_hash( { base => $claim, keys => $pkey } );
103
            my $value = defined $pkey ? $self->_traverse_hash( { base => $claim, keys => $pkey } ) : undef;
100
            $mapped_data->{$koha_field} = $value
104
            $mapped_data->{$koha_field} = $value
101
                if defined $value;
105
                if defined $value;
102
        }
106
        }
(-)a/Koha/Auth/Identity/Provider/Mappings.pm (-2 / +4 lines)
Lines 46-53 sub as_auth_mapping { Link Here
46
46
47
    while ( my $m = $self->next ) {
47
    while ( my $m = $self->next ) {
48
        $mapping{ $m->koha_field } = {
48
        $mapping{ $m->koha_field } = {
49
            is      => $m->provider_field,
49
            is               => $m->provider_field,
50
            content => $m->default_content,
50
            content          => $m->default_content,
51
            sync_on_creation => $m->sync_on_creation,
52
            sync_on_update   => $m->sync_on_update,
51
        };
53
        };
52
    }
54
    }
53
55
(-)a/Koha/REST/Plugin/Auth/IdP.pm (-3 / +11 lines)
Lines 90-101 if other values or none are passed. Link Here
90
                Koha::Exceptions::Auth::Unauthorized->throw( code => 401 );
90
                Koha::Exceptions::Auth::Unauthorized->throw( code => 401 );
91
            }
91
            }
92
92
93
            my $provider = $domain->identity_provider;
94
            my $mapping  = $provider->mappings->as_auth_mapping;
95
93
            my ( %patron_attrs, %borrower_data );
96
            my ( %patron_attrs, %borrower_data );
94
            for my $key ( keys %$data ) {
97
            for my $key ( keys %$mapping ) {
98
                next unless $mapping->{$key}->{sync_on_creation};
99
                my $value = $data->{$key};
100
                $value //= $mapping->{$key}->{content};
101
                next unless defined $value;
102
95
                if ( $key =~ /^patron_attribute:(.+)$/ ) {
103
                if ( $key =~ /^patron_attribute:(.+)$/ ) {
96
                    $patron_attrs{$1} = $data->{$key};
104
                    $patron_attrs{$1} = $value;
97
                } else {
105
                } else {
98
                    $borrower_data{$key} = $data->{$key};
106
                    $borrower_data{$key} = $value;
99
                }
107
                }
100
            }
108
            }
101
            my $patron = Koha::Patron->new( \%borrower_data )->store;
109
            my $patron = Koha::Patron->new( \%borrower_data )->store;
(-)a/api/v1/swagger/definitions/identity_provider_mapping.yaml (+8 lines)
Lines 22-27 properties: Link Here
22
      - string
22
      - string
23
      - "null"
23
      - "null"
24
    description: Default value to use if the provider does not supply this attribute
24
    description: Default value to use if the provider does not supply this attribute
25
  sync_on_creation:
26
    type: boolean
27
    description: Whether to sync this field on user creation
28
    default: true
29
  sync_on_update:
30
    type: boolean
31
    description: Whether to sync this field on user update
32
    default: true
25
additionalProperties: false
33
additionalProperties: false
26
required:
34
required:
27
  - koha_field
35
  - koha_field
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/IdentityProviders/MappingResource.vue (-1 / +20 lines)
Lines 61-66 export default { Link Here
61
                    "Value to use when the provider does not supply this attribute"
61
                    "Value to use when the provider does not supply this attribute"
62
                ),
62
                ),
63
            },
63
            },
64
            {
65
                name: "sync_on_creation",
66
                type: "checkbox",
67
                label: __("Sync on creation"),
68
                group: "Mapping",
69
                toolTip: __(
70
                    "If checked, this field will be synced when the user is first created"
71
                ),
72
                default: true,
73
            },
74
            {
75
                name: "sync_on_update",
76
                type: "checkbox",
77
                label: __("Sync on update"),
78
                group: "Mapping",
79
                toolTip: __(
80
                    "If checked, this field will be synced on subsequent logins"
81
                ),
82
                default: true,
83
            },
64
        ];
84
        ];
65
85
66
        const baseResource = useBaseResource({
86
        const baseResource = useBaseResource({
67
- 

Return to bug 33538