Portal SOAP:

* perltidy
* Add process stages in getCookies
* Move _buildSoapHash in private methods parts
* Create getXmlMenu method in /config
* Update buildPortalWSDL script
This commit is contained in:
Clément Oudot 2010-01-19 16:50:38 +00:00
parent a5c89df613
commit 15e77c7d88
2 changed files with 95 additions and 35 deletions

View File

@ -164,6 +164,37 @@ print Lemonldap::NG::Common::BuildWSDL->new->buildWSDL(<<EOT);
<wsdl:message name="isAuthorizedURIResponse">
<wsdl:part name="result" type="xsd:boolean" />
</wsdl:message>
<wsdl:service name="configHandlerService">
<wsdl:port binding="impl:configSoapBinding" name="config">
<wsdlsoap:address location="__PORTAL__/config" />
</wsdl:port>
</wsdl:service>
<wsdl:binding name="configSoapBinding" type="impl:configHandler">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getXmlMenu">
<wsdlsoap:operation soapAction="" />
<wsdl:input name="getXmlMenuRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Lemonldap/NG/Common/CGI/SOAPService" use="encoded" />
</wsdl:input>
<wsdl:output name="getXmlMenuResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Lemonldap/NG/Common/CGI/SOAPService" use="encoded" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:portType name="configHandler">
<wsdl:operation name="getgetXmlMenu" parameterOrder="file">
<wsdl:input message="impl:getXmlMenuRequest" name="getXmlMenuRequest" />
<wsdl:output message="impl:getXmlMenuResponse" name="getXmlMenuResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:message name="getXmlMenuRequest">
<wsdl:part name="file" type="xsd:string" />
</wsdl:message>
<wsdl:message name="getXmlMenuResponse">
<wsdl:part name="result" type="xsd:string" />
</wsdl:message>
</wsdl:definitions>
EOT

View File

@ -29,7 +29,7 @@ sub startSoapServices {
'/sessions' => 'getAttributes isAuthorizedURI',
'/adminSessions' => 'getAttributes setAttributes isAuthorizedURI '
. 'newSession deleteSession get_key_from_all_sessions',
'/config' => 'getConfig lastCfg'
'/config' => 'getConfig lastCfg getXmlMenu'
}->{ $ENV{PATH_INFO} }
)
{
@ -74,7 +74,8 @@ sub getCookies {
else {
$self->{error} = $self->_subProcess(
qw(authInit userDBInit getUser setAuthSessionInfo setSessionInfo
setMacros setGroups authenticate store buildCookie)
setMacros setLocalGroups setGroups authenticate removeOther grantSession
store buildCookie)
);
}
my @tmp = ();
@ -173,29 +174,6 @@ sub lastCfg {
return $self->{lmConf}->lastCfg();
}
##@fn private SOAP::Data _buildSoapHash()
# Serialize a hashref into SOAP::Data. Types are fixed to "string".
# @return SOAP::Data serialized datas
sub _buildSoapHash {
my ( $h, @keys ) = @_;
my @tmp = ();
@keys = keys %$h unless (@keys);
foreach (@keys) {
if ( ref( $h->{$_} ) eq 'ARRAY' ) {
push @tmp,
SOAP::Data->name( $_, \SOAP::Data->value( @{ $h->{$_} } ) );
}
elsif ( ref( $h->{$_} ) ) {
push @tmp, SOAP::Data->name( $_ => _buildSoapHash( $h->{$_} ) );
}
else {
push @tmp, SOAP::Data->name( $_, $h->{$_} )->type('string')
if ( defined( $h->{$_} ) );
}
}
return \SOAP::Data->value(@tmp);
}
## @method SOAP::Data newSession(hashref args)
# Store a new session.
# @return Session datas
@ -226,7 +204,8 @@ sub deleteSession {
return $self->_deleteSession($h);
}
##@method SOAP::Data getConfig()
##@method SOAP::Data get_key_from_all_sessions
# Returns key from all sessions
sub get_key_from_all_sessions {
my $self = shift;
shift;
@ -256,10 +235,9 @@ _RETURN $isAuthorizedURIResponse Response
# @param $id Id of the session
# @param $uri URL string
# @return True if granted
sub isAuthorizedURI
{
sub isAuthorizedURI {
my $self = shift;
my ($id, $uri) = @_;
my ( $id, $uri ) = @_;
die 'id is required' unless ($id);
die 'uri is required' unless ($uri);
@ -285,20 +263,22 @@ sub isAuthorizedURI
foreach my $vpath ( keys %{ $self->{locationRules}->{$vhost} } ) {
if ( $vpath eq 'default' ) {
$defaultCondition->{$vhost} =
$self->_conditionSub($id, $self->{locationRules}->{$vhost}->{$vpath});
$self->_conditionSub( $id,
$self->{locationRules}->{$vhost}->{$vpath} );
}
else {
$locationCondition->{$vhost}->[$i] =
$self->_conditionSub($id, $self->{locationRules}->{$vhost}->{$vpath});
$self->_conditionSub( $id,
$self->{locationRules}->{$vhost}->{$vpath} );
$locationRegexp->{$vhost}->[$i] = qr/$vpath/;
$i++;
}
}
$defaultCondition->{$vhost} ||= $self->_conditionSub($id, 'accept');
$defaultCondition->{$vhost} ||= $self->_conditionSub( $id, 'accept' );
}
# Test rules.
unless (defined($defaultCondition->{$vhost})) {
unless ( defined( $defaultCondition->{$vhost} ) ) {
$self->lmLog( "No default condition builded", 'warn' );
return 0;
}
@ -314,16 +294,65 @@ sub isAuthorizedURI
return 1;
}
=begin WSDL
_IN file $string Menu XML file complete path
_RETURN $getXmlMenuResponse Response
=end WSDL
=cut
##@method SOAP::Data getXmlMenu(string file)
#@param file
#@return SOAP::Data
sub getXmlMenu {
my $self = shift;
my ($file) = @_;
die 'file is required' unless ($file);
die 'file cannot be read' unless ( -r $file );
# Load XML::Simple
use XML::Simple;
# Get XML content
my $xml = new XML::Simple( ForceArray => '1' );
return _buildSoapHash( $xml->XMLin($file) );
}
#######################
# Private subroutines #
#######################
##@fn private SOAP::Data _buildSoapHash()
# Serialize a hashref into SOAP::Data. Types are fixed to "string".
# @return SOAP::Data serialized datas
sub _buildSoapHash {
my ( $h, @keys ) = @_;
my @tmp = ();
@keys = keys %$h unless (@keys);
foreach (@keys) {
if ( ref( $h->{$_} ) eq 'ARRAY' ) {
push @tmp,
SOAP::Data->name( $_, \SOAP::Data->value( @{ $h->{$_} } ) );
}
elsif ( ref( $h->{$_} ) ) {
push @tmp, SOAP::Data->name( $_ => _buildSoapHash( $h->{$_} ) );
}
else {
push @tmp, SOAP::Data->name( $_, $h->{$_} )->type('string')
if ( defined( $h->{$_} ) );
}
}
return \SOAP::Data->value(@tmp);
}
## @method private CODE _conditionSub(string cond)
# Return subroutine giving authorization condition.
# @param $cond boolean expression
# @return Compiled routine
sub _conditionSub
{
sub _conditionSub {
my $self = shift;
my $id = shift;
my ($cond) = @_;