Created
January 10, 2017 14:41
-
-
Save push-gists/43aece9a02155970573f2f89e7121176 to your computer and use it in GitHub Desktop.
A simple JS Reappt client that updates the security and system authentication stores.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var diffusion = require('diffusion'); | |
// Connect to Reappt with admin credentials | |
diffusion.connect({ | |
host : 'approvingBoldDaVinci.us.reappt.io', | |
port : 443, | |
secure : true, | |
principal : 'admin', | |
credentials : 'nimda' | |
}).then(function(session) { | |
// Change the security configuration to give the GATEKEEPER and REQUESTER roles the required permissions | |
var securityScriptBuilder = session.security.securityScriptBuilder(); | |
var script = securityScriptBuilder.setGlobalPermissions('GATEKEEPER', ['VIEW_SESSION', 'MODIFY_SESSION']) | |
.setTopicPermissions('GATEKEEPER', 'closed', ['SELECT_TOPIC']) | |
.setTopicPermissions('REQUESTER', 'closed', ['READ_TOPIC']) | |
.setTopicPermissions('REQUESTER', 'open', ['SELECT_TOPIC', 'READ_TOPIC']) | |
.setTopicPermissions('TOPIC_CONTROL', 'closed', ['MODIFY_TOPIC', 'UPDATE_TOPIC']) | |
.setTopicPermissions('TOPIC_CONTROL', 'open', ['MODIFY_TOPIC', 'UPDATE_TOPIC']) | |
.build(); | |
// Update the server-side store with the generated script | |
session.security.updateSecurityStore(script).then(function() { | |
console.log('Security configuration updated successfully'); | |
}, function(error) { | |
console.log('Failed to update security configuration: ', error); | |
}); | |
// Change the system authentication store to add users and give them roles | |
var authenticationScriptBuilder = session.security.authenticationScriptBuilder(); | |
var addUserScript = authenticationScriptBuilder.addPrincipal('gatekeeper', 'repeeketag') | |
.assignRoles('gatekeeper', ['GATEKEEPER']) | |
.addPrincipal('requester', 'retseuqer') | |
.assignRoles('requester', ['REQUESTER']) | |
.build(); | |
// Update the system authentication store | |
session.security.updateAuthenticationStore(addUserScript).then(function() { | |
console.log('Updated system authentication config'); | |
}, function(error) { | |
console.log('Failed to update system authentication: ', error); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment