Commit 5f0dded7 authored by Thomas Chemineau's avatar Thomas Chemineau
Browse files

managing samlIDPMetaData node now working, and stored well formated data in configuration backend

parent 9937568f
......@@ -219,15 +219,29 @@ sub toXML {
# @return string
sub toConf {
my $self = shift;
my $fields;
my $fields = $self->toHash();
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Varname = "data";
my $data = Dumper($self);
my $data = Dumper($fields);
$data =~ s/^\s*(.*?)\s*$/$1/;
$data =~ s/'/'/g;
$data =~ s/^\$data[0-9]*\s*=\s*({?\s*.+\s*}?)/$1/g;
return $data;
}
## @method public string toHash ()
# Return this object in configuration hash format.
# @return hashref
sub toHash {
my $self = shift;
my $fields = ();
foreach (keys %$self)
{
$fields->{$_} = $self->{$_};
}
return $fields;
}
## @method public hashref toStruct ()
# Return this object to be display into the Manager.
# NOT USED FOR THE MOMENT.
......
......@@ -211,6 +211,7 @@ function display(div,title) {
$('#content_'+div).addClass('content');
$('#content_title').html(title);
$('#newkb,#newrb,#delkb,#newkbr,#newrbr,#bdelvh').hide();
$('#newsamlmetadatab,#delsamlmetadatab').hide();
}
function none(id) {
currentId=id;
......@@ -268,13 +269,14 @@ function samlAssertion(id) {
}
function samlMetaData(id){
currentId=id;
if($('#li_'+myB64('/samlIDPMetaData')).find('span').size()==1){
$('#samlMetaData').attr('value',lmtext(id));
display('samlMetaData',lmtext(id));
if($('#li_'+myB64('/samlIDPMetaDataNode')).find('span').size()==1){
$('#delsamlmetadatab').hide();
}else{
$('#delsamlmetadatab').show();
}
$('#samlMetaData').attr('value',lmtext(id));
display('samlMetaData',lmtext(id));
$('#newsamlmetadatab').show();
}
function samlService(id) {
currentId=id;
......@@ -409,7 +411,7 @@ function newSamlMetaData(){
var name = prompt(text4newSamlMetaData,'authentic');
if(!name){return false;}
var idpId='li_'+myB64('/samlIDPMetaDataExportedAttributes/'+name);
simpleTreeCollection[0].newAjaxNodeIn($('#li_L3NhbWxJRFBNZXRhRGF0YQ2'),idpId,name,scriptname+'?type=new&node=samlIDPMetaData/'+name,function(d,s){
simpleTreeCollection[0].newAjaxNodeIn($('#li_L3NhbWxJRFBNZXRhRGF0YU5vZGU1'),idpId,name,scriptname+'?type=new&node=/samlIDPMetaDataNode/'+name,function(d,s){
$('>span',s).attr('name',name).attr('help','default').attr('id','text_'+idpId).attr('onclick','samlMetaData(\''+idpId+'\')');
samlMetaData(idpId);
});
......
......@@ -192,9 +192,9 @@ sub confNode {
$metadata->initializeFromConfHash($h);
my $text = $target;
$text =~ s/^\/([^\/]+)\/.*$/$1/;
$res .= $self->li("$target")
$res .= $self->li("$target/")
. $self->span(
id => "$target",
id => "$target/",
text => $text,
data => $metadata->toXML(),
js => $js,
......
......@@ -28,7 +28,8 @@ sub import {
$l ||= "en";
foreach $h (
qw(authParams cookieName domain groups ldap macros storage timeout vars
whatToTrace virtualHosts portalForceAuthn default saml samlServicePrivateKey)
whatToTrace virtualHosts portalForceAuthn default samlIDPMetaDataNode
samlServicePrivateKey)
)
{
*{"${caller_package}::help_$h"} = \&{"help_${h}_$l"};
......
......@@ -67,7 +67,7 @@ sub confUpload {
$id =~ s/\r//g;
$id =~ s/^\///;
$id =~ s/(?:\/[^\/]*)?$/\/$name/ if ($NK);
next if ( $id =~ /^(generalParameters|virtualHosts|samlIDPMetaData)/);
next if ( $id =~ /^(generalParameters|virtualHosts|samlIDPMetaDataNode)/);
my ( $confKey, $test ) = $self->getConfTests($id);
my ( $res, $m );
......@@ -132,8 +132,6 @@ sub confUpload {
foreach ( @{ $result->getChildrenByTagName('ignore') } ) {
my $node = $_->getAttribute('value');
$node =~ s/^.*node=(.*?)(?:&.*)?\}$/$1/;
# HACK: do it better, this IS NOT the good solution.
$node =~ s/^(\/?samlIDPMetaData(?!XML|ExportedAttributes))\/.*/$1/;
foreach my $k ( $self->findAllConfKeys( $self->corresp($node) ) ) {
my $v = $self->keyToH( $k, $self->conf );
$v = $self->keyToH( $k, $self->defaultConf ) unless ( defined $v );
......@@ -311,6 +309,30 @@ sub findAllConfKeys {
return @res;
}
## @method protected String formatValue(string key, string value)
# Format a value.
# @param $key String "/path/key"
# @param $value String
# @return A formated value.
sub formatValue {
my ( $self, $key, $value ) = @_;
my $newvalue = $value;
if ( $key =~ /^samlIDPMetaDataXML/ )
{
my $metadata = Lemonldap::NG::Common::Conf::SAML::Metadata->new();
if (ref($value))
{
$metadata->initializeFromConfHash($value);
}
else
{
$metadata->initializeFromXML($value);
}
$newvalue = $metadata->toHash();
}
return $newvalue;
}
## @method protected void setKeyToH(hashref h,string key,string k2,string value)
# Insert key=>$value in $h at the position declared with $key. If $k2 is set,
# insert key=>{$k2=>$value}. Note that $key is splited with "/". The last part
......@@ -324,6 +346,7 @@ sub setKeyToH {
my ( $self, $h, $key, $k2 ) = @_;
my $tmp = $h;
$key =~ s/^\///;
$value = $self->formatValue($key, $value);
while (1) {
if ( $key =~ /\// ) {
my $k = $`;
......
......@@ -42,11 +42,11 @@ sub cstruct {
}
);
}
elsif ($k1 =~ /^samlIDPMetaData/i)
elsif ($k1 =~ /^samlIDPMetaDataNode/i)
{
%$h = (
%$h,
samlIDPMetaData => {
samlIDPMetaDataNode => {
$k2 => {
_nodes => [
qw(samlIDPMetaDataExportedAttributes samlIDPMetaDataXML)
......@@ -73,7 +73,7 @@ sub cstruct {
sub struct {
my $self = shift;
return {
_nodes => [qw(n:generalParameters n:variables n:virtualHosts n:samlServiceMetaData n:samlIDPMetaData)],
_nodes => [qw(n:generalParameters n:variables n:virtualHosts n:samlServiceMetaData n:samlIDPMetaDataNode)],
_help => 'default',
######################
......@@ -272,8 +272,9 @@ sub struct {
########
# SAML #
########
samlIDPMetaData => {
_nodes => ['nhash:/samlIDPMetaDataExportedAttributes:samlIDPMetaData:samlMetaData'],
# virtual keys should not begin like configuration keys.
samlIDPMetaDataNode => {
_nodes => ['nhash:/samlIDPMetaDataExportedAttributes:samlIDPMetaDataNode:samlMetaData'],
_upload => ['/samlIDPMetaDataXML'],
_help => 'default',
_call => '$(\'#newsamlmetadatab\').show();',
......@@ -689,8 +690,23 @@ sub testStruct {
########
# SAML #
########
samlIDPMetaDataExportedAttributes => $testNotDefined,
samlIDPMetaDataXML => $testNotDefined,
samlIDPMetaDataExportedAttributes => {
keyTest => qr/^[a-zA-Z](?:[\w\-\.]*\w)?$/,
keyMsgFail => 'Bad metadata name',
'*' => {
keyTest => qr/^\w([\w\-]*\w)?$/,
keyMsgFail => 'Bad attribute name',
test => $perlExpr,
},
},
samlIDPMetaDataXML => {
keyTest => qr/^[a-zA-Z](?:[\w\-\.]*\w)?$/,
keyMsgFail => 'Bad metadata name',
'*' => {
test => sub { return 1; },
keyTest => sub { return 1; },
},
},
samlServicePrivateKey => $testNotDefined,
samlEntityID => $testNotDefined,
samlOrganizationDisplayName => $testNotDefined,
......@@ -841,7 +857,7 @@ sub subDefaultConf {
return {
locationRules => { default => 'deny' },
exportedHeaders => { 'Auth-User' => '$uid' },
samlIDPMetaDataXML => {},
samlIDPMetaDataXML => { {} },
samlIDPMetaDataExportedAttributes => { 'uid' => ';0;uid;;' },
};
}
......
......@@ -127,7 +127,7 @@ sub en {
saml => 'SAML',
samlServicePrivateKey => 'Private Key',
samlIDPMetaData => 'Identity providers',
samlIDPMetaDataNode => 'Identity providers',
samlIDPMetaDataXML => 'Metadata XML',
samlIDPMetaDataExportedAttributes => 'Exported attributes',
samlServiceMetaData => 'SAML 2 Service',
......@@ -264,7 +264,7 @@ sub fr {
saml => 'SAML',
samlServicePrivateKey => 'Clé privée',
samlIDPMetaData => 'Fournisseurs d\'identités',
samlIDPMetaDataNode => 'Fournisseurs d\'identités',
samlIDPMetaDataXML => 'XML Metadata',
samlIDPMetaDataExportedAttributes => 'Attributs exportés',
samlServiceMetaData => 'Service SAML 2',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment