CGI-Application-Plugin-RequireSSL-0.04/0000755000076400007640000000000010645302352017060 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/lib/0000755000076400007640000000000010645302352017626 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/lib/CGI/0000755000076400007640000000000010645302352020230 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/lib/CGI/Application/0000755000076400007640000000000010645302352022473 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/lib/CGI/Application/Plugin/0000755000076400007640000000000010645302352023731 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/lib/CGI/Application/Plugin/RequireSSL.pm0000644000076400007640000001550510645302157026276 0ustar dhornedhornepackage CGI::Application::Plugin::RequireSSL; use warnings; use strict; use Carp; use base 'Exporter'; use Attribute::Handlers; our @EXPORT = qw/config_requiressl mode_redirect/; our %SSL_RUN_MODES; use Data::Dumper; =head1 NAME CGI::Application::Plugin::RequireSSL - Force SSL in specified pages or modules =head1 VERSION Version 0.04 =cut our $VERSION = '0.04'; =head1 SYNOPSIS use CGI::Application::Plugin::RequireSSL; sub login_form :RequireSSL { my $self = shift; # etc } =head1 DESCRIPTION CGI::Application::Plugin::RequireSSL allows individual run modes or whole modules to be protected by SSL. If a standard HTTP request is received, you can specify whether an error is raised or if the request should be redirected to the HTTPS equivalent URL. =head1 EXPORT Exported methods: config_requiressl, mode_redirect =head1 USAGE =head2 run mode-level protection run mode protection is specified by the RequireSSL attribute after the method name: sub process_login :RequireSSL { my $self = shift; } =head2 Module-level protection You can protect a complete module by setting the 'require_ssl' parameter in your instance script: use MyApp; my $webapp = MyApp->new( PARAMS => {require_ssl => 1} ); $webapp->run(); =head2 Redirecting to a protected URL. By default, an error is raised if a request is made to a protected run mode or module using HTTP. However, you can specify that the request is redirected to the HTTPS url by setting the rewrite_to_ssl parameter as long as the requested method is not POST: my $webapp = MyApp->new( PARAMS => {rewrite_to_ssl => 1} ); =head2 Turning off checks. If you need to turn off checks, simply set the ignore_check parameter when configuring the plugin (see L below). =head2 Reverting to HTTP Once a successful request is made to a protected run mode or module, subsequent requests to a non-protected run mode or module will revert to using HTTP. To prevent this from happening, set the parameter keep_in_ssl in the configuration (see L below) =cut sub import { my $caller = scalar(caller); $caller->add_callback(init => \&_add_runmodes); $caller->add_callback(prerun => \&_check_ssl); goto &Exporter::import; } sub CGI::Application::RequireSSL : ATTR(CODE, BEGIN, CHECK) { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; if ($phase eq 'CHECK') { $SSL_RUN_MODES{*{$symbol}{NAME}}++; } } =head1 METHODS =head2 config_requiressl Optionally configure the plugin in your cgiapp_init method $self->config_requiressl( keep_in_ssl => 0, ignore_check => 0, ) Valid parameters are: =over 4 =item * keep_in_ssl - if set, all subsequent requests following one to a protected run mode or module will be via HTTPS. =item * ignore_check - ignore SSL schecking. This is useful if your application is deployed in an environment that doesn't support SSL. =back =cut sub config_requiressl { my ($self, %args) = @_; foreach my $param (qw/ keep_in_ssl ignore_check/) { $self->{__PACKAGE__ . $param} = $args{$param} if $args{$param}; } } =head2 mode_redirect This is a run mode that will be automatically called if the request should be redirected to the equivalent HTTP or HTTPS URL. You should not call it directly. =cut sub mode_redirect { my $self = shift; my $new_mode = $self->{__PACKAGE__ . 'new_mode'}; croak "Cannot redirect from POST" if $self->query->request_method eq 'POST'; my $new_url = $self->query->url(-base => 1); # Can't rely on -query option in case the query has been played with # prior to the redirect being invoked. Use the REQUEST_URI instead $new_url .= $ENV{REQUEST_URI} if $ENV{REQUEST_URI}; if ($new_mode eq 'https') { $new_url =~ s/^http:/https:/; } else { $new_url =~ s/^https:/http:/; } $self->header_type('redirect'); $self->header_add(-uri => $new_url); return ' '; } sub _add_runmodes { my $self = shift; $self->run_modes([qw/config_requiressl mode_redirect/]); } sub _check_ssl { my $self = shift; my $rm = $self->get_current_runmode; unless ($self->{__PACKAGE__ . 'ignore_check'}) { # Process protection is either the module or the requested run mode # is protected if (($self->param('require_ssl') || $SSL_RUN_MODES{$rm}) && !$self->query->https) { if ($self->param('rewrite_to_ssl')) { $self->{__PACKAGE__ . 'new_mode'} = 'https'; return $self->prerun_mode('mode_redirect'); } else { croak "https request required"; } } # If a request is made using SSL, but we don't need it to be, then # redirect to the non-SSL page if ( $self->query->https && !( $self->{__PACKAGE__ . 'keep_in_ssl'} || $self->param('require_ssl') || $SSL_RUN_MODES{$rm} ) ) { $self->{__PACKAGE__ . 'new_mode'} = 'http'; return $self->prerun_mode('mode_redirect'); } } } =head1 AUTHOR Dan Horne, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 CAVEAT This module been tested under the FastCGI persistent environment, but not under mod_perl. The author would apprecaute feedback from anyone who is able to test with that environment. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc CGI::Application::Plugin::RequireSSL You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS =over 4 =item * Users of the CGI::Application wiki (http://www.cgi-app.org) who requested this module. =item * Andy Grundman - I stole the idea of the keep_in_ssl parameter from his L module =back =head1 COPYRIGHT & LICENSE Copyright 2007 Dan Horne, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of CGI::Application::Plugin::RequireSSL CGI-Application-Plugin-RequireSSL-0.04/Makefile.PL0000644000076400007640000000122010630634651021031 0ustar dhornedhorneuse strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'CGI::Application::Plugin::RequireSSL', AUTHOR => 'Dan Horne ', VERSION_FROM => 'lib/CGI/Application/Plugin/RequireSSL.pm', ABSTRACT_FROM => 'lib/CGI/Application/Plugin/RequireSSL.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'Attribute::Handlers' => 0, 'CGI::Application' => 4.01, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'CGI-Application-Plugin-RequireSSL-*' }, ); CGI-Application-Plugin-RequireSSL-0.04/MANIFEST0000644000076400007640000000037010630633727020220 0ustar dhornedhorneChanges MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/CGI/Application/Plugin/RequireSSL.pm t/01-standard_call.t t/02-protected_rm.t t/03-protected-module.t t/pod-coverage.t t/pod.t t/lib/MyTestApp2.pm t/lib/MyTestApp.pm CGI-Application-Plugin-RequireSSL-0.04/README0000644000076400007640000000276610627246432017761 0ustar dhornedhorneCGI-Application-Plugin-RequireSSL The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. A README file is required for CPAN modules since CPAN extracts the README file from a module distribution so that people browsing the archive can use it get an idea of the modules uses. It is usually a good idea to provide version information here so that people can decide whether fixes for the module are worth downloading. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc CGI::Application::Plugin::RequireSSL You can also look for information at: Search CPAN http://search.cpan.org/dist/CGI-Application-Plugin-RequireSSL CPAN Request Tracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Application-Plugin-RequireSSL AnnoCPAN, annotated CPAN documentation: http://annocpan.org/dist/CGI-Application-Plugin-RequireSSL CPAN Ratings: http://cpanratings.perl.org/d/CGI-Application-Plugin-RequireSSL COPYRIGHT AND LICENCE Copyright (C) 2007 Dan Horne This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. CGI-Application-Plugin-RequireSSL-0.04/t/0000755000076400007640000000000010645302352017323 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/t/lib/0000755000076400007640000000000010645302352020071 5ustar dhornedhorneCGI-Application-Plugin-RequireSSL-0.04/t/lib/MyTestApp.pm0000644000076400007640000000044010627262572022324 0ustar dhornedhornepackage MyTestApp; use base 'CGI::Application'; use CGI::Application::Plugin::RequireSSL; sub setup { my $self = shift; $self->start_mode('mode1'); $self->run_modes([qw/mode1 mode2/]); } sub mode1 : RequireSSL { 'called mode1'; } sub mode2 { 'called mode2'; } 1; CGI-Application-Plugin-RequireSSL-0.04/t/lib/MyTestApp2.pm0000644000076400007640000000061410627265732022412 0ustar dhornedhornepackage MyTestApp2; use base 'CGI::Application'; use CGI::Application::Plugin::RequireSSL; sub cgiapp_init { my $self = shift; $self->config_requiressl( ignore_check => 1, ) } sub setup { my $self = shift; $self->start_mode('mode1'); $self->run_modes([qw/mode1 mode2/]); } sub mode1 : RequireSSL { 'called mode1'; } sub mode2 { 'called mode2'; } 1; CGI-Application-Plugin-RequireSSL-0.04/t/pod-coverage.t0000644000076400007640000000025410627363426022075 0ustar dhornedhorne#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); CGI-Application-Plugin-RequireSSL-0.04/t/01-standard_call.t0000644000076400007640000000057010627263260022527 0ustar dhornedhorne#!perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use MyTestApp; use Test::More tests => 1; $ENV{CGI_APP_RETURN_ONLY} = 1; $ENV{REQUEST_METHOD} = 'GET'; $ENV{QUERY_STRING} = 'rm=mode2'; use CGI; my $q = new CGI; { my $testname = "Standard call"; my $app = new MyTestApp(QUERY=>$q); my $t = $app->run; ok ($t =~ /called mode2/, $testname); } CGI-Application-Plugin-RequireSSL-0.04/t/02-protected_rm.t0000644000076400007640000000114510645301735022423 0ustar dhornedhorne#!perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use MyTestApp; use Test::More tests => 2; $ENV{CGI_APP_RETURN_ONLY} = 1; $ENV{REQUEST_METHOD} = 'GET'; $ENV{QUERY_STRING} = 'rm=mode1'; use CGI; my $q = new CGI; { my $testname = "Test RequireSSL in CGI::App class"; my $app = new MyTestApp(QUERY=>$q); my $t; eval {$t = $app->run}; ok ($@ =~ /https request required/, $testname); } { my $testname = "Test RewriteSSL in CGI::App class"; my $app = new MyTestApp(QUERY=>$q, PARAMS => {rewrite_to_ssl => 1}); my $t = $app->run; ok ($t =~ /Status:\s+302\s/, $testname); } CGI-Application-Plugin-RequireSSL-0.04/t/pod.t0000644000076400007640000000021410627246432020275 0ustar dhornedhorne#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); CGI-Application-Plugin-RequireSSL-0.04/t/03-protected-module.t0000644000076400007640000000172710645302036023212 0ustar dhornedhorne#!perl use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use MyTestApp; use MyTestApp2; use Test::More tests => 3; $ENV{CGI_APP_RETURN_ONLY} = 1; $ENV{REQUEST_METHOD} = 'GET'; $ENV{QUERY_STRING} = 'rm=mode2'; use CGI; my $q = new CGI; { my $testname = "Module requires SSL"; my $app = new MyTestApp(QUERY => $q, PARAMS => {require_ssl => 1}); my $t; eval { $t = $app->run }; ok($@ =~ /https request required/, $testname); } { my $testname = "Module requires SSL, Request rewritten"; my $app = new MyTestApp( QUERY => $q, PARAMS => {require_ssl => 1, rewrite_to_ssl => 1} ); my $t = $app->run; ok($t =~ /Status:\s+302\s/, $testname); } { my $testname = "Module requires SSL, Explicitly ignore check"; my $app = new MyTestApp2( QUERY => $q, PARAMS => {require_ssl => 1, rewrite_to_ssl => 1} ); my $t = $app->run; ok($t =~ /called mode2/, $testname); } CGI-Application-Plugin-RequireSSL-0.04/Changes0000644000076400007640000000051510645302236020355 0ustar dhornedhorneRevision history for CGI-Application-Plugin-RequireSSL 0.04 12 July 2007 Changed the check for a 302 response in the tests 0.03 04 June 2007 Added CGI::Application prerequisite 0.02 01 June 2007 Removed backup test file 0.01 31 May 2007 First version, released on an unsuspecting world. CGI-Application-Plugin-RequireSSL-0.04/META.yml0000644000076400007640000000072010645302352020330 0ustar dhornedhorne# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: CGI-Application-Plugin-RequireSSL version: 0.04 version_from: lib/CGI/Application/Plugin/RequireSSL.pm installdirs: site requires: Attribute::Handlers: 0 CGI::Application: 4.01 Test::More: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17