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

Added authentication type to the ImportUsers tool #210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
110 changes: 98 additions & 12 deletions src/software/js-samples/importUsers.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ <h3>Import users</h3>
<input id="import-password" type="password" placeholder="Minimum of 8 characters" maxlength="255" />
<label style="font-size: 14px; margin-top: 10px;"><input id="import-password-reset" style="float:none" type="checkbox" title="This user will need to enter a new password the first time they log in to the database.">Force password change on next login</label>
</p>
<p>

<label for="import-authType">Authentication Type</label>

<select name="authType" id="import-authType" style="height: 33px;">
<option value="BasicAuthentication">Basic Authentication</option>
</select>
<select id="import-authType-certificate" data-placeholder="Select user certificate" style="height: 33px; display:none;"></select>
</p>

<p>
<label for="import-groups">Groups</label>
<select id="import-groups" multiple data-placeholder="Select groups"></select>
Expand Down Expand Up @@ -765,6 +775,7 @@ <h2>Help</h2>
var passwordResetCheckbox = document.getElementById("import-password-reset");
var hosRulesetArray = [];
var moreCalls = [];
var certificates = {};

function toggleDocs(event) {

Expand Down Expand Up @@ -800,8 +811,8 @@ <h2>Help</h2>
groupCache = refreshGroupCache(null);
securityClearanceCache = refreshSecurityClearanceCache(null);
timeZoneCache = refreshTimeZoneCache(null);
getCertificates(null);
document.getElementById("content").addEventListener("keyup", function(event) {
event.preventDefault();

Expand Down Expand Up @@ -914,10 +925,10 @@ <h2>Help</h2>
newContent += user.phoneNumberExtension + ",";
newContent += user.designation + ",";
newContent += user.employeeNo + ",";
newContent += user.fuelEconomyUnit + ",";
newContent += user.fuelEconomyUnit + ","; //16
newContent += user.isMetric + ",";
newContent += user.isLabsEnabled + ",";
newContent += user.timeZoneId + ",";
newContent += user.timeZoneId + ","; // 19
newContent += user.authorityName + ",";
newContent += user.authorityAddress + ",";
newContent += user.carrierNumber + ",";
Expand All @@ -927,7 +938,9 @@ <h2>Help</h2>
newContent += user.licenseProvince + ",";
newContent += user.hosRuleSet + ",";
newContent += user.isYardMoveEnabled + ",";
newContent += user.isPersonalConveyanceEnabled;
newContent += user.isPersonalConveyanceEnabled + ",";
newContent += user.userAuthenticationType + ",";
newContent += user.userSelectedCertificate;

document.getElementById("content").value = newContent;
document.getElementById("importUsers").disabled = false;
Expand Down Expand Up @@ -958,8 +971,8 @@ <h2>Help</h2>

for (i = 0; i < users.length; i++) {
var split = users[i].split(",");

if (split.length !== 28) {
if (split.length !== 30) {
alert("Missing necessary information from user: " + users[i]);
continue;
}
Expand Down Expand Up @@ -990,7 +1003,9 @@ <h2>Help</h2>
var licenseProvince = split[24];
var hosRuleSet = split[25];
var isYardMoveEnabled = split[26];
var isPersonalConveyanceEnabled = split[27];
var isPersonalConveyanceEnabled = split[27];
var userAuthenticationType = split[28];
var userSelectedCertificate = split[29];

// when pasting in ',' seperated string make sure values aren't empty
if (isYardMoveEnabled === '') {
Expand All @@ -1008,7 +1023,7 @@ <h2>Help</h2>
companyGroups: groups,
reportGroups: reportGroups,
securityGroups: securityGroups,
userAuthenticationType: "BasicAuthentication",
userAuthenticationType: userAuthenticationType,
activeFrom: new Date().toISOString(),
activeTo: "2050-01-01T00:00:00.000Z",
countryCode: countryCode,
Expand All @@ -1030,6 +1045,14 @@ <h2>Help</h2>
isYardMoveEnabled: isYardMoveEnabled,
isPersonalConveyanceEnabled: isPersonalConveyanceEnabled
};

if (newUser.userAuthenticationType == 'SAML') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks off here.
Should use === in js?


newUser.issuerCertificate = {
id: userSelectedCertificate,
isRoot: certificates[userSelectedCertificate].isRoot
};
}

if (keys.length > 0){
newUser.driverGroups = groups;
Expand All @@ -1056,7 +1079,7 @@ <h2>Help</h2>
}
]);
}

api.multiCall(calls, function(results) {
var userIds = results;
pushRulesets(userIds);
Expand Down Expand Up @@ -1104,6 +1127,7 @@ <h2>Help</h2>
}
}
}

}
});

Expand Down Expand Up @@ -1179,8 +1203,16 @@ <h2>Help</h2>
var isPersonalConveyanceEnabled = true;
} else {
var isPersonalConveyanceEnabled = false;
}
}

var selectedAuthType = document.getElementById("import-authType").value;

if (selectedAuthType == 'SAML') {
var selectedCertificate = document.getElementById("import-authType-certificate").value;
} else {
var selectedCertificate = null;
}

return {
userName: document.getElementById("import-userName").value,
firstName: document.getElementById("import-firstName").value,
Expand Down Expand Up @@ -1209,7 +1241,9 @@ <h2>Help</h2>
licenseProvince: plateState,
hosRuleSet: document.getElementById("options_hosRuleSet").value,
isYardMoveEnabled: isYardMoveEnabled,
isPersonalConveyanceEnabled: isPersonalConveyanceEnabled
isPersonalConveyanceEnabled: isPersonalConveyanceEnabled,
userAuthenticationType: selectedAuthType,
userSelectedCertificate: selectedCertificate
}
}

Expand Down Expand Up @@ -1307,6 +1341,58 @@ <h2>Help</h2>
console.log(error);
});
}


function getCertificates(callback) {
var selectAuthType = document.getElementById("import-authType");
var select = document.getElementById("import-authType-certificate");

document.getElementById("import-authType").addEventListener('change', function(event) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this event listener should be lumped in with the getCertificates method?


if (event.target.value == 'SAML'){
select.style.display = '';
} else {
select.style.display = 'none';
}

});

api.call("Get", {
"typeName":"Certificate"
}, function(result) {
if (result !== undefined && result != null && result.length > 0) {

for (i = 0; i < result.length; i++) {

var option = new Option();
option.text = result[i].issuer;
option.value = result[i].id;
select.add(option);

certificates[result[i].id] = {
name: result[i].issuer,
id : result[i].id,
isRoot: result[i].isRoot
};
}

var option = new Option();
option.text = "SAML";
option.value = "SAML";
selectAuthType.add(option);

select.style.display = 'none';
//return certificates;

}
if (callback) {
callback();
}
}, function(error) {
console.log(error);
});
}


function refreshGroupCache(callback) {
var select = document.getElementById("import-groups");
Expand Down
Binary file modified src/software/js-samples/templates/import-users-template.xlsx
Binary file not shown.