App-Context

 view release on metacpan or  search on metacpan

lib/App/Authentication.pm  view on Meta::CPAN

App::Authentication - Interface for authentication and authorization

=head1 SYNOPSIS

    use App;

    $context = App->context();
    $authentication = $context->service("Authentication");  # or ...
    $authentication = $context->authentication();

    if ($authentication->validate_password($username, $password)) {
       ...
    }

=head1 DESCRIPTION

An Authentication service is a means by which a user may be authenticated.

=cut

#############################################################################

lib/App/Authentication.pm  view on Meta::CPAN


#############################################################################
# PUBLIC METHODS
#############################################################################

=head1 Public Methods:

=cut

#############################################################################
# validate_password()
#############################################################################

=head2 validate_password()

    * Signature: $username = $auth->validate_password();
    * Param:     void
    * Return:    $username        string
    * Throws:    App::Exception::Authentication
    * Since:     0.01

    Sample Usage:

    $username = $auth->validate_password();

=cut

sub validate_password {
    my ($self, $username, $password) = @_;
    return(1);
}

#############################################################################
# Method: service_type()
#############################################################################

=head2 service_type()

    * Signature: $service_type = App::Authentication->service_type();

lib/App/Authentication/Htpasswd.pm  view on Meta::CPAN

App::Authentication::Htpasswd - Interface for authentication using an htpasswd file

=head1 SYNOPSIS

    use App;

    $context = App->context();
    $authentication = $context->service("Authentication");  # or ...
    $authentication = $context->authentication();

    if ($authentication->validate_password($username, $password)) {
       ...
    }

=head1 DESCRIPTION

An App::Authentication::Htpasswd service is a means by which a user may be authenticated
using an htpasswd file.

=cut

#############################################################################
# PUBLIC METHODS
#############################################################################

=head1 Public Methods:

=cut

#############################################################################
# validate_password()
#############################################################################

=head2 validate_password()

    * Signature: $username = $auth->validate_password();
    * Param:     void
    * Return:    $username        string
    * Throws:    App::Exception::Authentication
    * Since:     0.01

    Sample Usage:

    $username = $auth->validate_password();

=cut

sub validate_password {
    &App::sub_entry if ($App::trace);
    my ($self, $username, $password) = @_;
    my $valid = 0;

    my $context = $self->{context};
    my $htpasswd_file = $context->get_option("htpasswd_file");

    if (-e $htpasswd_file) {
        my ($uname, $pword);
        if (open(PFILE, "< $htpasswd_file")) {
            while (<PFILE>) {
                chomp;
                ($uname, $pword) = split(/:/);
                last if ($uname eq $username);
                $uname = "";
            }
            close(PFILE);
            if ($uname) {
                my $crypt = crypt($password, $pword);
                $valid = ($pword eq $crypt) ? 1 : 0;
            }
        }
    }
    &App::sub_exit($valid) if ($App::trace);
    return($valid);
}

=head1 ACKNOWLEDGEMENTS

lib/App/Context/HTTP.pm  view on Meta::CPAN

