Commit 940ca006 authored by Lukas Haemmerle's avatar Lukas Haemmerle

Ensure that IdP domain cookie array contains no more than 5 elements

parent ba284bc1
...@@ -220,20 +220,35 @@ function setDomainSAMLDomainCookie(entityID){ ...@@ -220,20 +220,35 @@ function setDomainSAMLDomainCookie(entityID){
// Create and store SAML domain cookie on host where WAYF is embedded // Create and store SAML domain cookie on host where WAYF is embedded
var currentDomainCookie = getCookie('_saml_idp'); var currentDomainCookie = getCookie('_saml_idp');
var encodedEntityID = encodeBase64(entityID); var encodedEntityID = encodeBase64(entityID);
if (currentDomainCookie == null){ if (currentDomainCookie == null){
currentDomainCookie = ''; currentDomainCookie = '';
} }
var oldIdPs = currentDomainCookie.split(' '); // Ensure current IdP is not already in array
var newCookie = ''; var currentIdPs = currentDomainCookie.split(' ');
for (var i = 0; i < oldIdPs.length; i++) { var newIdPs = new Array();
if (oldIdPs[i] != encodedEntityID && oldIdPs[i] != ''){ for (var i = 0; i < currentIdPs.length; i++) {
newCookie += oldIdPs[i] + ' '; if (currentIdPs[i] != encodedEntityID && currentIdPs[i] != ''){
newIdPs.push(currentIdPs[i]);
} }
} }
newCookie += encodedEntityID;
setCookie('<?php echo $SAMLDomainCookieName ?>', newCookie , 100); // Add new IdP
newIdPs.push(encodedEntityID);
// Ensure array is no longer than 5 IdPs
while (newIdPs.length > 5){
newIdPs.shift();
}
// Compose cookie value
var newDomainCookie = '';
for (var i = 0; i < newIdPs.length; i++) {
newDomainCookie += newIdPs[i] + ' ';
}
// Set cookie value
setCookie('<?php echo $SAMLDomainCookieName ?>', newDomainCookie.trim() , 100);
} }
function setCookie(c_name, value, expiredays){ function setCookie(c_name, value, expiredays){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment