Skip to content

Commit

Permalink
[web-app][service] post json for auth configuration instead of form u…
Browse files Browse the repository at this point in the history
…rl encoded with json string
  • Loading branch information
restjohn committed Oct 25, 2023
1 parent 9b8e12d commit 6853951
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
19 changes: 7 additions & 12 deletions service/src/routes/authenticationconfigurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ module.exports = function (app, security) {
access.authorize('READ_AUTH_CONFIG'),
function (req, res, next) {
const includeDisabled = req.query.includeDisabled === 'true' ? true :
req.query.includeDisabled === 'false' ? false :
req.query.includeDisabled;
AuthenticationConfiguration.getAllConfigurations().then(configs => {
req.query.includeDisabled === 'false' ? false : req.query.includeDisabled;
AuthenticationConfiguration.getAllConfigurations().then(configs => {
const filtered = configs.filter(config => {
if (!config.enabled) {
if (includeDisabled) {
Expand All @@ -34,7 +33,7 @@ module.exports = function (app, security) {
});

const promises = [];

filtered.forEach(config => {
promises.push(SecurePropertyAppender.appendToConfig(config));
});
Expand Down Expand Up @@ -79,14 +78,12 @@ module.exports = function (app, security) {
enabled: req.body.enabled,
settings: {}
};

const securityData = {};

const settings = JSON.parse(req.body.settings);
const { settings } = req.body;

Object.keys(settings).forEach(key => {
if (blacklist && blacklist.indexOf(key.toLowerCase()) != -1) {
if(AuthenticationConfiguration.secureMask !== settings[key]) {
if (AuthenticationConfiguration.secureMask !== settings[key]) {
securityData[key] = settings[key];
}
} else {
Expand Down Expand Up @@ -150,10 +147,8 @@ module.exports = function (app, security) {
enabled: req.body.enabled,
settings: {}
};

const securityData = {};

const settings = JSON.parse(req.body.settings);
const { settings } = req.body;

Object.keys(settings).forEach(key => {
if (blacklist && blacklist.indexOf(key.toLowerCase()) != -1) {
Expand All @@ -176,7 +171,7 @@ module.exports = function (app, security) {
return Promise.all(response);
}).then(response => {
// Read any authentications that could be attached to this config
// For example:
// For example:
// 1. authentications attached to saml
// 2. saml removed
// 3. Authentications attached to saml no longer have a config
Expand Down
35 changes: 20 additions & 15 deletions web-app/src/ng1/factories/authentication-configuration.service.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
function AuthenticationConfigurationService($http, $httpParamSerializer) {

const service = {
getAllConfigurations: getAllConfigurations,
updateConfiguration: updateConfiguration,
deleteConfiguration: deleteConfiguration,
createConfiguration: createConfiguration,
countUsers: countUsers
};

return service;
function AuthenticationConfigurationService($http, $httpParamSerializer) {

function getAllConfigurations(options) {
options = options || {};

return $http.get('/api/authentication/configuration/', { params: options });
}

/**
* TODO: why is this using form encoding instead of straight json?
*/
function updateConfiguration(config) {
return $http.put('/api/authentication/configuration/' + config._id, $httpParamSerializer(config), {
headers: { "Content-Type": "application/x-www-form-urlencoded" }
return $http.put('/api/authentication/configuration/' + config._id, config, {
headers: {
'content-type': 'application/json'
}
});
}

Expand All @@ -27,14 +22,24 @@ function AuthenticationConfigurationService($http, $httpParamSerializer) {
}

function createConfiguration(config) {
return $http.post('/api/authentication/configuration/', $httpParamSerializer(config), {
headers: { "Content-Type": "application/x-www-form-urlencoded" }
return $http.post('/api/authentication/configuration/', config, {
headers: {
'content-type': 'application/json'
}
});
}

function countUsers(id) {
return $http.get('/api/authentication/configuration/count/' + id);
}

return {
getAllConfigurations,
updateConfiguration,
deleteConfiguration,
createConfiguration,
countUsers
};
};

module.exports = AuthenticationConfigurationService;
Expand Down

0 comments on commit 6853951

Please sign in to comment.