From 305113c53f15bc434860ed3aafed4e5db524c318 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 17 Sep 2010 15:32:43 +0000 Subject: [PATCH] #28 in progress : - Extension to Net::OpenID::Server to manage extensions (and sign them) --- modules/lemonldap-ng-common/MANIFEST | 1 + .../lib/Lemonldap/NG/Common/OpenID/Server.pm | 102 ++++++++++++++++++ .../lib/Lemonldap/NG/Portal/IssuerDBOpenID.pm | 4 +- 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/OpenID/Server.pm diff --git a/modules/lemonldap-ng-common/MANIFEST b/modules/lemonldap-ng-common/MANIFEST index 3b4162c0e..ed590fa2b 100644 --- a/modules/lemonldap-ng-common/MANIFEST +++ b/modules/lemonldap-ng-common/MANIFEST @@ -19,6 +19,7 @@ lib/Lemonldap/NG/Common/Conf/SAML/Metadata.pm lib/Lemonldap/NG/Common/Conf/Serializer.pm lib/Lemonldap/NG/Common/Conf/SOAP.pm lib/Lemonldap/NG/Common/Crypto.pm +lib/Lemonldap/NG/Common/OpenID/Server.pm lib/Lemonldap/NG/Common/Safelib.pm Makefile.PL MANIFEST This list of files diff --git a/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/OpenID/Server.pm b/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/OpenID/Server.pm new file mode 100644 index 000000000..636707557 --- /dev/null +++ b/modules/lemonldap-ng-common/lib/Lemonldap/NG/Common/OpenID/Server.pm @@ -0,0 +1,102 @@ +package Lemonldap::NG::Common::OpenID::Server; + +use strict; +use fields qw(_extensions); +use Net::OpenID::Server; + +our @ISA = qw(Net::OpenID::Server); +our $VERSION = '0.1'; + +sub new { + my $class = shift; + my $self = fields::new($class); + my %opts = splice @_; + $self->$_(delete $opts{$_}) foreach (qw(extensions)); + return $self->SUPER::new(%opts); +} + +sub extensions { + my $self = shift; + $self->{_extensions} = @_; +} + +sub signed_return_url { + my ( $self, %opts ) = splice @_; + my $extra; + if(ref $self->{_extensions}){ + my $list = $self->args(); + my @list = $self->get_args(); + my %h; + foreach my $arg (@list) { + next unless($arg =~/^openid\.(\w+)/); + my $tmp = $1; + if(defined $self->{_extensions}->{$tmp}) { + push @{$h{$tmp}},$arg,scalar self->get_args($arg); + } + } + my %vars; + foreach my $ns (keys %h){ + %vars = (%vars,$self->{_extensions}->{$ns}->(@{$h{$ns}})); + } + $opts{extra_fields} = \%vars; + } + return $self->SUPER::signed_return_url(%opts); +} + +#sub get_args { +# my ($self, $hash) = shift; +# return sub +#} + +1; +__END__ + +=head1 NAME + +Lemonldap::NG::Common::OpenID::Server - Add capability to manage extensions to +Net::OpenID::Server + +=head1 SYNOPSIS + + use Lemonldap::NG::Common::OpenID::Server; + blah blah blah + +=head1 DESCRIPTION + +Stub documentation for Lemonldap::NG::Common::OpenID::Server, created by h2xs. It looks like the +author of the extension was negligent enough to leave the stub +unedited. + +Blah blah blah. + +=head2 EXPORT + +None by default. + + + +=head1 SEE ALSO + +Mention other useful documentation such as the documentation of +related modules or operating system documentation (such as man pages +in UNIX), or any relevant external documentation such as RFCs or +standards. + +If you have a mailing list set up for your module, mention it here. + +If you have a web site set up for your module, mention it here. + +=head1 AUTHOR + +guimard, Eguimard@E + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2010 by guimard + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.10.1 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/modules/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/IssuerDBOpenID.pm b/modules/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/IssuerDBOpenID.pm index 58f3b555a..bdb0b21bd 100644 --- a/modules/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/IssuerDBOpenID.pm +++ b/modules/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/IssuerDBOpenID.pm @@ -15,7 +15,7 @@ our $VERSION = '0.01'; # @return Lemonldap::NG::Portal error code sub issuerDBInit { my $self = shift; - eval { require Net::OpenID::Server }; + eval { require Lemonldap::NG::Common::OpenID::Server }; $self->abort( 'Unable to load Net::OpenID::Server', $@ ) if ($@); $self->{openIdSecret} ||= $self->{cipher}->encrypt(0); return PE_OK; @@ -107,7 +107,7 @@ sub openIDServer { $self->{_openidPortal} = $self->{portal} . "/openidserver/"; $self->{_openidPortal} =~ s#(?{_openidserver} = Net::OpenID::Server->new( + $self->{_openidserver} = Lemonldap::NG::Common::OpenID::Server->new( # TODO server_secret => sub { return $self->{openIdSecret} },