SAML: metadata could be now loaded through URL

This commit is contained in:
Thomas CHEMINEAU 2010-03-12 12:56:14 +00:00
parent 60501cb715
commit a8865ee094
5 changed files with 96 additions and 15 deletions

View File

@ -196,3 +196,21 @@ input
background:#ddd;
font-weight:bold;
}
/* Filearea */
#content_filearea table tr td
{
text-align:left;
vertical-align:center;
}
#content_filearea table
{
margin-left:auto;
margin-right:auto;
padding-left:20px;
}
#content_filearea span.loadimg
{
display:inline-block;
width:20px;
}

View File

@ -157,18 +157,19 @@ function setlmtext(id,v){
function setlmdata(id,v){
$('#text_'+id).attr('value',escape(v));
}
function setlmfile(id){
$("#fileloading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
function setlmfile(id,input){
var inputname=$(input).attr('id');
$("#"+inputname+"-loadimg")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
$.ajaxFileUpload({
url:scriptname,
secureuri:false,
fileElementId:'file',
fileElementId:inputname,
dataType:'json',
success:function(data,status){
if(typeof(data.errors) != 'undefined' && data.errors != ''){
@ -184,6 +185,8 @@ function setlmfile(id){
$('#help_content').html('<h3>Request failed</h3> Error code: '+xhr.status+', '+thrownError);
}
});
/* Remove global event on loading image */
$("#"+inputname+"-loadimg").unbind('ajaxStart');
return false;
}
function setlmsamlassertion(id){

View File

@ -169,12 +169,28 @@
<!-- File textarea -->
<div id="content_filearea" class="hidden">
<textarea readonly id="filearea" cols="80" rows="10"></textarea>
<p><lang en="Load from a file:" fr="Charger depuis un fichier:" /></p>
<input type="file" name="file" id="file" size="50" style="margin-left:23px;"/>
<button onclick="setlmfile(currentId);return false;" class="ui-state-default ui-corner-all">
<lang en="Load" fr="Charger" />
</button>
<span style="display:inline-block;width:20px;"><img id="fileloading" name="fileloading" src="<TMPL_VAR NAME="DIR">/ajax-loader.gif" style="vertical-align:middle;" /></span>
<table class="filearea">
<tr>
<td><lang en="Load from a file" fr="Charger depuis un fichier" /> :</td>
<td>
<input type="file" name="file" id="file" size="30"/>
</td>
<td>
<button onclick="setlmfile(currentId,file);return false;" class="ui-state-default ui-corner-all"><lang en="Load" fr="Charger" /></button>
<span class="loadimg"><img class="hidden" id="file-loadimg" src="<TMPL_VAR NAME="DIR">/spinner.gif" /></span>
</td>
</tr>
<tr>
<td><lang en="Load from a URL" fr="Charger depuis une URL" /> :</td>
<td>
<input type="text" name="url" id="url" size="40"/>
</td>
<td>
<button onclick="setlmfile(currentId,url);return false;" class="ui-state-default ui-corner-all"><lang en="Load" fr="Charger" /></button>
<span class="loadimg"><img class="hidden" id="url-loadimg" src="<TMPL_VAR NAME="DIR">/spinner.gif" /></span>
</td>
</tr>
</table>
</div>
<!-- Specific to securedCookie (TODO push in _Struct.pm) -->

View File

@ -73,6 +73,14 @@ sub new {
$self->quit();
}
# URL upload
elsif ( my $rurl = $self->rparam('url') ) {
require Lemonldap::NG::Manager::Uploader; #inherits
$self->urlUpload('url');
$self->quit();
}
# Else load conf
require Lemonldap::NG::Manager::Downloader; #inherits
$self->{cfgNum} =

View File

@ -10,6 +10,7 @@ use XML::LibXML;
use XML::LibXSLT;
use MIME::Base64;
use JSON;
use LWP::Simple;
# TODO
use Data::Dumper;
@ -299,6 +300,41 @@ sub fileUpload {
$self->quit();
}
## @method public void fileUpload (fieldname)
# Retrieve a file from an URL, and return it. This function is for
# some functionnalities into the SAML2 modules of the manager, accessing
# to data through Ajax requests.
# @param $fieldname The name of the html input field that contains the URL.
sub urlUpload {
my $self = shift;
my $fieldname = shift;
# Get the URL
my $url = ${$self->rparam($fieldname)};
# Get contents from URL
print STDERR "---> " . $url . "\n";
my $content = get $url;
$content = '' unless(defined $content);
$content =~ s!<!&lt;!g;
$content =~ s!>!&gt;!g;
# Build JSON reponse
my $json = new JSON();
$json = $json->allow_nonref(['1']);
$json = $json->utf8(['1']);
my $json_content = $json->encode($content);
my $buf = '{"status":"OK", "content":' . $json_content . '}';
# Send JSON response
# text/html is recommended header for JSON data retrieved by JQuery.
print $self->header(
-type => 'text/html',
-Content_Length => length($buf)
) . $buf;
$self->quit();
}
## @method protected array applyTest(void* test,string value)
# Apply the test to the value and return the result and an optional message
# returned by the test if the sub ref.