sub user {
    &App::sub_entry if ($App::trace);
    my $self = shift;
    my $user = $self->{effective_user} || $self->{user};

    if (!$user) {
        my $options = $self->{options};
        my ($effective_user);
        my $authenticated = 0;
        if ($options->{app_auth_required}) {
            # Bypass Basic Authentication, /../..?u=username&p=password
            my $password = $self->so_get("default","p");
            $user = $self->so_get("default","u");

            if (defined $password && defined $user) {
                my $authentication = $self->authentication();
                if ( $authentication->validate_password($user, $password) ) {
                    $authenticated = 1;
                    $effective_user = $self->so_get("default","eu");
                }
            }
        }
        else {
            $user = $self->request()->user();

            my $p_pass = $self->so_get("default","p");
            my $u_user = $self->so_get("default","u");
            if (defined $p_pass && defined $u_user) {
                my $authentication = $self->authentication();
                if ( $authentication->validate_password($u_user, $p_pass) ) {
                    $authenticated = 1;
                    $user = $self->so_get("default","u");
                    $effective_user = $self->so_get("default","u");
                }
                else {
                    $user = 'guest';
                    $effective_user = 'guest';
                }
            }

lib/App/adminguide/cvs.pod  view on Meta::CPAN

Then I ran the same commands in my current shell to set CVSROOT for
the current session.

=head2 Initializing the CVS Repository

I initialized the CVS Repository (/usr/mycompany/cvs).

  su - cvs
  cvs init

Then I created the CVS password file.

  cd ~
  mkdir src
  cd src
  cvs co CVSROOT
  cd CVSROOT
  touch passwd
  cvs add passwd
  cvs update
  cvs commit -m "new" passwd

lib/App/installguide.pod  view on Meta::CPAN

Try one of the other methods.

=head2 Get App from CVS (to develop App)

You should use this method if you *do* have commit access
on the App CVS repository.  (Note, substitute your CVS
user id for "LOGIN" below.)

  cd $PREFIX/src
  cvs -d :pserver:LOGIN@cvs.perl.org:/cvs/public login
  [enter your perl.org password]
  cvs -d :pserver:LOGIN@cvs.perl.org:/cvs/public co p5ee

Later, when you want to refresh your directory with the latest software
from CVS, you can repeat the same commands or you can do the following.

  cd $PREFIX/src/p5ee
  cvs update -dP

See a CVS document to find out how to create, delete, and modify files
and then submit changes.

=head2 Get App from CVS (anonymous, read-only access to latest App)

You should use this method if you do *not* have commit access
on the App CVS repository but you do want to stay up to date with the
latest App software (recommended, because there are no releases yet).

  cd $PREFIX/src
  cvs -d :pserver:anonymous@cvs.perl.org:/cvs/public login
  [press enter at the password prompt]
  cvs -d :pserver:anonymous@cvs.perl.org:/cvs/public co p5ee

Later, when you want to refresh your directory with the latest software
from CVS, you can repeat the same commands or you can do the following.

  cd $PREFIX/src/p5ee
  cvs update -dP

The "cvs update" method is the preferred way to get updates.

lib/App/installguide/hosted.pod  view on Meta::CPAN

(This is all just an example of how I did it so that I can refer to this in later
setup documentation.  You will probably do this differently.)

I created three databases: "devel", "test", and "prod".  The control panel
prepended my hosting username, so they ended up being called "username_devel",
"username_test", and "username_prod".

Then I created three users: "dbview", "dbuser", and "dbadmin".  Again, the control
panel prepended my hosting username, so they ended up being called
"username_dbview", "username_dbuser", and "username_dbadmin".  I gave them
appropriate passwords and recorded what they were for future reference.

Then I went through each combination of database and database-user to assign
permissions to each.  I assigned all permissions to "username_dbadmin",
"select/insert/update/delete" permissions to "username_dbuser" and only "select"
permissions to "username_dbview".

I was then able to use the web-based database administration tool, "phpMyAdmin".
However, I prefer to do things from the command line.

The next thing I did was put my MySQL login credentials into the $HOME/.my.cnf file.

   [client]
   user            = username_dbadmin
   password        = my_password_here
   host            = localhost

   [mysql]
   database        = username_devel

Then it is *very* important to set the permissions on this file.

   chmod 600 $HOME/.my.cnf

This will keep anyone from reading the contents of the file (which contains your 
database password). Then you should be able to log in directly with the mysql
command line client.  Some sample commands are shown, but it is assumed that
you will read the MySQL documentation and know what you are doing.

   # mysql
   Welcome to the MySQL monitor.  Commands end with ; or \g.
   Your MySQL connection id is 1742668 to server version: 4.1.20-standard-log

   Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

   mysql> \s                             # show connection status

lib/App/installguide/hosted.pod  view on Meta::CPAN

It can be thought of as a "deployment descriptor".

For our purposes, the only thing unique about our installation
is the database connection information.

   vi $PREFIX/etc/app/app.conf

      dbhost = localhost
      dbname = username_prod
      dbuser = username_dbuser
      dbpass = my_password_here

   chmod 600 $PREFIX/etc/app/app.conf

=head2 CREATE app.pl

The "app.pl" file is the Application Configuration file.
This is where you define (and assemble) Services (i.e. components)
in the App::Context framework.

When an application is developed, a file like "app.pl" is part of the source

lib/App/installguide/win32.pod  view on Meta::CPAN

Use a version of MySQL which is compatible with your Apache setup.

  http://dev.mysql.com/downloads/
  http://dev.mysql.com/doc/refman/5.0/en/windows-installation.html

On March 13, 2006, the latest version of MySQL is 5.0.19.
I download and install the "Windows Essentials (x86)" binary distribution.

  http://dev.mysql.com/downloads/mysql/5.0.html

Based on whatever password you entered in the configuration (instead of
"xyzabc" shown below), enter something like the following in a new file
named "C:\windows\my.cnf".

  [client]
  host            = localhost
  port            = 3306
  user            = root
  password        = xyzabc
  [mysql]
  database        = test

Then from the Windows command shell, you can type "mysql" and get
in to the database directly.

=head1 APACHE AND MOD_PERL: METHOD 1

I recommend the all-in-one Apache/mod_perl/PHP/phpMyAdmin approach.

lib/App/quickstart.pod  view on Meta::CPAN

          },
          dbname => {
              description => "database name",
              required => 1,
          },
          dbuser => {
              description => "database user",
              required => 1,
          },
          dbpass => {
              description => "database password",
              required => 1,
          },
      },
  );
  use App;
  use App::Repository;
  {
      my $context = $App->context();
      my $db = $context->repository();
      # perform database ops like ...

lib/App/quickstart.pod  view on Meta::CPAN

          },
          dbname => {
              description => "database name",
              required => 1,
          },
          dbuser => {
              description => "database user",
              required => 1,
          },
          dbpass => {
              description => "database password",
              required => 1,
          },
          customer_id => {
              description => "the ID of the customer to check",
              required => 1,
              type => "integer",
          },
      },
  );
  use App;



( run in 2.061 seconds using v1.01-cache-2.11-cpan-49f99fa48dc )