Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Latest commit dec871f Jan 3, 2018 History
0 contributors

Users who have contributed to this file

402 lines (364 sloc) 8.77 KB
/**
* A representation of a SAML entity
*
* Requires:
* http-utils.js
*/
/**
* SAMLEntity constructor
*/
var SAMLEntity = function (entity) {
this.entity = entity;
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getEntityID = function () {
return this.entity.entityID;
};
/**
* @returns {array}
*/
SAMLEntity.prototype.getEntityAttributes = function () {
var attributes = this.entity.EntityAttributes;
if (attributes == null) {
return [];
}
return attributes;
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getErrorURL = function () {
if (this.isIdP()) {
return this.entity.IDPSSODescriptor.errorURL;
} else {
return null;
}
};
SAMLEntity.prototype.hasErrorURL = function () {
var errorURL = this.getErrorURL();
return (errorURL != null && errorURL != "");
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getDisplayName = function () {
if (this.isIdP()) {
return this.entity.IDPSSODescriptor.DisplayName;
} else if (this.isSP()) {
return this.entity.SPSSODescriptor.DisplayName;
} else {
return null;
}
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getDescription = function () {
if (this.isIdP()) {
return this.entity.IDPSSODescriptor.Description;
} else if (this.isSP()) {
return this.entity.SPSSODescriptor.Description;
} else {
return null;
}
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getInformationURL = function () {
if (this.isIdP()) {
return this.entity.IDPSSODescriptor.InformationURL;
} else if (this.isSP()) {
return this.entity.SPSSODescriptor.InformationURL;
} else {
return null;
}
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getPrivacyStatementURL = function () {
if (this.isIdP()) {
return this.entity.IDPSSODescriptor.PrivacyStatementURL;
} else if (this.isSP()) {
return this.entity.SPSSODescriptor.PrivacyStatementURL;
} else {
return null;
}
};
/**
* A <code>Logo</code> object has three properties:
* <ol>
* <li><code>value</code></li>
* <li><code>width</code></li>
* <li><code>height</code></li>
* </ol>
* The <code>value</code> is the URL location of the logo.
* The <code>width</code> and <code>height</code> are the
* actual width and height of the logo.
*
* @returns {object}
*/
SAMLEntity.prototype.getLogo = function () {
if (this.isIdP()) {
return this.entity.IDPSSODescriptor.Logo;
} else if (this.isSP()) {
return this.entity.SPSSODescriptor.Logo;
} else {
return null;
}
};
/**
* An <code>AttributeConsumingService</code> object has three
* properties:
* <ol>
* <li><code>ServiceName</code></li>
* <li><code>ServiceDescription</code></li>
* <li><code>RequestedAttributes</code></li>
* </ol>
* For convenience, getter methods are provided for each of these
* properties.
*
* @returns {object}
*/
SAMLEntity.prototype.getAttributeConsumingService = function () {
if (this.isSP()) {
return this.entity.SPSSODescriptor.AttributeConsumingService;
} else {
return null;
}
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getServiceName = function () {
var attributeConsumingService = this.getAttributeConsumingService();
if (attributeConsumingService == null) {
return null;
}
return attributeConsumingService.ServiceName;
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getServiceDescription = function () {
var attributeConsumingService = this.getAttributeConsumingService();
if (attributeConsumingService == null) {
return null;
}
return attributeConsumingService.ServiceDescription;
};
/**
* @returns {array}
*/
SAMLEntity.prototype.getRequestedAttributes = function () {
var attributeConsumingService = this.getAttributeConsumingService();
if (attributeConsumingService == null) {
return [];
}
return attributeConsumingService.RequestedAttributes;
};
/**
* @returns {object}
*/
SAMLEntity.prototype.getOrganization = function () {
return this.entity.Organization;
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getOrganizationName = function () {
var organization = this.getOrganization();
if (organization == null) {
return null;
}
return this.entity.Organization.OrganizationName;
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getOrganizationDisplayName = function () {
var organization = this.getOrganization();
if (organization == null) {
return null;
}
return this.entity.Organization.OrganizationDisplayName;
};
/**
* @returns {string}
*/
SAMLEntity.prototype.getOrganizationURL = function () {
var organization = this.getOrganization();
if (organization == null) {
return null;
}
return this.entity.Organization.OrganizationURL;
};
/**
* Gets and returns an array of contacts. Returns an empty array
* if there are no contacts.
*
* @returns {array}
*/
SAMLEntity.prototype.getContactPersons = function () {
var contacts = this.entity.ContactPersons;
if (contacts == null) {
return [];
}
return contacts;
};
/**
* The name of the IdP is given by the following precedence rule:
*
* <mdui:DisplayName> => <md:OrganizationDisplayName> => entityID
*
* The name of the SP is given by the following precedence rule:
*
* <mdui:DisplayName> => <md:ServiceName> => entityID
*
* Note that multiple <md:AttributeConsumingService> elements implies
* multiple <md:ServiceName> elements, which causes the above rule to
* break down. (Supporting multiple <md:AttributeConsumingService>
* elements is difficult in, oh, so many ways!)
*
* @returns {string}
*/
SAMLEntity.prototype.getDefaultDisplayName = function () {
var displayName = this.getDisplayName();
if (displayName == null || displayName == "") {
if (this.isIdP()) {
displayName = this.getOrganizationDisplayName();
} else if (this.isSP()) {
displayName = this.getServiceName();
} else {
return null;
}
if (displayName == null || displayName == "") {
displayName = this.getEntityID();
}
}
return displayName;
};
/**
* A comparison function for sorting purposes. Takes a pair
* SAMLEntity objects and returns -1, 0, or 1 depending on
* the display names of the two objects.
*/
SAMLEntity.comparison_function = function (a, b) {
var a_key = a.getDefaultDisplayName();
var b_key = b.getDefaultDisplayName();
return (a_key < b_key) ? -1 : ((a_key > b_key) ? 1 : 0);
};
/**
* The URL to the entity info page for this entity.
*
* @returns {string}
*/
SAMLEntity.prototype.getEntityInfoURL = function (prefix) {
var search = utils.initQueryString('entityID', this.entity.entityID);
if (typeof prefix === 'undefined') {
prefix = './';
}
return prefix + 'entity.html' + search;
}
/**
* The absolute URL to the entity info page for this entity.
*
* @returns {string}
*/
SAMLEntity.prototype.getAbsEntityInfoURL = function () {
return this.getEntityInfoURL('https://incommon.org/federation/info/');
}
/**
* The URL to the org info page for this entity.
*
* @returns {string}
*/
SAMLEntity.prototype.getOrgInfoURL = function (prefix) {
var search = utils.initQueryString('orgName', this.getOrganizationName());
if (typeof prefix === 'undefined') {
prefix = './';
}
return prefix + 'org.html' + search;
}
/**
* The absolute URL to the org info page for this entity.
*
* @returns {string}
*/
SAMLEntity.prototype.getAbsOrgInfoURL = function () {
return this.getOrgInfoURL('https://incommon.org/federation/info/');
}
/**
* @returns {boolean}
*/
SAMLEntity.prototype.hasAdminContact = function () {
return this.hasContactType("administrative");
};
/**
* @returns {boolean}
*/
SAMLEntity.prototype.hasTechContact = function () {
return this.hasContactType("technical");
};
/**
* @returns {boolean}
*/
SAMLEntity.prototype.hasSupportContact = function () {
return this.hasContactType("support");
};
/**
* @returns {boolean}
*/
SAMLEntity.prototype.hasContactType = function (type) {
var i;
var contacts = this.getContactPersons();
for (i = 0; i < contacts.length; i += 1) {
if (contacts[i].contactType === type) {
return true;
}
}
return false;
};
/**
* @returns {array}
*/
SAMLEntity.prototype.getContactEmailAddresses = function () {
var i;
var items = [];
var contacts = this.getContactPersons();
for (i = 0; i < contacts.length; i += 1) {
if (!(items[contacts[i].contactType] instanceof Object)) {
items[contacts[i].contactType] = [];
}
items[contacts[i].contactType].push(
SAMLEntity.getFullEmailAddress(contacts[i])
);
}
return items;
};
/**
* @returns {string}
*/
SAMLEntity.getFullEmailAddress = function (contact) {
var fullEmailAddress = '"' + contact.GivenName;
if (contact.SurName != null && contact.SurName != "") {
fullEmailAddress += ' ' + contact.SurName;
}
fullEmailAddress += '" <' + contact.EmailAddress + '>';
return fullEmailAddress;
};
/**
* @returns {boolean}
*/
SAMLEntity.prototype.isIdP = function () {
return (this.entity.IDPSSODescriptor != null);
};
/**
* @returns {boolean}
*/
SAMLEntity.prototype.isSP = function () {
return (this.entity.SPSSODescriptor != null);
};