| 1 | package OpenInteract::SPOPS::LDAP; | ||
| 2 | |||
| 3 | # $Id: LDAP.pm,v 1.11 2002/01/02 02:43:53 lachoy Exp $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use OpenInteract::SPOPS; | ||
| 7 | |||
| 8 | @OpenInteract::SPOPS::LDAP::ISA = qw( OpenInteract::SPOPS ); | ||
| 9 | $OpenInteract::SPOPS::LDAP::VERSION = sprintf("%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/); | ||
| 10 | |||
| 11 | |||
| 12 | # TODO: Ensure stub is in SPOPS::LDAP for this | ||
| 13 | |||
| 14 | sub global_datasource_handle { | ||
| 15 | my ( $self, $connect_key ) = @_; | ||
| 16 | $connect_key ||= $self->get_connect_key(); | ||
| 17 | my $R = OpenInteract::Request->instance; | ||
| 18 | $R->DEBUG && $R->scrib( 1, "Trying to retrieve handle for key ($connect_key) for: ", | ||
| 19 | ( ref $self ) ? ref $self : $self ); | ||
| 20 | return $R->ldap( $connect_key ); | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | # TODO: Ensure stub is in SPOPS::LDAP for this | ||
| 25 | |||
| 26 | sub connection_info { | ||
| 27 | my ( $self, $connect_key ) = @_; | ||
| 28 | $connect_key ||= $self->get_connect_key(); | ||
| 29 | return \%{ $self->global_config->{ldap_info}{ $connect_key } }; | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | # TODO: Move this to SPOPS::LDAP and document | ||
| 34 | |||
| 35 | sub base_dn { | ||
| 36 | my ( $class, $connect_key ) = @_; | ||
| 37 | my $partial_dn = $class->get_partial_dn( $connect_key ); | ||
| 38 | unless ( $partial_dn ) { | ||
| 39 | die "No Base DN defined in SPOPS configuration key 'ldap_base_dn', cannot continue!\n"; | ||
| 40 | } | ||
| 41 | my $connect_info = $class->connection_info( $connect_key ); | ||
| 42 | return join( ',', $partial_dn, $connect_info->{base_dn} ); | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | # Retrieves the connect key when none is passed in | ||
| 47 | |||
| 48 | # TODO: Move this (minus the 'global_config' option) to SPOPS::LDAP | ||
| 49 | # and document | ||
| 50 | |||
| 51 | sub get_connect_key { | ||
| 52 | my ( $class ) = @_; | ||
| 53 | my $connect_key = $class->CONFIG->{datasource} || | ||
| 54 | $class->global_config->{datasource}{default_connection_ldap} || | ||
| 55 | $class->global_config->{default_connection_ldap}; | ||
| 56 | $connect_key = $connect_key->[0] if ( ref $connect_key eq 'ARRAY' ); | ||
| 57 | return $connect_key; | ||
| 58 | } | ||
| 59 | |||
| 60 | # Retrieves the 'partial dn', or the section that's prepended to the | ||
| 61 | # server's 'base DN' to identify the branch on which these objects | ||
| 62 | # live | ||
| 63 | |||
| 64 | # TODO: Move this to SPOPS::LDAP (?) and document | ||
| 65 | |||
| 66 | sub get_partial_dn { | ||
| 67 | my ( $class, $connect_key ) = @_; | ||
| 68 | my $base_dn_info = $class->CONFIG->{ldap_base_dn}; | ||
| 69 | return $base_dn_info unless ( ref $base_dn_info eq 'HASH' ); | ||
| 70 | $connect_key ||= $class->get_connect_key; | ||
| 71 | return $base_dn_info->{ $connect_key }; | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ |