Permalink
Browse files

searchable directory!

ProtocolHandler changes
- added unbind operation
- wrote an useful search operation
- improved documentation

LDIFstore changes
- removed filter method
- added and accessor method list to the list of entries
- improved documentation

Improved tests
- improved some test messages
- add more test to the ldif store
- added test to the search function
- simplified the example ldif, to ease debugging ;-)

Signed-off-by: Alexei Znamensky <russoz@cpan.org>
  • Loading branch information...
1 parent ad14dce commit c6aaacba7ea6aaec30fcc8e12b1aaf8cac613002 @russoz russoz committed Apr 21, 2012
View
@@ -6,23 +6,10 @@ objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Alexei Znamensky
-accountExpires: 129290832000000000
-badPasswordTime: 129253228359870323
-badPwdCount: 0
-codePage: 0
-countryCode: 0
description: Consultant - SnakeOil Brazil on Extranet
displayName: Alexei Znamensky
distinguishedName: CN=Alexei Znamensky,OU=SnakeOil,OU=Extranet,DC=sa,DC=mynet,DC=net
givenName: Alexei
-lastLogoff: 0
-logonCount: 684
manager: CN=John Doe,OU=SnakeOil,OU=Extranet,DC=na,DC=mynet,DC=net
-memberOf: CN=g_SPO_ADM_WAS,OU=AD_Based_Apps,OU=GROUPS,OU=SPO,DC=sa,DC=mynet,DC=net
name: Alexei Znamensky
sn: Znamensky
-userPrincipalName: ZnamensA@mynet.net
-uSNChanged: 160358095
-uSNCreated: 144230343
-whenChanged: 20100906002534.0Z
-whenCreated: 20100318194403.0Z
@@ -131,7 +131,7 @@ sub process_request {
until ( $handler->handle ) {
- # empty loop
+ # intentionally empty loop
}
return;
}
@@ -142,8 +142,6 @@ __END__
=head1 SYNOPSIS
-B<< WORK IN PROGRESS!! NOT READY TO USE YET!! >>
-
package MyServer;
use Net::LDAP::SimpleServer;
@@ -174,46 +172,30 @@ The default configuration file is:
=head1 DESCRIPTION
-=for author to fill in:
- Write a full description of the module and its features here.
- Use subsections (=head2, =head3) as appropriate.
-
As the name suggests, this module aims to implement a simple LDAP server,
using many components already available in CPAN. It can be used for
prototyping and/or development purposes. This is B<NOT> intended to be a
production-grade server, altough some brave souls in small offices might
use it as such.
-As of November 2010, the server will simply load a LDIF file and serve its
+As of April 2010, the server will load a LDIF file and serve its
contents through the LDAP protocol. Many operations are B<NOT> available yet,
-notably writing into the directory tree, but we would like to implement that
-in a near future.
-
-
-=head1 CONSTRUCTOR
-
-The constructors will follow the rules defined by L<Net::Server>, but most
-notably we have the two forms below:
+notably writing into the directory tree.
-=over
+The constructors will follow the rules defined by L<Net::Server>, but the most
+useful are the two forms described below.
-=item new()
+=method new()
Attempts to create a server by using the default configuration file,
C<< ${HOME}/.ldapsimpleserver/config >>.
-=item new( HASHREF )
+=method new( HASHREF )
Attempts to create a server by using the options specified in a hash
reference rather than reading them from a configuration file.
-=back
-
-=head1 METHODS
-
-=over
-
-=item options()
+=method options()
As specified in L<Net::Server>, this method creates new options for the,
server, namely:
@@ -228,7 +210,7 @@ root_pw - the password for root_dn
=back
-=item default_values()
+=method default_values()
As specified in L<Net::Server>, this method provides default values for a
number of options. In Net::LDAP::SimpleServer, this method is defined as:
@@ -250,50 +232,18 @@ Notice that we do set a default password for the C<< cn=root >> DN. This
allows for out-of-the-box testing, but make sure you change the password
when putting this to production use.
-=item post_configure_hook()
+=method post_configure_hook()
Method specified by L<Net::Server> to validate the passed options
-=item process_request()
+=method process_request()
Method specified by L<Net::Server> to actually handle one connection. In this
module it basically delegates the processing to
L<Net::LDAP::SimpleServer::ProtocolHandler>.
-=back
-
-=head1 DIAGNOSTICS
-
-=for author to fill in:
- List every single error and warning message that the module can
- generate (even the ones that will "never happen"), with a full
- explanation of each problem, one or more likely causes, and any
- suggested remedies.
-
-=over
-
-=item C<< Error message here, perhaps with %s placeholders >>
-
-[Description of error here]
-
-=item C<< Another error message here >>
-
-[Description of error here]
-
-[Et cetera, et cetera]
-
-=back
-
-
=head1 CONFIGURATION AND ENVIRONMENT
-=for author to fill in:
- A full explanation of any configuration system(s) used by the
- module, including the names and locations of any configuration
- files, and the meaning of any environment variables or properties
- that can be set. These descriptions must also include details of any
- configuration language used.
-
Net::LDAP::SimpleServer may use a configuration file to specify the
server settings. If no file is specified and options are not passed
in a hash, this module will look for a default configuration file named
@@ -308,32 +258,5 @@ C<< ${HOME}/.ldapsimpleserver/config >>.
#user_id_attr uid
#user_pw_attr password
-
-=head1 DEPENDENCIES
-
-=for author to fill in:
- A list of all the other modules that this module relies upon,
- including any restrictions on versions, and an indication whether
- the module is part of the standard Perl distribution, part of the
- module's distribution, or must be installed separately. ]
-
-L<< Net::LDAP >>
-
-L<< Net::LDAP::Server >>
-
-L<< Net::Server >>
-
-L<< UNIVERSAL::isa >>
-
-L<< Carp >>
-
-L<< File::HomeDir >>
-
-L<< File::Spec::Functions >>
-
-L<< Scalar::Util >>
-
-L<< Config::General >>
-
-L<< Net::LDAP::SimpleServer::LDIFStore >>
+=cut
@@ -12,6 +12,7 @@ use 5.010;
use Carp qw/carp croak/;
use UNIVERSAL::isa;
use Scalar::Util qw(blessed reftype);
+
use Net::LDAP::LDIF;
sub new {
@@ -94,19 +95,11 @@ sub _load_ldif {
return \@sortedlist;
}
-sub filter {
- my ( $self, $sub ) = @_;
- return () unless $self->{list};
-
- my @list = @{ $self->{list} };
-
- foreach my $index ( 0 .. $#list ) {
- delete $list[$index] unless $sub->( $list[$index] );
- }
- return @list;
+sub list { ## no critic
+ return $_[0]->{list};
}
-1; # Magic true value required at end of module
+1; # Magic true value required at end of module
__END__
@@ -123,11 +116,6 @@ __END__
my $ldif = Net::LDAP::LDIF->new( "file.ldif" );
my $store = Net::LDAP::SimpleServer::LDIFStore->new($ldif);
- my $result = $store->filter( sub {
- $a = shift;
- $a->get_value('cn') =~ m/joe/i;
- } );
-
=head1 DESCRIPTION
This module provides an interface between Net::LDAP::SimpleServer and a
@@ -136,16 +124,13 @@ LDIF file where the data is stored.
As of now, this interface is quite simple, and so is the underlying data
structure, but this can be easily improved in the future.
-=head1 CONSTRUCTOR
-
-=over
-
-=item new()
+=method new()
Creates a store with no data in it. It cannot be really used like that, you
-B<must> C<< load() >> some data in it first.
+B<must> C<< load() >> some data with the C<load()> method before being able
+to use it.
-=item new( FILE )
+=method new( FILE )
Create the data store by reading FILE, which may be the name of a file or an
already open filehandle. It is passed directly to
@@ -154,7 +139,7 @@ L<< Net::LDAP::LDIF >>.
Constructor. Expects either: a filename, a file handle, a hash reference or
a reference to a C<Net::LDAP::LDIF> object.
-=item new( HASHREF )
+=method new( HASHREF )
Create the data store using the parameters in HASHREF. The associative-array
referenced by HASHREF B<must> contain a key named C<< ldif >>, which must
@@ -163,71 +148,22 @@ C<< ldif_options >>, which may contain optional parameters used in the
3-parameter version of the C<Net::LDAP::LDIF> constructor. The LDIF file will
be used for reading the data.
-=item new( LDIF )
+=method new( LDIF )
Uses an existing C<< Net::LDAP::LDIF >> as the source for the directory data.
-=back
-
-=head1 METHODS
-
-=over
-
-=item load( PARAM )
+=method load( PARAM )
Loads data from a source specified by PARAM. The argument may be in any of the
forms accepted by the constructor, except that it B<must> be specified.
-=item ldif()
+=method ldif()
Returns the underlying C<< Net::LDAP::LDIF >> object.
-=item filter( SUBREF )
-
-Returns a list of entries for which the function referenced by SUBREF returns
-C<true>.
-
-=back
-
-=for head1 DIAGNOSTICS
-
-=for author to fill in:
- List every single error and warning message that the module can
- generate (even the ones that will "never happen"), with a full
- explanation of each problem, one or more likely causes, and any
- suggested remedies.
- =over
- =item C<< Error message here, perhaps with %s placeholders >>
- [Description of error here]
- =item C<< Another error message here >>
- [Description of error here]
- [Et cetera, et cetera]
- =back
-
-=head1 CONFIGURATION AND ENVIRONMENT
-
-=for author to fill in:
- A full explanation of any configuration system(s) used by the
- module, including the names and locations of any configuration
- files, and the meaning of any environment variables or properties
- that can be set. These descriptions must also include details of any
- configuration language used.
-
-Net::LDAP::SimpleServer requires no configuration files or environment variables.
-
-=head1 DEPENDENCIES
-
-L<< UNIVERSAL::isa >>
-
-L<< Scalar::Util >>
-
-L<< Net::LDAP::LDIF >>
-
-=head1 INCOMPATIBILITIES
+=method list
-None reported.
+Returns the list of entries.
-=head1 BUGS AND LIMITATIONS
+=cut
-This store does not yet support writing to a LDIF file, which makes the
-C<< Net::LDAP::SimpleServer >> a read-only server.
Oops, something went wrong.

0 comments on commit c6aaacb

Please sign in to comment.