ClearPress

 view release on metacpan or  search on metacpan

cgi-bin/login  view on Meta::CPAN

			     );
    $decor->username(q[]);
    print qq[Set-Cookie: $cookie\n];
    print $decor->header();
    print login_form($decor);
    print $decor->footer();
    return 1;
  }

  my $authenticator = ClearPress::authenticator::passwd->new();
  my $user_info     = $authenticator->authen_credentials({
							  username => $username,
							  password => $password,
							 });

  if($user_info) {
    $decor->username($username);
    my $session = ClearPress::authenticator::session->new();
    my $encoded = $session->encode_token($user_info);

    my $auth_cookie = $cgi->cookie(

lib/ClearPress/authenticator/db.pm  view on Meta::CPAN

    $self->{cipher} = $v;
  }

  if($self->{cipher}) {
    return $self->{cipher};
  }

  return $DEFAULT_CIPHER;
}

sub authen_credentials {
  my ($self, $ref) = @_;

  if(!$ref ||
     !$ref->{username} ||
     !$ref->{password} ) {
    return;
  }

  my $dbh     = $self->dbh();
  my $table   = $self->table;

lib/ClearPress/authenticator/db.pm  view on Meta::CPAN

=head2 cipher - get/set accessor for encryption function name

  $oDBAuth->cipher('sha1');
  my $sCipher = $oDBAuth->cipher();

=head2 dbh - get/set accessor for database handle to use for query

  $oDBAuth->dbh($oDBH);
  my $oDBH = $oDBAuth->dbh();

=head2 authen_credentials - attempt to authenticate against database using given username & password

  my $hrAuthenticated = $oDBAuth->authen_credentials({username => $sUsername, password => $sPassword});

  returns undef or hashref

=head1 DIAGNOSTICS

=head1 CONFIGURATION AND ENVIRONMENT

=head1 DEPENDENCIES

=over

lib/ClearPress/authenticator/ldap.pm  view on Meta::CPAN

sub _ldap {
  my $self = shift;

  if(!$self->{_ldap}) {
    $self->{_ldap} = Net::LDAP->new($self->server);
  }

  return $self->{_ldap};
}

sub authen_credentials {
  my ($self, $ref) = @_;

  if(!$ref ||
     !$ref->{username} ||
     !$ref->{password} ) {
    return;
  }

  my $ldap = $self->_ldap;
  if(!$ldap) {

lib/ClearPress/authenticator/ldap.pm  view on Meta::CPAN

=head2 server - server url (ldaps://ldap.local)

  my $sLDAPServer = $oLDAP->server();

=head2 ad_domain - Active Directory Domain (WORKGROUP)

  my $ad_domain = $oLDAP->ad_domain();

=head2 _ldap - Net::LDAP object

=head2 authen_credentials - attempt to authenticate against LDAP/AD using given username & password

  my $hrAuthenticated = $oLDAP->authen_credentials({username => $sUsername, password => $sPassword});

  returns undef or hashref

=head1 DIAGNOSTICS

=head1 CONFIGURATION AND ENVIRONMENT

=head1 DEPENDENCIES

=over

lib/ClearPress/authenticator/passwd.pm  view on Meta::CPAN

# Author: rmp
#
package ClearPress::authenticator::passwd;
use strict;
use warnings;
use base qw(ClearPress::authenticator);
use Carp;

our $VERSION = q[477.1.4];

sub authen_credentials {
  my ($self, $ref) = @_;

  if(!$ref ||
     !$ref->{username} ||
     !$ref->{password} ) {
    return;
  }

  my ($name, $passwd) = getpwnam $ref->{username};
  if(!$name) {

lib/ClearPress/authenticator/passwd.pm  view on Meta::CPAN

=head1 VERSION

$LastChangedRevision: 470 $

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 SUBROUTINES/METHODS

=head2 authen_credentials - attempt to authenticate against passwd/NIS using given username & password

  my $hrAuthenticated = $oPasswd->authen_credentials({username => $sUsername, password => $sPassword});

  returns undef or hashref

=head1 DIAGNOSTICS

=head1 CONFIGURATION AND ENVIRONMENT

=head1 DEPENDENCIES

=over

lib/ClearPress/util.pm  view on Meta::CPAN


  delete $INSTANCES->{$singleton_key};

  if(exists $self->{dbh}) {
    $self->{dbh}->disconnect();
  }

  return 1;
}

sub db_credentials {
  my $self      = shift;
  my $cfg       = $self->config();
  my $dbsection = $self->dbsection();
  my $ref       = {};

  for my $field (qw(dbuser dbpass dbhost dbport dbname dsn_opts)) {
    $ref->{$field} = $cfg->val($dbsection, $field);
  }

  return $ref;
}

sub dbname {
  my $self = shift;
  return $self->db_credentials->{dbname};
}

sub dbuser {
  my $self = shift;
  return $self->db_credentials->{dbuser};
}

sub dbpass {
  my $self = shift;
  return $self->db_credentials->{dbpass};
}

sub dbhost {
  my $self = shift;
  return $self->db_credentials->{dbhost};
}

sub dbport {
  my $self = shift;
  return $self->db_credentials->{dbport};
}

sub dsn_opts {
  my $self = shift;
  return $self->db_credentials->{dsn_opts};
}

END {
  # dereferences and causes orderly destruction of all instances
  my $cap = IO::Capture::Stderr->new();
  $cap->start;
  undef $INSTANCES;
  $cap->stop;
  while(my $line = $cap->read()) {
    if($line =~ /MySQL[ ]server[ ]has[ ]gone[ ]away/smix) { # brute force do not display these copious, noisy warnings

lib/ClearPress/util.pm  view on Meta::CPAN

  my $oRequestingUser = $oUtil->requestor();

=head2 log - Formatted debugging output to STDERR

  $oUtil->log(@aMessages);

=head2 cleanup - housekeeping stub for subclasses - called when response has completed processing

  $oUtil->cleanup();

=head2 db_credentials - hashref of database connection info from the current dbsection

  my $hrDBHInfo = $oUtil->db_credentials();

=head2 dbname - database name from db_credentials

  my $sDBName = $oUtil->dbname();

=head2 dbuser - database user from db_credentials

  my $sDBUser = $oUtil->dbuser();

=head2 dbpass - database pass from db_credentials

  my $sDBPass = $oUtil->dbpass();

=head2 dbhost - database host from db_credentials

  my $sDBHost = $oUtil->dbhost();

=head2 dbport - database port from db_credentials

  my $sDBPort = $oUtil->dbport();

=head2 dsn_opts - database dsn settings from db_credentials

  my $sDBDSNOptions = $oUtil->dsn_opts();

=head1 DIAGNOSTICS

=head1 CONFIGURATION AND ENVIRONMENT

=head1 DEPENDENCIES

=over

t/authenticator/db-sha1.t  view on Meta::CPAN

};

our $PKG = 'ClearPress::authenticator::db';
use ClearPress::authenticator::db;
my $util = t::util->new();
my $dbh  = $util->dbh();

{
  $dbh->do(q[CREATE TABLE user(username,pass)]);
  my $auth = $PKG->new({dbh=>$dbh});
  is($auth->authen_credentials({
				username => 'missing',
				password => 'something',
			       }), undef, 'unknown user');
  $dbh->do(q[DROP TABLE user]);
}

{
  my $crypt = Digest::SHA::sha1_hex('notthesame');
  $dbh->do(q[CREATE TABLE user(username,pass)]);
  $dbh->do(qq[INSERT INTO user(username,pass) VALUES('dummyuser','$crypt')]);
  my $auth = $PKG->new({dbh => $dbh});
  my $ref  = {
	      username => 'dummyuser',
	      password => 'dummypass',
	     };
  my $result = $auth->authen_credentials($ref);
  is_deeply($result, undef, 'valid user, bad password');
  $dbh->do(q[DROP TABLE user]);
}

{
  my $crypt = Digest::SHA::sha1_hex('dummy');
  $dbh->do(q[CREATE TABLE user(username,pass)]);
  $dbh->do(qq[INSERT INTO user(username,pass) VALUES('dummyuser','$crypt')]);
  my $auth = $PKG->new({dbh => $dbh});
  my $ref  = {
	      username => 'dummyuser',
	      password => 'dummy',
	     };
  my $result = $auth->authen_credentials($ref);
  is_deeply($result, $ref, 'valid user');
  $dbh->do(q[DROP TABLE user]);
}

t/authenticator/db.t  view on Meta::CPAN

# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
# vim:ts=8:sw=2:et:sta:sts=2
use strict;
use warnings;
use Test::More tests => 7;
use lib qw(t/lib);
use t::util;

our $PKG = 'ClearPress::authenticator::db';
use_ok($PKG);
can_ok($PKG, qw(new authen_credentials));

my $util = t::util->new();

{
  my $auth = $PKG->new();
  isa_ok($auth, $PKG);
  isa_ok($auth, 'ClearPress::authenticator');
}

{
  my $auth = $PKG->new();
  is($auth->authen_credentials(), undef, 'no creds');
}

{
  my $auth = $PKG->new();
  is($auth->authen_credentials({username => 'dummy'}), undef, 'no password');
}

{
  my $auth = $PKG->new();
  is($auth->authen_credentials({password => 'dummy'}), undef, 'no username');
}

t/authenticator/ldap.t  view on Meta::CPAN


{
  my $ldap      = $PKG->new();
  my $connector = $ldap->_ldap();
  is_deeply($connector->{constructor_args}, [qw(ldaps://ldap.local:636)], 'connector construction');
  is_deeply($ldap->_ldap(), $connector, 'cached connector');
}

{
  my $ldap = $PKG->new;
  is($ldap->authen_credentials(), undef, 'auth no args');
  is($ldap->authen_credentials({username => 'bob'}), undef, 'auth no password');
  is($ldap->authen_credentials({password => 'passw0rd'}), undef, 'auth no username');
}

{
  no warnings qw(once);
  my $ldap = $PKG->new;
  eval {
    local $Net::LDAP::CONSTRUCTOR_FAIL = 1;
    $ldap->authen_credentials({username => 'bob', password => 'pass'});
  };
  like($EVAL_ERROR, qr/Failed[ ]to[ ]connect/smx, 'ldap connection failure');
}

{
  my $ref  = {
	      username => 'bob',
	      password => 'pass',
	     };
  my $ldap = $PKG->new;
  my $state;
  eval {
    local $Net::LDAP::BIND_CODE  = undef;
    local $Net::LDAP::BIND_ERROR = 'no bind error';

    $state = $ldap->authen_credentials($ref);
  };
  unlike($EVAL_ERROR, qr/Failed[ ]to[ ]connect/smx, 'no ldap connection failure');
  is_deeply($state, $ref, 'authentication pass');
}

{
  my $ref  = {
	      username => 'bob',
	      password => 'pass',
	     };
  my $ldap = $PKG->new;
  my $cap = IO::Capture::Stderr->new;
  $cap->start;
  my $state;
  eval {
    local $Net::LDAP::BIND_CODE  = 1;
    local $Net::LDAP::BIND_ERROR = 'bind error number 1';

    $state = $ldap->authen_credentials($ref);
  };
  $cap->stop;
  is($state, undef, 'authentication fail');
}

t/authenticator/passwd.t  view on Meta::CPAN

    if($name eq 'dummyuser') {
      return qw(dummyuser du2M/eJoAA/Ak 1809244410 1139001599 0  Roger Pettett /Users/rpettett /bin/bash 0);
    }

    return ();
  };
}

our $PKG = 'ClearPress::authenticator::passwd';
use_ok($PKG);
can_ok($PKG, qw(new authen_credentials));

{
  my $auth = $PKG->new();
  isa_ok($auth, $PKG);
  isa_ok($auth, 'ClearPress::authenticator');
}

{
  my $auth = $PKG->new();
  is($auth->authen_credentials(), undef, 'no creds');
}

{
  my $auth = $PKG->new();
  is($auth->authen_credentials({username => 'dummy'}), undef, 'no password');
}

{
  my $auth = $PKG->new();
  is($auth->authen_credentials({password => 'dummy'}), undef, 'no username');
}


{
  my $auth = $PKG->new();
  is($auth->authen_credentials({
				username => 'missing',
				password => 'something',
			       }), undef, 'unknown user');
}

{
  my $auth = $PKG->new();
  my $ref  = {
	      username => 'dummyuser',
	      password => 'dummypass',
	     };
  my $result = $auth->authen_credentials($ref);
  is_deeply($result, undef, 'valid user, bad password');
}

{
  my $auth = $PKG->new();
  my $ref  = {
	      username => 'dummyuser',
	      password => 'dummy',
	     };
  my $result = $auth->authen_credentials($ref);
  is_deeply($result, $ref, 'valid user');
}



( run in 0.289 second using v1.01-cache-2.11-cpan-4d50c553e7e )