[Catalyst-commits] r7018 - in trunk/Catalyst-Plugin-Authentication-Store-LDAP: . lib/Catalyst/Plugin/Authentication/Store lib/Catalyst/Plugin/Authentication/Store/LDAP t

karpet at dev.catalyst.perl.org karpet at dev.catalyst.perl.org
Tue Oct 16 19:31:10 GMT 2007


Author: karpet
Date: 2007-10-16 19:31:09 +0100 (Tue, 16 Oct 2007)
New Revision: 7018

Added:
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/01-pre_realms_api.t
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/02-realms_api.t
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod-coverage.t
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod.t
Removed:
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/simple.t
Modified:
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/META.yml
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/Makefile.PL
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/TODO
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP.pm
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/Backend.pm
   trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/User.pm
Log:
Added realms API patches and accompanying test. Added standard POD
tests, and the POD they carped about. Renamed the simple test to reflect
that it actually tests the pre-realms API.


Modified: trunk/Catalyst-Plugin-Authentication-Store-LDAP/META.yml
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/META.yml	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/META.yml	2007-10-16 18:31:09 UTC (rev 7018)
@@ -1,16 +1,21 @@
+--- 
 abstract: Authenticate Users against LDAP Directories
-author: 'Adam Jacob <holoway at cpan.org>'
-build_requires:
+author: Adam Jacob <holoway at cpan.org>
+build_requires: 
   Test::More: 0
 distribution_type: module
-generated_by: Module::Install version 0.62
+generated_by: Module::Install version 0.67
 license: perl
+meta-spec: 
+  url: http://module-build.sourceforge.net/META-spec-v1.3.html
+  version: 1.3
 name: Catalyst-Plugin-Authentication-Store-LDAP
-no_index:
-  directory:
+no_index: 
+  directory: 
     - inc
     - t
-requires:
+requires: 
+  Catalyst::Model::LDAP: 0
   Catalyst::Plugin::Authentication: 0
   Net::LDAP: 0
-version: 0.051
+version: 0.0600

Modified: trunk/Catalyst-Plugin-Authentication-Store-LDAP/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/Makefile.PL	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/Makefile.PL	2007-10-16 18:31:09 UTC (rev 7018)
@@ -8,6 +8,7 @@
 
 requires('Net::LDAP');
 requires('Catalyst::Plugin::Authentication');
+requires('Catalyst::Model::LDAP');
 build_requires('Test::More');
 
 auto_install();

Modified: trunk/Catalyst-Plugin-Authentication-Store-LDAP/TODO
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/TODO	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/TODO	2007-10-16 18:31:09 UTC (rev 7018)
@@ -1,6 +1,6 @@
 * Cache - this hits the directory a lot during full Auth/Authz usage.  
 
-* Recipies - We could handle some default recipes in the documentation for
+* Recipes - We could handle some default recipes in the documentation for
              different usage patterns.
 
 * Tests - We don't do any but the most cursory of tests

Modified: trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/Backend.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/Backend.pm	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/Backend.pm	2007-10-16 18:31:09 UTC (rev 7018)
@@ -76,6 +76,8 @@
 use strict;
 use warnings;
 
+our $VERSION = '0.0600';
+
 use Catalyst::Plugin::Authentication::Store::LDAP::User;
 use Net::LDAP;
 
@@ -118,6 +120,23 @@
     return $self;
 }
 
+=head2 find_user( I<authinfo> )
+
+Creates a L<Catalyst::Plugin::Authentication::Store::LDAP::User> object
+for the given User ID.  This is the preferred mechanism for getting a 
+given User out of the Store.
+
+I<authinfo> should be a hashref with a key of either C<id> or
+C<username>. The value will be compared against the LDAP C<user_field> field.
+
+=cut
+
+sub find_user {
+    my ( $self, $authinfo, $c ) = @_;
+    return $self->get_user( $authinfo->{id} || $authinfo->{username} );
+}
+
+
 =head2 get_user($id)
 
 Creates a L<Catalyst::Plugin::Authentication::Store::LDAP::User> object
@@ -349,6 +368,13 @@
     return $filter;
 }
 
+=head2 user_supports
+
+Returns the value of 
+Catalyst::Plugin::Authentication::Store::LDAP::User->supports(@_).
+
+=cut
+
 sub user_supports {
     my $self = shift;
 
@@ -356,6 +382,12 @@
     Catalyst::Plugin::Authentication::Store::LDAP::User->supports(@_);
 }
 
