« blib/lib/Lemonldap/NG/Common/Conf/Wrapper.pm
↑ Summary
blib/lib/Lemonldap/NG/Common/Apache/Session/Serialize/JSON.pm »
| 1 | package Lemonldap::NG::Common::Conf::Backends::SOAP; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use utf8; | ||
| 5 | use SOAP::Lite; | ||
| 6 | use Lemonldap::NG::Common::Conf::Constants; | ||
| 7 | |||
| 8 | our $VERSION = '2.0.0'; | ||
| 9 | |||
| 10 | #parameter proxy Url of SOAP service | ||
| 11 | #parameter proxyOptions SOAP::Lite parameters | ||
| 12 | |||
| 13 | BEGIN { | ||
| 14 | *Lemonldap::NG::Common::Conf::_soapCall = \&_soapCall; | ||
| 15 | *Lemonldap::NG::Common::Conf::_connect = \&_connect; | ||
| 16 | |||
| 17 | sub SOAP::Transport::HTTP::Client::get_basic_credentials { | ||
| 18 | return $Lemonldap::NG::Common::Conf::Backends::SOAP::username => | ||
| 19 | $Lemonldap::NG::Common::Conf::Backends::SOAP::password; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | our ( $username, $password ) = ( '', '' ); | ||
| 24 | |||
| 25 | sub prereq { | ||
| 26 | my $self = shift; | ||
| 27 | unless ( $self->{proxy} ) { | ||
| 28 | $Lemonldap::NG::Common::Conf::msg .= | ||
| 29 | "proxy parameter is required in SOAP configuration type \n"; | ||
| 30 | return 0; | ||
| 31 | } | ||
| 32 | 1; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub _connect { | ||
| 36 | my $self = shift; | ||
| 37 | return $self->{service} if ( $self->{service} ); | ||
| 38 | my @args = ( $self->{proxy} ); | ||
| 39 | if ( $self->{proxyOptions} ) { | ||
| 40 | push @args, %{ $self->{proxyOptions} }; | ||
| 41 | } | ||
| 42 | $self->{ns} ||= 'urn:/Lemonldap/NG/Common/PSGI/SOAPService'; | ||
| 43 | return $self->{service} = SOAP::Lite->ns( $self->{ns} )->proxy(@args); | ||
| 44 | } | ||
| 45 | |||
| 46 | sub _soapCall { | ||
| 47 | my $self = shift; | ||
| 48 | my $func = shift; | ||
| 49 | $username = $self->{User}; | ||
| 50 | $password = $self->{Password}; | ||
| 51 | my $r = $self->_connect->$func(@_); | ||
| 52 | if ( $r->fault() ) { | ||
| 53 | print STDERR "SOAP error : " . $r->fault()->{faultstring}; | ||
| 54 | return (); | ||
| 55 | } | ||
| 56 | return $r->result; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub available { | ||
| 60 | my $self = shift; | ||
| 61 | return @{ $self->_soapCall( 'available', @_ ) }; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub lastCfg { | ||
| 65 | my $self = shift; | ||
| 66 | return $self->_soapCall( 'lastCfg', @_ ); | ||
| 67 | } | ||
| 68 | |||
| 69 | # lock and unlock must not be requested by the SOAP client, since | ||
| 70 | # they will be done by the SOAP server when storing the config | ||
| 71 | sub lock { | ||
| 72 | return 1; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub unlock { | ||
| 76 | return 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | sub isLocked { | ||
| 80 | return 1; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub store { | ||
| 84 | my $self = shift; | ||
| 85 | return $self->_soapCall( 'store', @_ ); | ||
| 86 | } | ||
| 87 | |||
| 88 | sub load { | ||
| 89 | my $self = shift; | ||
| 90 | my $conf = $self->_soapCall( 'getConfig', @_ ); | ||
| 91 | |||
| 92 | # Force empty hash that are not converted by SOAP | ||
| 93 | foreach ( keys %{ $conf || {} } ) { | ||
| 94 | if ( $_ =~ /$hashParameters/ ) { | ||
| 95 | $conf->{$_} ||= {}; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | return $conf; | ||
| 100 | } | ||
| 101 | |||
| 102 | 1; |