Skip to content

Instantly share code, notes, and snippets.

@push-gists
Created January 10, 2017 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save push-gists/43aece9a02155970573f2f89e7121176 to your computer and use it in GitHub Desktop.
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.
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