Diff for /loncom/auth/lonshibauth.pm between versions 1.10 and 1.11

version 1.10, 2021/10/10 23:59:19 version 1.11, 2021/10/26 15:52:54
Line 68  package Apache::lonshibauth; Line 68  package Apache::lonshibauth;
 use strict;  use strict;
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use Apache::lonnet;  use Apache::lonnet;
   use Apache::loncommon;
   use Apache::lonacc;
 use Apache::Constants qw(:common REDIRECT);  use Apache::Constants qw(:common REDIRECT);
 use LONCAPA qw(:DEFAULT);  use LONCAPA qw(:DEFAULT :match);
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
Line 77  sub handler { Line 79  sub handler {
     if (&Apache::lonnet::get_saml_landing()) {      if (&Apache::lonnet::get_saml_landing()) {
         $target = '/adm/login';          $target = '/adm/login';
     }      }
     my $uri = $r->uri;      if (($r->user eq '') && ($r->uri ne $target) && ($r->uri ne '/adm/sso')) {
     if (($r->user eq '') && ($uri ne $target) && ($uri ne '/adm/sso')) {  
         my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};          my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
         my $hostname = &Apache::lonnet::hostname($lonhost);          my $hostname = &Apache::lonnet::hostname($lonhost);
         if (!$hostname) { $hostname = $r->hostname(); }          if (!$hostname) { $hostname = $r->hostname(); }
Line 90  sub handler { Line 91  sub handler {
             $hostname = $alias;              $hostname = $alias;
         }          }
         my $dest = $protocol.'://'.$hostname.$target;          my $dest = $protocol.'://'.$hostname.$target;
         if ($r->args ne '') {          if ($target eq '/adm/login') {
             $dest .= (($dest=~/\?/)?'&':'?').$r->args;               my $querystring = &set_token($r,$lonhost);
         }               if ($querystring ne '') {
         unless (($uri eq '/adm/roles') || ($uri eq '/adm/logout')) {                   $dest .= '?'.$querystring;
             if ($target eq '/adm/login') {               }
                 unless ($ENV{'QUERY_STRING'} =~ /firsturl=/) {          } else {
                     $dest.=(($dest=~/\?/)?'&':'?').'firsturl='.$uri;              my $uri = $r->uri;
                 }              if ($r->args ne '') {
             } else {                  $dest .= (($dest=~/\?/)?'&':'?').$r->args;
                 unless ($ENV{'QUERY_STRING'} =~ /origurl=/) {              }
               unless (($uri eq '/adm/roles') || ($uri eq '/adm/logout')) {
                   unless ($r->args =~ /origurl=/) {
                     $dest.=(($dest=~/\?/)?'&':'?').'origurl='.$uri;                      $dest.=(($dest=~/\?/)?'&':'?').'origurl='.$uri;
                 }                  }
             }              }
               if ($uri =~ m{^/tiny/$match_domain/\w+$}) {
                   unless (($r->args =~ /ltoken=/) || ($r->args =~ /linkkey=/)) {
                       &Apache::lonacc::get_posted_cgi($r,['linkkey']);
                       if ($env{'form.linkkey'} ne '') {
                           $dest.=(($dest=~/\?/)?'&':'?').'linkkey='.$env{'form.linkkey'};
                       }
                   }
               }
         }          }
         $r->header_out(Location => $dest);          $r->header_out(Location => $dest);
         return REDIRECT;          return REDIRECT;
Line 111  sub handler { Line 122  sub handler {
     }      }
 }  }
   
   sub set_token {
       my ($r,$lonhost) = @_;
       my ($firsturl,$querystring,$ssotoken,@names,%token);
       @names = ('role','symb','ltoken','linkkey');
       map { $token{$_} = 1; } @names;
       unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/logout')) {
           $firsturl = $r->uri;
       }
       if ($r->args ne '') {
           &Apache::loncommon::get_unprocessed_cgi($r->args);
       }
       if ($r->uri =~ m{^/tiny/$match_domain/\w+$}) {
           unless (($env{'form.ltoken'}) || ($env{'form.linkkey'})) {
               &Apache::lonacc::get_posted_cgi($r,['linkkey']);
           }
       }
       my $extras;
       foreach my $name (@names) {
           if ($env{'form.'.$name} ne '') {
               if ($name eq 'ltoken') {
                   my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
                   if ($info{'linkprot'}) {
                       $extras .= '&linkprot='.&escape($info{'linkprot'});
                       last;
                   }
               } else {
                   $extras .= '&'.$name.'='.&escape($env{'form.'.$name});
               }
           }
       }
       if (($firsturl ne '') || ($extras ne '')) {
           $extras .= ':sso';
           $ssotoken = &Apache::lonnet::reply('tmpput:'.&escape($firsturl).
                                              $extras,$lonhost);
           $querystring = 'sso='.$ssotoken;
       }
       if ($r->args ne '') {
           foreach my $key (sort(keys(%env))) {
               if ($key =~ /^form\.(.+)$/) {
                   my $name = $1;
                   next if ($token{$name});
                   $querystring .= '&'.$name.'='.$env{$key};
               }
           }
       }
       return $querystring;
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.10  
changed lines
  Added in v.1.11


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>