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

(-)a/C4/Auth.pm (-12 / +4 lines)
Lines 48-54 use Koha::Patrons; Link Here
48
use Koha::Patron::Consents;
48
use Koha::Patron::Consents;
49
use List::MoreUtils qw( any );
49
use List::MoreUtils qw( any );
50
use Encode;
50
use Encode;
51
use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_shib checkpw_shib );
51
use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_shib checkpw_shib get_force_sso_setting );
52
use Net::CIDR;
52
use Net::CIDR;
53
use C4::Log qw( logaction );
53
use C4::Log qw( logaction );
54
use Koha::CookieManager;
54
use Koha::CookieManager;
Lines 1183-1197 sub checkauth { Link Here
1183
            }
1183
            }
1184
1184
1185
            # If shib configured and shibOnly enabled, we should ignore anything other than a shibboleth type login.
1185
            # If shib configured and shibOnly enabled, we should ignore anything other than a shibboleth type login.
1186
            if (
1186
            if (   $shib
1187
                   $shib
1188
                && !$shibSuccess
1187
                && !$shibSuccess
1189
                && (
1188
                && get_force_sso_setting($type) )
1190
                    ( ( $type eq 'opac' ) && C4::Context->preference('OPACShibOnly') )
1191
                    || ( ( $type ne 'opac' )
1192
                        && C4::Context->preference('staffShibOnly') )
1193
                )
1194
                )
1195
            {
1189
            {
1196
                $return = 0;
1190
                $return = 0;
1197
            }
1191
            }
Lines 1586-1594 sub checkauth { Link Here
1586
    if ($shib) {
1580
    if ($shib) {
1587
1581
1588
        #If shibOnly is enabled just go ahead and redirect directly
1582
        #If shibOnly is enabled just go ahead and redirect directly
1589
        if (   ( ( $type eq 'opac' ) && C4::Context->preference('OPACShibOnly') )
1583
        if ( get_force_sso_setting($type) ) {
1590
            || ( ( $type ne 'opac' ) && C4::Context->preference('staffShibOnly') ) )
1591
        {
1592
            my $redirect_url = login_shib_url($query);
1584
            my $redirect_url = login_shib_url($query);
1593
            print $query->redirect( -uri => "$redirect_url", -status => 303 );
1585
            print $query->redirect( -uri => "$redirect_url", -status => 303 );
1594
            safe_exit;
1586
            safe_exit;
(-)a/C4/Auth_with_shibboleth.pm (-4 / +33 lines)
Lines 29-41 use Carp qw( carp ); Link Here
29
use List::MoreUtils qw( any );
29
use List::MoreUtils qw( any );
30
30
31
use Koha::Logger;
31
use Koha::Logger;
32
use Koha::ShibbolethConfigs;
32
33
33
our ( @ISA, @EXPORT_OK );
34
our ( @ISA, @EXPORT_OK );
34
35
35
BEGIN {
36
BEGIN {
36
    require Exporter;
37
    require Exporter;
37
    @ISA       = qw(Exporter);
38
    @ISA       = qw(Exporter);
38
    @EXPORT_OK = qw(shib_ok logout_shib login_shib_url checkpw_shib get_login_shib);
39
    @EXPORT_OK = qw(shib_ok logout_shib login_shib_url checkpw_shib get_login_shib get_force_sso_setting);
39
}
40
}
40
41
41
# Check that shib config is not malformed
42
# Check that shib config is not malformed
Lines 243-256 sub _get_return { Link Here
243
    return $uri_base_part . URI::Escape::uri_escape_utf8($uri_params_part);
244
    return $uri_base_part . URI::Escape::uri_escape_utf8($uri_params_part);
244
}
245
}
245
246
247
sub get_force_sso_setting {
248
    my ($interface) = @_;
249
250
    my $db_config = Koha::ShibbolethConfigs->new->get_configuration;
251
    return 0 unless $db_config;
252
253
    if ( $interface eq 'opac' ) {
254
        return $db_config->get_value('force_opac_sso') || 0;
255
    } else {
256
        return $db_config->get_value('force_staff_sso') || 0;
257
    }
258
}
259
246
sub _get_shib_config {
260
sub _get_shib_config {
247
    my $config = C4::Context->config('shibboleth');
261
    my $db_config = Koha::ShibbolethConfigs->new->get_configuration;
248
262
249
    if ( !$config ) {
263
    if ( !$db_config ) {
250
        Koha::Logger->get->warn('shibboleth config not defined');
264
        Koha::Logger->get->warn('shibboleth config not defined');
251
        return 0;
265
        return 0;
252
    }
266
    }
253
267
268
    my $config = $db_config->get_combined_config;
269
270
    if ( !$config ) {
271
        Koha::Logger->get->warn('shibboleth config could not be loaded');
272
        return 0;
273
    }
274
254
    if ( $config->{matchpoint}
275
    if ( $config->{matchpoint}
255
        && defined( $config->{mapping}->{ $config->{matchpoint} }->{is} ) )
276
        && defined( $config->{mapping}->{ $config->{matchpoint} }->{is} ) )
256
    {
277
    {
Lines 408-413 A sugar function to that simply returns the current page URI with appropriate pr Link Here
408
429
409
This routine is NOT exported
430
This routine is NOT exported
410
431
432
=head2 get_force_sso_setting
433
434
  my $force_sso = get_force_sso_setting($interface);
435
436
Returns the force SSO setting for the given interface (opac or intranet).
437
Returns 0 if shibboleth is not configured or the setting is disabled.
438
439
  $interface - 'opac' or 'intranet'
440
411
=head2 _get_shib_config
441
=head2 _get_shib_config
412
442
413
  my $config = _get_shib_config();
443
  my $config = _get_shib_config();
414
- 

Return to bug 39224