File:  [LON-CAPA] / loncom / auth / lonshibacc.pm
Revision 1.2: download - view: text, annotated - select for diffs
Fri Jan 23 15:57:27 2015 UTC (9 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, HEAD
- Shibboleth SSO - regexp used for extraction of <username> from eppn
  (for which format is <username>@somewhere.edu) made consistent with
  $LONCAPA::match_username regexp (aside from @ separator).

# The LearningOnline Network
# Authorization handler for Shibboleth authenticated users
#
# $Id: lonshibacc.pm,v 1.2 2015/01/23 15:57:27 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#

=head1 NAME

Apache::lonshibacc - Authorization handler if Shibboleth-authenticated

=head1 SYNOPSIS

Invoked for /adm/sso by
/etc/httpd/conf/loncapa_apache.conf:

PerlAuthzHandler       Apache::lonshibacc

=head1 INTRODUCTION

Authorization handler used to remove trailing @internet dom
from Shibboleth authenticated username (e.g., @mit.edu).

After making change to $r->user, will return DECLINE so
lonacc.pm can be invoked as the next authorization handler.

PerlAuthzHandler       Apache::lonacc

=head1 HANDLER SUBROUTINE

This routine is called by Apache and mod_perl.

=cut

package Apache::lonshibacc;

use strict;
use lib '/home/httpd/lib/perl/';
use Apache::lonnet;
use Apache::Constants qw(:common);
use LONCAPA qw(:DEFAULT);

sub handler {
    my $r = shift;
    my $user = $r->user;
    if ($user ne '') {
        my $udom = $r->dir_config('lonSSOUserDomain');
        if ($udom eq '') {
            $udom = $r->dir_config('lonDefDomain');
        }
        if ($udom ne '') {
            my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
            my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
            if ($user =~ /^(\w[a-zA-Z0-9_\-.]+)\@\Q$uint_dom\E$/i) {
                my $username = $1;
                $user = $r->user($username);
            }
        }
    }
    return DECLINED;
}

1;
__END__

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