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

(-)a/Koha/ShibbolethConfig.pm (+113 lines)
Line 0 Link Here
1
package Koha::ShibbolethConfig;
2
3
use Modern::Perl;
4
use base qw(Koha::Object);
5
6
use Koha::ShibbolethFieldMappings;
7
8
=head1 NAME
9
10
Koha::ShibbolethConfig - Koha ShibbolethConfig Object class
11
12
=head1 API
13
14
=head2 Class Methods
15
16
=cut
17
18
=head3 _type
19
20
=cut
21
22
sub _type {
23
    return 'ShibbolethConfig';
24
}
25
26
=head3 store
27
28
Override store method to ensure we always update the single config row
29
30
=cut
31
32
sub store {
33
    my ($self) = @_;
34
35
    # Force ID to be 1
36
    $self->shibboleth_config_id(1);
37
38
    # If record exists, update it
39
    if ( my $existing = Koha::ShibbolethConfigs->find(1) ) {
40
        foreach my $field (qw( force_opac_sso force_staff_sso autocreate sync welcome )) {
41
            $existing->$field( $self->$field ) if defined $self->$field;
42
        }
43
        return $existing->SUPER::store();
44
    }
45
46
    # Otherwise create new record with ID 1
47
    return $self->SUPER::store();
48
}
49
50
=head3 mappings
51
52
Returns field mappings associated with this config
53
54
=cut
55
56
sub mappings {
57
    my ($self) = @_;
58
    return Koha::ShibbolethFieldMappings->new;
59
}
60
61
=head3 get_combined_config
62
63
Returns complete configuration including mappings
64
65
=cut
66
67
sub get_combined_config {
68
    my ($self) = @_;
69
70
    my $config = $self->unblessed;
71
    my ( $success, $mapping_config ) = $self->mappings->get_mapping_config;
72
73
    if ($success) {
74
75
        # Merge mapping config with base config
76
        $config->{matchpoint} = $mapping_config->{matchpoint};
77
        $config->{mapping}    = $mapping_config->{mapping};
78
        return $config;
79
    }
80
81
    return;
82
}
83
84
=head3 get_field_mappings
85
86
Returns a hashref of field mappings in config format
87
88
=cut
89
90
sub get_field_mappings {
91
    my ($self) = @_;
92
    my ( $success, $mapping_config ) = $self->mappings->get_mapping_config;
93
    return $mapping_config->{mapping} if $success;
94
    return {};
95
}
96
97
=head3 get_value
98
99
Returns the value of a specific configuration column.
100
101
@param string $column The name of the configuration column to retrieve
102
@return mixed The value of the configuration column or undef if not found
103
104
=cut
105
106
sub get_value {
107
    my ( $self, $column ) = @_;
108
    return unless $column;
109
    return unless $self->_result->result_source->has_column($column);
110
    return $self->$column;
111
}
112
113
1;
(-)a/Koha/ShibbolethConfigs.pm (+63 lines)
Line 0 Link Here
1
package Koha::ShibbolethConfigs;
2
3
use Modern::Perl;
4
use base qw(Koha::Objects);
5
use Koha::ShibbolethConfig;
6
7
=head1 NAME
8
9
Koha::ShibbolethConfigs - Koha ShibbolethConfig Object set class
10
11
=head1 API
12
13
=head2 Class Methods
14
15
=cut
16
17
=head3 get_configuration
18
19
Returns the Shibboleth configuration settings.
20
Always returns the single configuration row with ID=1.
21
22
=cut
23
24
sub get_configuration {
25
    my ($self) = @_;
26
27
    # Always get config with ID=1
28
    my $config = $self->find(1);
29
    unless ($config) {
30
31
        # Create default config with ID=1 if it doesn't exist
32
        $config = Koha::ShibbolethConfig->new(
33
            {
34
                shibboleth_config_id => 1,
35
                force_opac_sso       => 0,
36
                force_staff_sso      => 0,
37
                autocreate           => 0,
38
                sync                 => 0,
39
                welcome              => 0
40
            }
41
        )->store;
42
    }
43
44
    return $config;
45
}
46
47
=head3 _type
48
49
=cut
50
51
sub _type {
52
    return 'ShibbolethConfig';
53
}
54
55
=head3 object_class
56
57
=cut
58
59
sub object_class {
60
    return 'Koha::ShibbolethConfig';
61
}
62
63
1;
(-)a/Koha/ShibbolethFieldMapping.pm (+52 lines)
Line 0 Link Here
1
package Koha::ShibbolethFieldMapping;
2
3
use Modern::Perl;
4
use Koha::Exceptions;
5
use base qw(Koha::Object);
6
7
=head1 NAME
8
9
Koha::ShibbolethFieldMapping - Koha ShibbolethFieldMapping Object class
10
11
=head1 API
12
13
=head2 Class Methods
14
15
=cut
16
17
=head3 store
18
19
Override the base store method to enforce business rules:
20
- Only one matchpoint can be set at a time
21
- Required fields must be present
22
23
=cut
24
25
sub store {
26
    my $self = shift;
27
28
    unless ( $self->koha_field ) {
29
        Koha::Exceptions::MissingParameter->throw( error => "koha_field is required" );
30
    }
31
32
    unless ( $self->idp_field || $self->default_content ) {
33
        Koha::Exceptions::MissingParameter->throw( error => "Either idp_field or default_content must be provided" );
34
    }
35
36
    # Handle matchpoint logic before storing
37
    if ( $self->is_matchpoint ) {
38
        Koha::ShibbolethFieldMappings->new->ensure_single_matchpoint( $self->mapping_id );
39
    }
40
41
    return $self->SUPER::store(@_);
42
}
43
44
=head3 _type
45
46
=cut
47
48
sub _type {
49
    return 'ShibbolethFieldMapping';
50
}
51
52
1;
(-)a/Koha/ShibbolethFieldMappings.pm (-1 / +99 lines)
Line 0 Link Here
0
- 
1
package Koha::ShibbolethFieldMappings;
2
3
use Modern::Perl;
4
use base qw(Koha::Objects);
5
use Koha::ShibbolethFieldMapping;
6
use Koha::Logger;
7
8
=head1 NAME
9
10
Koha::ShibbolethFieldMappings - Koha ShibbolethFieldMapping Object set class
11
12
=head1 API
13
14
=head2 Class Methods
15
16
=cut
17
18
=head3 ensure_single_matchpoint
19
20
Ensures only one matchpoint exists by clearing other matchpoints when setting a new one
21
22
=cut
23
24
sub ensure_single_matchpoint {
25
    my ( $self, $new_matchpoint_id ) = @_;
26
27
    return $self->search(
28
        {
29
            is_matchpoint => 1,
30
            mapping_id    => { '!=' => $new_matchpoint_id || 0 }
31
        }
32
    )->update( { is_matchpoint => 0 } );
33
}
34
35
=head3 get_matchpoint
36
37
Returns the field mapping that is set as the matchpoint
38
39
=cut
40
41
sub get_matchpoint {
42
    my ($self) = @_;
43
    my $matchpoint = $self->search( { is_matchpoint => 1 } )->single;
44
45
    unless ($matchpoint) {
46
        Koha::Logger->get->warn('No matchpoint configured in Shibboleth field mappings');
47
    }
48
49
    return $matchpoint;
50
}
51
52
=head3 get_mapping_config
53
54
Returns the field mappings formatted for use in authentication configuration.
55
56
=cut
57
58
sub get_mapping_config {
59
    my ($self) = @_;
60
61
    my $mappings   = {};
62
    my $matchpoint = $self->get_matchpoint;
63
64
    return ( 0, undef ) unless $matchpoint;
65
66
    my $all_mappings = $self->search;
67
    while ( my $mapping = $all_mappings->next ) {
68
        $mappings->{ $mapping->koha_field } = {
69
            is      => $mapping->idp_field,
70
            content => $mapping->default_content,
71
        };
72
    }
73
74
    return (
75
        1,
76
        {
77
            matchpoint => $matchpoint->koha_field,
78
            mapping    => $mappings
79
        }
80
    );
81
}
82
83
=head3 _type
84
85
=cut
86
87
sub _type {
88
    return 'ShibbolethFieldMapping';
89
}
90
91
=head3 object_class
92
93
=cut
94
95
sub object_class {
96
    return 'Koha::ShibbolethFieldMapping';
97
}
98
99
1;

Return to bug 39224