Created
April 1, 2015 10:13
-
-
Save simong/410f23bb3cd1deefccb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// npm install underscore | |
// npm install xml2js | |
// npm install oae-rest | |
// | |
// wget http://metadata.ukfederation.org.uk/ukfederation-metadata.xml | |
// | |
// Run this script: | |
var _ = require('underscore'); | |
var fs = require('fs'); | |
var xml2js = require('xml2js'); | |
var util = require('util'); | |
var RestContext = require('oae-rest/lib/model').RestContext; | |
var RestAPI = require('oae-rest'); | |
var restContext = new RestContext('http://admin.oae-qa0.oaeproject.org', { | |
'username': 'administrator', | |
'userPassword': 'administrator', | |
'hostHeader': 'admin.oae.com', | |
'refererHeader': '/', | |
'strictSSL': false | |
}); | |
RestAPI.Authentication.login(restContext, restContext.username, restContext.userPassword, function(err) { | |
if (err) { | |
console.log('Could not log in'); | |
} | |
var parser = new xml2js.Parser(); | |
fs.readFile('ukfederation-metadata.xml', function(err, data) { | |
parser.parseString(data, function (err, result) { | |
_.each(result.EntitiesDescriptor.EntityDescriptor, function(entityDescriptor) { | |
if (entityDescriptor.IDPSSODescriptor) { | |
var displayName = 'Unknown'; | |
var tenantAlias = _.random(0, 1000000000); | |
var hostname = util.format('%s.oaeproject.org', tenantAlias); | |
var idp = entityDescriptor['$'].entityID; | |
if (entityDescriptor.Organization) { | |
displayName = entityDescriptor.Organization[0].OrganizationDisplayName[0]['_']; | |
} | |
RestAPI.Tenants.createTenant(restContext, tenantAlias, displayName, hostname, function(err) { | |
if (err) { | |
console.log('Failed to create tenant') | |
console.log(err); | |
} | |
// Configure Shibboleth | |
var update = { | |
'oae-authentication/shibboleth/enabled': true, | |
'oae-authentication/shibboleth/idpEntityID': idp | |
}; | |
RestAPI.Config.updateConfig(restContext, tenantAlias, update, function(err) { | |
if (err) { | |
console.log('Failed to update config') | |
console.log(err); | |
} | |
}) | |
}); | |
} | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment