Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option to use a Shibboleth SP discovery feed for metadata filtering #53

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions discojuice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Example for using the Shibboleth SP DiscoFeed for metadata filtering

```javascript

// base path of your application
var appUrl = "https://www.example.com";

// url to redirect to after the SSO login process was completed
var targetUrl = appUrl + "/login/shibboleth";

// setup discojuice with metadata filtering using the Shibboleth DiscoFeed
$('#disco-juice-login-link')
.DiscoJuice({
"title" : "Shibboleth Login",
"subtitle" : "Please choose your organization from the list",

"cookie" : false,
"location" : true,
"country" : false,
//"countryAPI" : "https://cdn.discojuice.org/country",

"discoPath" : "https://cdn.discojuice.org/",
"redirectURL": appUrl + "/Shibboleth.sso/Login?target=" + encodeURIComponent(targetUrl) + "&entityID=",
"spentityid" : appUrl + "/Shibboleth.sso/Metadata",
"discofeed" : appUrl + '/Shibboleth.sso/DiscoFeed', //FFX
"metadata" : ['https://cdn.discojuice.org/feed/dfn'], // DFN-AAI

"callback" : function (e, djc) {
var returnto = window.location.href;
var options = djc.parent.Utils.options;
var redirectURL = options.get('redirectURL');
if (redirectURL) {
var newlocation = redirectURL + escape(e.entityID);
//console.log("Redirecting to " + newlocation);
window.location = newlocation;
}
else alert("DiscoJuice is misconfigured. You need to provide a redirectURL to send the user when a provider is selected.");
},

});
```
2 changes: 1 addition & 1 deletion discojuice/css/discojuice.css
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ div.discojuice div.scroller a {
color: #333;
text-shadow: 0 1px #fff;
font-size: 135%;
font-family: "Arial Narrow", "Arial", sans-serif;
font-family: "Arial", sans-serif;
text-decoration: none;
}

Expand Down
139 changes: 112 additions & 27 deletions discojuice/discojuice.control.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ DiscoJuice.Control = {
metadataurls = metadataurl;
}


// immediately set inlinemetadata
if (typeof inlinemetadata === 'object' && inlinemetadata) {
this.data = inlinemetadata;
}


this.parent.Utils.log('metadataurl is ' + metadataurl);
if (!metadataurl) return;
//this.parent.Utils.log('metadataurl is ' + metadataurl);
console.log("METADATAURLS", metadataurls);
if (!metadataurls) return;

// If SP EntityID is set in configuration make sure it is sent as a parameter
// to the feed endpoint.
Expand All @@ -101,36 +104,58 @@ DiscoJuice.Control = {
parameters.entityID = discosettings.spentityid;
}

// load metadata from urls
that.parent.Utils.log('Setting up load() waiter');
waiter = DiscoJuice.Utils.waiter(function() {
that.parent.Utils.log('load() waiter EXECUTE');
that.postLoad();
that.filterDiscoFeed();
}, 10000);

// console.log("METADATAURLS", metadataurls);

for (i = 0; i < metadataurls.length; i++) {
curmdurl = metadataurls[i];
waiter.runAction(
function(notifyCompleted) {
var j = i+1;
$.ajax({
url: curmdurl,
dataType: 'jsonp',
jsonpCallback: function() {
// Important to use a reliable hash function for caching purposes
// same URL will always result in same callback function.
return '_' + (that.parent.Utils.murmurhash3_32_gc(curmdurl, 0)).toString(36);
},
cache: true,
data: parameters,
success: function(data) {
that.data = $.merge(that.data, data);
//that.mergeData(data);
that.parent.Utils.log('Successfully loaded metadata (' + data.length + ') (' + j + ' of ' + metadataurls.length + ')');
notifyCompleted();
}
});

function successCallback(data) {
that.data = $.merge(that.data, data);
that.parent.Utils.log('Successfully loaded metadata (' + data.length + ') (' + j + ' of ' + metadataurls.length + ')');
notifyCompleted();
}



var isLocalDomain = curmdurl.startsWith('/');
if (!isLocalDomain) {
var curmdDomain = curmdurl.match(/^http[s]?:\/\/[^/]+/)[0];
var curBrowserDomain = window.location.href.match(/^http[s]?:\/\/[^/]+/)[0];
isLocalDomain = (curmdDomain == curBrowserDomain);
}

if (isLocalDomain) {
console.log("Fetching metadata from local domain as JSON: " + curmdurl);
$.ajax({
url: curmdurl,
dataType: 'json',
cache: true,
data: parameters,
success: successCallback
});

}
else {
console.log("Fetching metadata from external domain as JSONP: " + curmdurl);
var callback = '_' + (that.parent.Utils.murmurhash3_32_gc(curmdurl, 0)).toString(36);
$.ajax({
url: curmdurl,
dataType: 'jsonp',
jasonp: callback,
cache: true,
data: parameters,
success: successCallback
});
}

},
// Callback function that will be executed if action completed after timeout.
Expand All @@ -144,19 +169,79 @@ DiscoJuice.Control = {
}

waiter.startTimer();




},

"filterDiscoFeed": function() {
var that = this;

// load metadata from SP discoFeed url
var discofeedurl = this.parent.Utils.options.get('discofeed');
if (!discofeedurl) that.postLoad();
else {
that.parent.Utils.log('Setting up load() waiter');
waiter = DiscoJuice.Utils.waiter(function() {
that.parent.Utils.log('load() waiter EXECUTE');
that.postLoad();
}, 5000);

console.log("DISCOFEEDURL", discofeedurl);
waiter.runAction(
function(notifyCompleted) {
$.ajax({
url: discofeedurl,
dataType: 'json',
cache: false,
success: function(data) {
var mappedData = [];
var filteredData = [];

for (i = 0; i < data.length; i++) {
var entry = data[i];
var mappedEntry = {
"title" : entry.DisplayNames[0].value,
"entityID" : entry.entityID,
};
//console.log(mappedEntry);
mappedData.push(mappedEntry);

// look for existing metadata entry and add all that are also found in discofeed
for (j = 0; j < that.data.length; j++) {
//console.log(that.data[j]);
//console.log(this.data[j].entityID + " vs " + mappedEntry.entityID);
if (that.data[j].entityID == mappedEntry.entityID) {
filteredData.push(that.data[j]);
}
}
}
//that.data = $.merge(that.data, mappedData);
console.log(filteredData);
that.data = filteredData;

that.parent.Utils.log('Successfully loaded JSON metadata from discofeed '+discofeedurl+' (' + mappedData.length + ')');
notifyCompleted();
}
});
},
// Callback function that will be executed if action completed after timeout.
function () {
return function() {
that.ui.error("DiscoFeed retrieval from [" + discofeedurl + "] to slow. Ignoring response.");
}
}()

);
}
},

"postLoad": function() {
var
that = this,
waiter;

if (!this.data) return;



// Iterate through entities, and update title from DisplayNames to support Shibboleth integration.
for(i = 0; i < this.data.length; i++) {
if (!this.data[i].title) {
Expand Down Expand Up @@ -574,7 +659,7 @@ DiscoJuice.Control = {

"selectProvider": function(entityID, subID) {

// console.log('entityid: ' + entityID);
console.log('entityid: ' + entityID);


var callback;
Expand Down Expand Up @@ -1020,4 +1105,4 @@ DiscoJuice.Control = {
}


};
};
2 changes: 1 addition & 1 deletion discojuice/discojuice.hosted.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ DiscoJuice.Hosted = {
});

}
};
};