--- loncom/auth/lonacc.pm 2018/07/02 20:53:07 1.170 +++ loncom/auth/lonacc.pm 2018/11/24 16:19:04 1.171 @@ -1,7 +1,7 @@ # The LearningOnline Network # Cookie Based Access Handler # -# $Id: lonacc.pm,v 1.170 2018/07/02 20:53:07 raeburn Exp $ +# $Id: lonacc.pm,v 1.171 2018/11/24 16:19:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -340,17 +340,21 @@ sub sso_login { ($is_balancer,$otherserver) = &Apache::lonnet::check_loadbalancing($user,$domain,'login'); if ($is_balancer) { - if ($otherserver eq '') { + # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer) + my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r); + if (($found_server) && ($balancer_cookie =~ /^\Q$domain\E_\Q$user\E_/)) { + $otherserver = $found_server; + } elsif ($otherserver eq '') { my $lowest_load; ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($domain); if ($lowest_load > 100) { $otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$domain); } - } - if ($otherserver ne '') { - my @hosts = &Apache::lonnet::current_machine_ids(); - if (grep(/^\Q$otherserver\E$/,@hosts)) { - $hosthere = $otherserver; + if ($otherserver ne '') { + my @hosts = &Apache::lonnet::current_machine_ids(); + if (grep(/^\Q$otherserver\E$/,@hosts)) { + $hosthere = $otherserver; + } } } } @@ -561,7 +565,7 @@ sub handler { my $checkexempt; if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) { if ($env{'user.loadbalcheck.time'} + 600 > time) { - $checkexempt = 1; + $checkexempt = 1; } } if ($env{'user.noloadbalance'} eq $r->dir_config('lonHostID')) { @@ -571,12 +575,23 @@ sub handler { ($is_balancer,$otherserver) = &Apache::lonnet::check_loadbalancing($env{'user.name'}, $env{'user.domain'}); + if ($is_balancer) { + unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) { + # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer) + my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r); + if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) { + $otherserver = $found_server; + } + } + } } if ($is_balancer) { - $r->set_handlers('PerlResponseHandler'=> - [\&Apache::switchserver::handler]); - if ($otherserver ne '') { - $env{'form.otherserver'} = $otherserver; + unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) { + $r->set_handlers('PerlResponseHandler'=> + [\&Apache::switchserver::handler]); + if ($otherserver ne '') { + $env{'form.otherserver'} = $otherserver; + } } unless (($env{'form.origurl'}) || ($r->uri eq '/adm/roles') || ($r->uri eq '/adm/switchserver') || ($r->uri eq '/adm/sso')) {