UNPKG

diffusion

Version:

Diffusion JavaScript client

189 lines (188 loc) 7.2 kB
"use strict"; /** * @module Security */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemAuthenticationScriptBuilderImpl = void 0; var util_1 = require("./../../features/security/util"); var require_non_null_1 = require("./../../util/require-non-null"); /** * Implementation of the {@link SystemAuthenticationScriptBuilder} interface */ var SystemAuthenticationScriptBuilderImpl = /** @class */ (function () { function SystemAuthenticationScriptBuilderImpl() { /** * The security script built so far */ this.commands = ''; } /** * Utility function that appends a new line * if commands already has lines */ SystemAuthenticationScriptBuilderImpl.prototype.maybeApppendNewLine = function () { if (this.commands.length > 0) { this.commands += '\n'; } }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.build = function () { return this.commands; }; /** * Convert the system authentication script builder to a string * * @return a string representation on this object */ SystemAuthenticationScriptBuilderImpl.prototype.toString = function () { return "SystemAuthenticationScriptBuilder [" + this.commands + "]"; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.assignRoles = function (principal, roles) { var nonNullRoles = require_non_null_1.requireNonNull(roles, 'roles'); var nonNullPrincipal = require_non_null_1.requireNonNull(principal, 'principal'); this.maybeApppendNewLine(); this.commands += 'assign roles ' + util_1.quoteAndEscape(nonNullPrincipal) + ' '; this.commands += util_1.setToString(nonNullRoles); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.addPrincipal = function (principal, password, roles, lockingPrincipal) { if (roles === void 0) { roles = []; } var nonNullRoles = require_non_null_1.requireNonNull(roles, 'roles'); var nonNullPrincipal = require_non_null_1.requireNonNull(principal, 'principal'); var nonNullPassword = require_non_null_1.requireNonNull(password, 'password'); this.maybeApppendNewLine(); this.commands += 'add principal ' + util_1.quoteAndEscape(nonNullPrincipal) + ' ' + util_1.quoteAndEscape(nonNullPassword); if (nonNullRoles.length) { this.commands += ' '; this.commands += util_1.setToString(nonNullRoles); } if (lockingPrincipal) { this.commands += ' locked by ' + util_1.quoteAndEscape(lockingPrincipal); } return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.setPassword = function (principal, password) { var nonNullPrincipal = require_non_null_1.requireNonNull(principal, 'principal'); var nonNullPassword = require_non_null_1.requireNonNull(password, 'password'); this.maybeApppendNewLine(); this.commands += 'set password ' + util_1.quoteAndEscape(nonNullPrincipal) + ' ' + util_1.quoteAndEscape(nonNullPassword); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.verifyPassword = function (principal, password) { var nonNullPrincipal = require_non_null_1.requireNonNull(principal, 'principal'); var nonNullPassword = require_non_null_1.requireNonNull(password, 'password'); this.maybeApppendNewLine(); this.commands += 'verify password ' + util_1.quoteAndEscape(nonNullPrincipal) + ' ' + util_1.quoteAndEscape(nonNullPassword); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.removePrincipal = function (principal) { var nonNullPrincipal = require_non_null_1.requireNonNull(principal, 'principal'); this.maybeApppendNewLine(); this.commands += 'remove principal ' + util_1.quoteAndEscape(nonNullPrincipal); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.allowAnonymousConnections = function (roles) { var nonNullRoles = roles !== null && roles !== void 0 ? roles : []; this.maybeApppendNewLine(); this.commands += "allow anonymous connections " + util_1.setToString(nonNullRoles); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.denyAnonymousConnections = function () { this.maybeApppendNewLine(); this.commands += 'deny anonymous connections'; return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.abstainAnonymousConnections = function () { this.maybeApppendNewLine(); this.commands += 'abstain anonymous connections'; return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.trustClientProposedPropertyIn = function (propertyName, allowedValues) { var nonNullPropertyName = require_non_null_1.requireNonNull(propertyName, 'propertyName'); var nonNullAllowedValues = require_non_null_1.requireNonNull(allowedValues, 'allowedValues'); this.maybeApppendNewLine(); this.commands += 'trust client proposed property ' + util_1.quoteAndEscape(nonNullPropertyName) + ' if value in '; this.commands += util_1.setToString(nonNullAllowedValues); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.trustClientProposedPropertyMatches = function (propertyName, regex) { var nonNullPropertyName = require_non_null_1.requireNonNull(propertyName, 'propertyName'); var nonNullRegex = require_non_null_1.requireNonNull(regex, 'regex'); this.maybeApppendNewLine(); this.commands += 'trust client proposed property ' + util_1.quoteAndEscape(nonNullPropertyName) + ' if value matches ' + util_1.quoteAndEscape(nonNullRegex); return this; }; /** * @inheritdoc */ SystemAuthenticationScriptBuilderImpl.prototype.ignoreClientProposedProperty = function (propertyName) { var nonNullPropertyName = require_non_null_1.requireNonNull(propertyName, 'propertyName'); this.maybeApppendNewLine(); this.commands += 'ignore client proposed property ' + util_1.quoteAndEscape(nonNullPropertyName); return this; }; return SystemAuthenticationScriptBuilderImpl; }()); exports.SystemAuthenticationScriptBuilderImpl = SystemAuthenticationScriptBuilderImpl;