+=head2 from_session( I<id> )
+
+Returns get_user() for I<id>.
+
+=cut
+
 sub from_session {
     my ($self, $c, $id) = @_;
     $self->get_user($id);
@@ -370,8 +402,10 @@
 Adam Jacob <holoway at cpan.org>
 
 Some parts stolen shamelessly and entirely from
-L<Catalyst::Plugin::Authentication::Store::Htpasswd>. 
+L<Catalyst::Plugin::Authentication::Store::Htpasswd>.
 
+Realms API patches from Peter Karman <karman at cpan.org>.
+
 =head1 THANKS
 
 To nothingmuch, ghenry, castaway and the rest of #catalyst for the help. :)

Modified: trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/User.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/User.pm	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP/User.pm	2007-10-16 18:31:09 UTC (rev 7018)
@@ -45,6 +45,8 @@
 use strict;
 use warnings;
 
+our $VERSION = '0.0600';
+
 BEGIN { __PACKAGE__->mk_accessors(qw/user store/) }
 
 use overload '""' => sub { shift->stringify }, fallback => 1;
@@ -103,6 +105,12 @@
     }
 }
 
+=head2 supported_features
+
+Returns hashref of features that this Authentication::User subclass supports.
+
+=cut
+
 sub supported_features {
     return {
         password => { self_check => 1, },
@@ -140,6 +148,12 @@
     return $self->store->lookup_roles($self);
 }
 
+=head2 for_session
+
+Returns the User object, stringified.
+
+=cut
+
 sub for_session {
     my $self = shift;
     return $self->stringify;
@@ -267,6 +281,8 @@
 Some parts stolen shamelessly and entirely from
 L<Catalyst::Plugin::Authentication::Store::Htpasswd>. 
 
+Realms API patches from Peter Karman <karman at cpan.org>.
+
 =head1 THANKS
 
 To nothingmuch, ghenry, castaway and the rest of #catalyst for the help. :)

Modified: trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP.pm
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP.pm	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/lib/Catalyst/Plugin/Authentication/Store/LDAP.pm	2007-10-16 18:31:09 UTC (rev 7018)
@@ -9,24 +9,10 @@
 
 use Catalyst::Plugin::Authentication::Store::LDAP::Backend;
 
-sub setup {
-    my $c = shift;
-
-    if (exists($c->config->{'authentication'})) {
-        unless (exists($c->config->{'authentication'}->{'ldap'})) {
-            Catalyst::Exception->throw("I require \$c->config->{'authentication'}->{'ldap'} to be configured.");
-        }
-    } else {
-        Catalyst::Exception->throw("I require \$c->config->{'authentication'}->{'ldap'} to be configured.");
-    }
-
-    $c->default_auth_store(
-        Catalyst::Plugin::Authentication::Store::LDAP::Backend->new(
-            $c->config->{'authentication'}->{'ldap'}
-        )
-    );
-
-	$c->NEXT::setup(@_);
+sub new {
+    my ( $class, $config, $app ) = @_;
+    return Catalyst::Plugin::Authentication::Store::LDAP::Backend->new(
+        $config);
 }
 
 __PACKAGE__;
@@ -49,42 +35,49 @@
       /;
 
     __PACKAGE__->config(
-        'authentication' => {
-            'ldap' => {
-                'ldap_server' => 'ldap.yourcompany.com',
-                'ldap_server_options' => {
-                    'timeout' => 30,
-                },
-                'binddn' => 'anonymous',
-                'bindpw' => 'dontcarehow',
-                'start_tls' => 1,
-                'start_tls_options' => {
-                    'verify' => 'none',
-                },
-                'user_basedn' => 'ou=people,dc=yourcompany,dc=com',
-                'user_filter' => '(&(objectClass=posixAccount)(uid=%s))',
-                'user_scope' => 'one',
-                'user_field' => 'uid',
-                'user_search_options' => {
-                    'deref' => 'always',
-                },
-                'use_roles' => 1,
-                'role_basedn' => 'ou=groups,dc=yourcompany,dc=com',
-                'role_filter' => '(&(objectClass=posixGroup)(memberUid=%s))',
-                'role_scope' => 'one',
-                'role_field' => 'uid',
-                'role_value' => 'dn',
-                'role_search_options' => {
-                    'deref' => 'always',
-                },
-            }
-        },
+      'authentication' => {
+         default_realm => "ldap",
+         realms => {
+           ldap => {
+             credential => {
+               class => "Password",
+               password_field => "password",
+               password_type => "self_check",
+             },
+             store => {
+               binddn              => "anonymous",
+               bindpw              => "dontcarehow",
+               class               => "LDAP",
+               ldap_server         => "ldap.yourcompany.com",
+               ldap_server_options => { timeout => 30 },
+               role_basedn         => "ou=groups,ou=OxObjects,dc=yourcompany,dc=com",
+               role_field          => "uid",
+               role_filter         => "(&(objectClass=posixGroup)(memberUid=%s))",
+               role_scope          => "one",
+               role_search_options => { deref => "always" },
+               role_value          => "dn",
+               start_tls           => 1,
+               start_tls_options   => { verify => "none" },
+               entry_class         => "MyApp::LDAP::Entry",
+               use_roles           => 1,
+               user_basedn         => "ou=people,dc=yourcompany,dc=com",
+               user_field          => "uid",
+               user_filter         => "(&(objectClass=posixAccount)(uid=%s))",
+               user_scope          => "one",
+               user_search_options => { deref => "always" },
+             },
+           },
+         },
+       },
     );
 
     sub login : Global {
         my ( $self, $c ) = @_;
 
-        $c->login( $c->req->param("login"), $c->req->param("password"), );
+        $c->authenticate({
+                          id          => $c->req->param("login"), 
+                          password    => $c->req->param("password") 
+                         });
         $c->res->body("Welcome " . $c->user->username . "!");
     }
 
@@ -122,30 +115,39 @@
 
     # Config for Store::LDAP
     authentication:
-        ldap:
-            ldap_server: ldap.yourcompany.com
-            ldap_server_options:
-                timeout: 30
-            binddn: anonymous
-            bindpw: dontcarehow
-            start_tls: 1
-            start_tls_options:
-                verify: none
-            user_basedn: ou=people,dc=yourcompany,dc=com
-            user_filter: (&(objectClass=posixAccount)(uid=%s))
-            user_scope: one
-            user_field: uid
-            user_search_options:
-                deref: always
-            use_roles: 1
-            role_basedn: ou=groups,ou=OxObjects,dc=yourcompany,dc=com
-            role_filter: (&(objectClass=posixGroup)(memberUid=%s))
-            role_scope: one
-            role_field: uid
-            role_value: dn
-            role_search_options:
-                deref: always
+        default_realm: ldap
+        realms:
+            ldap:
+                credential:
+                    class: Password
+                    password_field: password
+                    password_type:  self_check
+                store:
+                    class: LDAP
+                    ldap_server: ldap.yourcompany.com
+                    ldap_server_options:
+                        timeout: 30
+                    binddn: anonymous
+                    bindpw: dontcarehow
+                    start_tls: 1
+                    start_tls_options:
+                        verify: none
+                    user_basedn: ou=people,dc=yourcompany,dc=com
+                    user_filter: (&(objectClass=posixAccount)(uid=%s))
+                    user_scope: one
+                    user_field: uid
+                    user_search_options:
+                        deref: always
+                    use_roles: 1
+                    role_basedn: ou=groups,ou=OxObjects,dc=yourcompany,dc=com
+                    role_filter: (&(objectClass=posixGroup)(memberUid=%s))
+                    role_scope: one
+                    role_field: uid
+                    role_value: dn
+                    role_search_options:
+                        deref: always
 
+
 =head2 ldap_server
 
 This should be the hostname of your LDAP server.
@@ -269,7 +271,7 @@
 
 =head1 METHODS
 
-=head2 setup
+=head2 new
 
 This method will populate
 L<Catalyst::Plugin::Authentication/default_auth_store> with this object. 
@@ -279,8 +281,10 @@
 Adam Jacob <holoway at cpan.org>
 
 Some parts stolen shamelessly and entirely from
-L<Catalyst::Plugin::Authentication::Store::Htpasswd>. 
+L<Catalyst::Plugin::Authentication::Store::Htpasswd>.
 
+Realms API patches from Peter Karman <karman at cpan.org>.
+
 =head1 THANKS
 
 To nothingmuch, ghenry, castaway and the rest of #catalyst for the help. :)

Copied: trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/01-pre_realms_api.t (from rev 7017, trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/simple.t)
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/01-pre_realms_api.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/01-pre_realms_api.t	2007-10-16 18:31:09 UTC (rev 7018)
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Catalyst::Exception;
+
+use Test::More tests => 4;
+
+BEGIN { use_ok("Catalyst::Plugin::Authentication::Store::LDAP::Backend") }
+
+my $back = Catalyst::Plugin::Authentication::Store::LDAP::Backend->new({
+            'ldap_server' => 'ldap.openldap.org',
+            'binddn' => 'anonymous',
+            'bindpw' => 'dontcarehow',
+            'start_tls' => 0,
+            'user_basedn' => 'ou=People,dc=OpenLDAP,dc=Org',
+            'user_filter' => '(&(objectClass=person)(uid=%s))',
+            'user_scope' => 'one',
+            'user_field' => 'uid',
+            'use_roles' => 0,
+    });
+isa_ok($back, "Catalyst::Plugin::Authentication::Store::LDAP::Backend");
+my $user = $back->get_user('kurt');
+isa_ok($user, "Catalyst::Plugin::Authentication::Store::LDAP::User");
+my $displayname = $user->displayname;
+cmp_ok($displayname, 'eq', 'Kurt Zeilenga', 'Should be Kurt Zeilenga');
+

Added: trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/02-realms_api.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/02-realms_api.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/02-realms_api.t	2007-10-16 18:31:09 UTC (rev 7018)
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Catalyst::Exception;
+
+use Test::More tests => 4;
+
+BEGIN { use_ok("Catalyst::Plugin::Authentication::Store::LDAP::Backend") }
+
+my $back = Catalyst::Plugin::Authentication::Store::LDAP::Backend->new(
+    {   'ldap_server' => 'ldap.openldap.org',
+        'binddn'      => 'anonymous',
+        'bindpw'      => 'dontcarehow',
+        'start_tls'   => 0,
+        'user_basedn' => 'ou=People,dc=OpenLDAP,dc=Org',
+        'user_filter' => '(&(objectClass=person)(uid=%s))',
+        'user_scope'  => 'one',
+        'user_field'  => 'uid',
+        'use_roles'   => 0,
+    }
+);
+isa_ok( $back, "Catalyst::Plugin::Authentication::Store::LDAP::Backend" );
+my $user = $back->find_user( { username => 'kurt' } );
+isa_ok( $user, "Catalyst::Plugin::Authentication::Store::LDAP::User" );
+my $displayname = $user->displayname;
+cmp_ok( $displayname, 'eq', 'Kurt Zeilenga', 'Should be Kurt Zeilenga' );

Added: trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod-coverage.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod-coverage.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod-coverage.t	2007-10-16 18:31:09 UTC (rev 7018)
@@ -0,0 +1,6 @@
+#!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();

Added: trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/pod.t	2007-10-16 18:31:09 UTC (rev 7018)
@@ -0,0 +1,6 @@
+#!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();

Deleted: trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/simple.t
===================================================================
--- trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/simple.t	2007-10-16 15:06:46 UTC (rev 7017)
+++ trunk/Catalyst-Plugin-Authentication-Store-LDAP/t/simple.t	2007-10-16 18:31:09 UTC (rev 7018)
@@ -1,27 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Catalyst::Exception;
-
-use Test::More tests => 4;
-
-BEGIN { use_ok("Catalyst::Plugin::Authentication::Store::LDAP::Backend") }
-
-my $back = Catalyst::Plugin::Authentication::Store::LDAP::Backend->new({
-            'ldap_server' => 'ldap.openldap.org',
-            'binddn' => 'anonymous',
-            'bindpw' => 'dontcarehow',
-            'start_tls' => 0,
-            'user_basedn' => 'ou=People,dc=OpenLDAP,dc=Org',
-            'user_filter' => '(&(objectClass=person)(uid=%s))',
-            'user_scope' => 'one',
-            'user_field' => 'uid',
-            'use_roles' => 0,
-    });
-isa_ok($back, "Catalyst::Plugin::Authentication::Store::LDAP::Backend");
-my $user = $back->get_user('kurt');
-isa_ok($user, "Catalyst::Plugin::Authentication::Store::LDAP::User");
-my $displayname = $user->displayname;
-cmp_ok($displayname, 'eq', 'Kurt Zeilenga', 'Should be Kurt Zeilenga');
-




More information about the Catalyst-commits mailing list