Skip to content

Commit

Permalink
Item12056: CasLogin shows template auth screen if a logged in user na…
Browse files Browse the repository at this point in the history
…vigates to it

git-svn-id: http://svn.foswiki.org/trunk/CasLoginContrib@15342 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Aug 29, 2012
1 parent e5bcf41 commit a444d21
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions data/System/CasLoginContrib.txt
Expand Up @@ -51,6 +51,7 @@ This is a re-write of the TWiki CASLogin work done by Greg Abbas, Charlie Reitsm
| Author(s): | Foswiki:Main.SvenDowideit |
| Copyright: | © SvenDowideit@fosiki.com |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL 3 (Gnu General Public License)]] |
| Aug 2012 | 1.6.2 - Item12056: CasLogin shows template auth screen if a logged in user navigates to it |
| Aug 2012 | 1.6.1 - quick fix for Foswiki::Tasks.Item12054: recursion in CasLogin if access is denied to the user that has just logged in |
| Aug 2012 | initial release of the third re-implementation |
| Release: | %$RELEASE% |
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/CasLoginContrib.pm
Expand Up @@ -31,7 +31,7 @@ our $VERSION = '$Rev$'; # version of *this file*.
# date - a date in 1 Jun 2009 format. Three letter English month names only.
# Note: it's important that this string is exactly the same in the extension
# topic - if you use %$RELEASE% with BuildContrib this is done automatically.
our $RELEASE = '1.6.1';
our $RELEASE = '1.6.2';

our $SHORTDESCRIPTION = 'CAS SSO Login for foswiki';

42 changes: 29 additions & 13 deletions lib/Foswiki/LoginManager/CasLogin.pm
Expand Up @@ -82,25 +82,32 @@ sub loadSession {

# LoginManager::loadSession does a redirect on logout, so we have to deal with (CAS) logout before it.
my $authUser = $this->SUPER::loadSession();
my $uri = Foswiki::Func::getUrlHost() . $query->uri();

#print STDERR "hello : $authUser\n";
#print STDERR "params: ".join(', ', $query->param())."\n";
#print STDERR "uri: ".Foswiki::Func::getUrlHost().$query->uri()."\n";
#print STDERR "uri: $uri\n";
#print STDERR "relative ".$query->url(-relative=>1);
#print STDERR "full ".$query->url(-full=>1);
#print STDERR "query ".$query->url(-query=>1);
#check returned ticket
if ( defined($ticket) ) {
my $uri = Foswiki::Func::getUrlHost() . $query->uri();
$uri =~ s/[?;&]ticket=.*$//;
$authUser = $this->{CAS}->validateST( $uri, $ticket );

# print STDERR "login? $authUser => $ticket\n";
#TODO: protect against auth as basemapper admin?
my $casUser = $this->{CAS}->validateST( $uri, $ticket );
if ($casUser) {
$authUser = $casUser;
# print STDERR "login? $authUser => $ticket\n";
#TODO: protect against auth as basemapper admin?

#if its an email address, we can make the generated wikiname more usefull
$authUser =~ s/(\.|@)(.)/$1.uc($2)/ge;
$authUser = ucfirst($authUser);
$authUser =~ s/(\.|@)(.)/$1.uc($2)/ge;
$authUser = ucfirst($authUser);

$this->userLoggedIn($authUser);
my $origurl = $query->param('foswiki_origin');
$this->userLoggedIn($authUser);
} else {
# a bad ticket - so ignore
# its a bit difficult if its a resubmit of an old ticket to the login script :/
}
}
else {
if ( defined( $query->param('sudo') )
Expand All @@ -112,8 +119,14 @@ sub loadSession {
$this->userLoggedIn($authUser);
}
else {
if ( $foswiki->inContext('login') ) {
$this->forceAuthentication();
if ( $foswiki->inContext('login') || $foswiki->inContext('logon') )
{
if ( !$this->forceAuthentication() ) {
my $full = $query->url(-full=>1);
$uri =~ s/^$full//;
$uri = Foswiki::Func::getScriptUrl(undef, undef, 'view').$uri;
$foswiki->redirect( $uri, 0 );
}
}
}
}
Expand All @@ -133,8 +146,11 @@ Triggered on auth fail
sub forceAuthentication {
my $this = shift;
my $session = $this->{session};
my $query = $session->{request};

if ( !$session->inContext('authenticated') && !defined($query->param('ticket'))) {
if ( !$session->inContext('authenticated')
&& !defined( $query->param('ticket') ) )
{
$session->redirect( $this->loginUrl(), 0 );
return 1;
}
Expand Down

0 comments on commit a444d21

Please sign in to comment.