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

107 lines (94 sloc) 2.9 KB
/**
* ProtocolEntity constructor
*
* See protocol-entity-schema.json for the definition of a ProtocolEntity.
*
* This constructor adds the following properties and objects:
*
* {boolean} this.entity.isIdP
* {boolean} this.entity.isSP
* {string} this.entity.displayName['IDPSSODescriptor']
* {string} this.entity.displayName['SPSSODescriptor']
*
*/
var ProtocolEntity = function (entity) {
var j;
var role_type;
var num_roles = new Object;
var displayName = new Object;
// capture this entity
this.entity = entity;
this.entity.displayName = new Object;
// count the number of roles of each type
for (j = 0; j < this.entity.roles.length; j += 1) {
role_type = this.entity.roles[j].type;
// initialize objects
if (typeof num_roles[role_type] === 'undefined') {
num_roles[role_type] = 0;
// opportunistically compute the entity displayName for this role
displayName[role_type] = this.entity.roles[j].displayName;
if (displayName[role_type] == null) {
displayName[role_type] = this.entity.entityID;
}
}
num_roles[role_type] += 1;
}
// If this entity descriptor contains one (and only one) IDPSSODescriptor,
// then this entity is (by definition) an IdP. Likewise, if there is one
// (and only one) SPSSODescriptor, then this entity is an SP.
//
// Note that a given entity may have both an IdP role and an SP role
// (e.g., an IdP Proxy is such an entity by definition). Also note that
// every entity is assumed to have at least one role, but this algorithm
// does not (and can not) identify all roles since the set of roles can
// not be positively enumerated.
//
this.entity.isIdP = false;
this.entity.isSP = false;
this.entity.displayName['IDPSSODescriptor'] = null;
this.entity.displayName['SPSSODescriptor'] = null;
if (num_roles['IDPSSODescriptor'] === 1) {
this.entity.isIdP = true;
this.entity.displayName['IDPSSODescriptor'] = displayName['IDPSSODescriptor'];
}
if (num_roles['SPSSODescriptor'] === 1) {
this.entity.isSP = true;
this.entity.displayName['SPSSODescriptor'] = displayName['SPSSODescriptor'];
}
};
/**
* @returns {string}
*/
ProtocolEntity.prototype.getEntityID = function () {
return this.entity.entityID;
};
/**
* @returns {string}
*/
ProtocolEntity.prototype.getRegistrarID = function () {
return this.entity.registrarID;
};
/**
* @returns {string}
*/
ProtocolEntity.prototype.getIdPDisplayName = function () {
return this.entity.displayName['IDPSSODescriptor'];
};
/**
* @returns {string}
*/
ProtocolEntity.prototype.getSPDisplayName = function () {
return this.entity.displayName['SPSSODescriptor'];
};
/**
* @returns {boolean}
*/
ProtocolEntity.prototype.isIdP = function () {
return this.entity.isIdP;
};
/**
* @returns {boolean}
*/
ProtocolEntity.prototype.isSP = function () {
return this.entity.isSP;
};