@rockcarver/frodo-lib 0.18.2-0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.18.2] - 2023-01-25
11
+
12
+ ### Added
13
+
14
+ - rockcarver/frodo-cli#52: Library support for script extract and watch functionality
15
+
16
+ ### Fixed
17
+
18
+ - rockcarver/frodo-cli#190: Frodo now properly imports previously exported saml providers.
19
+
10
20
  ## [0.18.2-0] - 2023-01-24
11
21
 
12
22
  ## [0.18.1] - 2023-01-20
@@ -14,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
24
  ### Changed
15
25
 
16
26
  - Return service account name when calling `ConnectionProfile.getConnectionProfileByHost`.
17
- - Save missing service account name when calling `ConnectionProfileOps.saveConnectionProfile`.
27
+ - Save missing service account name when calling `ConnectionProfile.saveConnectionProfile`.
18
28
 
19
29
  ### Fixed
20
30
 
@@ -1030,7 +1040,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1030
1040
  - Fixed problem with adding connection profiles
1031
1041
  - Miscellaneous bug fixes
1032
1042
 
1033
- [Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.18.2-0...HEAD
1043
+ [Unreleased]: https://github.com/rockcarver/frodo-lib/compare/v0.18.2...HEAD
1044
+
1045
+ [0.18.2]: https://github.com/rockcarver/frodo-lib/compare/v0.18.2-0...v0.18.2
1034
1046
 
1035
1047
  [0.18.2-0]: https://github.com/rockcarver/frodo-lib/compare/v0.18.1...v0.18.2-0
1036
1048
 
package/cjs/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.state = exports.constants = exports.VariablesRaw = exports.Variables = exports.ValidationUtils = exports.Utils = exports.TypesRaw = exports.Types = exports.TreeRaw = exports.Theme = exports.StartupRaw = exports.Startup = exports.SocialIdentityProvidersRaw = exports.ServiceAccount = exports.Service = exports.SecretsRaw = exports.Secrets = exports.Script = exports.Saml2 = exports.Realm = exports.Organization = exports.OAuth2OIDCApi = exports.OAuth2Client = exports.NodeRaw = exports.Node = exports.ManagedObject = exports.Log = exports.LibVersion = exports.Journey = exports.Jose = exports.Info = exports.Idp = exports.IdmConfigRaw = exports.Idm = exports.ExportImportUtils = exports.EmailTemplate = exports.ConnectionProfile = exports.CirclesOfTrust = exports.AuthenticateRaw = exports.Authenticate = exports.AgentRaw = exports.Agent = exports.Admin = void 0;
6
+ exports.state = exports.constants = exports.VariablesRaw = exports.Variables = exports.ValidationUtils = exports.Utils = exports.TypesRaw = exports.Types = exports.TreeRaw = exports.Theme = exports.StartupRaw = exports.Startup = exports.SocialIdentityProvidersRaw = exports.ServiceAccount = exports.Service = exports.SecretsRaw = exports.Secrets = exports.Script = exports.Saml2 = exports.Realm = exports.Organization = exports.OAuth2OIDCApi = exports.OAuth2Client = exports.NodeRaw = exports.Node = exports.ManagedObject = exports.Log = exports.LibVersion = exports.Journey = exports.Jose = exports.Info = exports.Idp = exports.IdmConfigRaw = exports.Idm = exports.ExportImportUtils = exports.EmailTemplate = exports.ConnectionProfile = exports.CirclesOfTrust = exports.Base64 = exports.AuthenticateRaw = exports.Authenticate = exports.AgentRaw = exports.Agent = exports.Admin = void 0;
7
7
  var _colors = _interopRequireDefault(require("colors"));
8
8
  var _AgentRaw = _interopRequireWildcard(require("./api/AgentApi"));
9
9
  exports.AgentRaw = _AgentRaw;
@@ -81,6 +81,8 @@ var _Variables = _interopRequireWildcard(require("./ops/cloud/VariablesOps"));
81
81
  exports.Variables = _Variables;
82
82
  var _Utils = _interopRequireWildcard(require("./ops/utils/OpsUtils"));
83
83
  exports.Utils = _Utils;
84
+ var _Base = _interopRequireWildcard(require("./api/utils/Base64"));
85
+ exports.Base64 = _Base;
84
86
  var _ValidationUtils = _interopRequireWildcard(require("./ops/utils/ValidationUtils"));
85
87
  exports.ValidationUtils = _ValidationUtils;
86
88
  var _LibVersion = _interopRequireWildcard(require("./ops/utils/Version"));
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Color","enable"],"sources":["index.ts"],"sourcesContent":["import Color from 'colors';\n\nColor.enable();\n\n// Api Layer\nexport * as AgentRaw from './api/AgentApi';\nexport * as AuthenticateRaw from './api/AuthenticateApi';\nexport * as NodeRaw from './api/NodeApi';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\nexport * as SecretsRaw from './api/cloud/SecretsApi';\nexport * as SocialIdentityProvidersRaw from './api/SocialIdentityProvidersApi';\nexport * as StartupRaw from './api/cloud/StartupApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as TypesRaw from './api/ApiTypes';\nexport * as VariablesRaw from './api/cloud/VariablesApi';\nexport * as IdmConfigRaw from './api/IdmConfigApi';\n\n// Ops Layer\nexport * as Admin from './ops/AdminOps';\nexport * as Agent from './ops/AgentOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Info from './ops/InfoOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Jose from './ops/JoseOps';\nexport * as Log from './ops/cloud/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as Node from './ops/NodeOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Service from './ops/ServiceOps';\nexport * as Secrets from './ops/cloud/SecretsOps';\nexport * as ServiceAccount from './ops/cloud/ServiceAccountOps';\nexport * as Startup from './ops/cloud/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Types from './ops/OpsTypes';\nexport * as Variables from './ops/cloud/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\nexport * as ValidationUtils from './ops/utils/ValidationUtils';\nexport * as LibVersion from './ops/utils/Version';\nexport * as ExportImportUtils from './ops/utils/ExportImportUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './shared/State';\nexport * as constants from './storage/StaticStorage';\n"],"mappings":";;;;;;AAAA;AAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAE3BA,eAAK,CAACC,MAAM,EAAE;;AAEd"}
1
+ {"version":3,"file":"index.js","names":["Color","enable"],"sources":["index.ts"],"sourcesContent":["import Color from 'colors';\n\nColor.enable();\n\n// Api Layer\nexport * as AgentRaw from './api/AgentApi';\nexport * as AuthenticateRaw from './api/AuthenticateApi';\nexport * as NodeRaw from './api/NodeApi';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\nexport * as SecretsRaw from './api/cloud/SecretsApi';\nexport * as SocialIdentityProvidersRaw from './api/SocialIdentityProvidersApi';\nexport * as StartupRaw from './api/cloud/StartupApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as TypesRaw from './api/ApiTypes';\nexport * as VariablesRaw from './api/cloud/VariablesApi';\nexport * as IdmConfigRaw from './api/IdmConfigApi';\n\n// Ops Layer\nexport * as Admin from './ops/AdminOps';\nexport * as Agent from './ops/AgentOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Info from './ops/InfoOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Jose from './ops/JoseOps';\nexport * as Log from './ops/cloud/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as Node from './ops/NodeOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Service from './ops/ServiceOps';\nexport * as Secrets from './ops/cloud/SecretsOps';\nexport * as ServiceAccount from './ops/cloud/ServiceAccountOps';\nexport * as Startup from './ops/cloud/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Types from './ops/OpsTypes';\nexport * as Variables from './ops/cloud/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\nexport * as Base64 from './api/utils/Base64';\nexport * as ValidationUtils from './ops/utils/ValidationUtils';\nexport * as LibVersion from './ops/utils/Version';\nexport * as ExportImportUtils from './ops/utils/ExportImportUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './shared/State';\nexport * as constants from './storage/StaticStorage';\n"],"mappings":";;;;;;AAAA;AAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAE3BA,eAAK,CAACC,MAAM,EAAE;;AAEd"}
@@ -336,6 +336,7 @@ function _importSaml2Provider() {
336
336
  (0, _Console.debugMessage)("Saml2Ops.importSaml2Provider: start");
337
337
  var entityId64 = (0, _Base.encode)(entityId, false);
338
338
  var location = getLocation(entityId64, importData);
339
+ (0, _Console.debugMessage)("Saml2Ops.importSaml2Provider: entityId=".concat(entityId, ", entityId64=").concat(entityId64, ", location=").concat(location));
339
340
  if (location) {
340
341
  var providerData = importData.saml[location][entityId64];
341
342
  yield importDependencies(providerData, importData);
@@ -343,7 +344,11 @@ function _importSaml2Provider() {
343
344
  if (location === _ApiTypes.Saml2ProiderLocation.REMOTE) {
344
345
  metaData = (0, _ExportImportUtils.convertTextArrayToBase64Url)(importData.saml.metadata[entityId64]);
345
346
  }
346
- yield (0, _Saml2Api.createProvider)(location, providerData, metaData);
347
+ try {
348
+ yield (0, _Saml2Api.createProvider)(location, providerData, metaData);
349
+ } catch (error) {
350
+ yield (0, _Saml2Api.updateProvider)(location, providerData);
351
+ }
347
352
  } else {
348
353
  throw new Error("Provider ".concat(entityId, " not found in import data!"));
349
354
  }
@@ -375,7 +380,6 @@ function _importSaml2Providers() {
375
380
  var remoteIds = Object.keys(importData.saml.remote);
376
381
  var providerIds = hostedIds.concat(remoteIds);
377
382
  myStatus.total = providerIds.length;
378
- (0, _Console.createProgressIndicator)(providerIds.length, 'Importing providers...');
379
383
  for (var entityId64 of providerIds) {
380
384
  (0, _Console.debugMessage)("Saml2Ops.importSaml2Providers: entityId=".concat((0, _Base.decodeBase64Url)(entityId64)));
381
385
  var location = hostedIds.includes(entityId64) ? _ApiTypes.Saml2ProiderLocation.HOSTED : _ApiTypes.Saml2ProiderLocation.REMOTE;
@@ -395,15 +399,19 @@ function _importSaml2Providers() {
395
399
  try {
396
400
  yield (0, _Saml2Api.createProvider)(location, providerData, metaData);
397
401
  myStatus.successes += 1;
398
- (0, _Console.updateProgressIndicator)("Imported ".concat(entityId));
399
402
  } catch (createProviderErr) {
400
- myStatus.failures += 1;
401
- (0, _Console.printMessage)("\nError importing provider ".concat(entityId), 'error');
402
- (0, _Console.printMessage)(createProviderErr, 'error');
403
+ try {
404
+ yield (0, _Saml2Api.updateProvider)(location, providerData);
405
+ myStatus.successes += 1;
406
+ } catch (updateProviderError) {
407
+ var _updateProviderError$;
408
+ myStatus.failures += 1;
409
+ (0, _Console.printMessage)("\nError importing provider ".concat(entityId, ": ").concat(updateProviderError.message), 'error');
410
+ (0, _Console.printMessage)((_updateProviderError$ = updateProviderError.response) === null || _updateProviderError$ === void 0 ? void 0 : _updateProviderError$.data, 'error');
411
+ }
403
412
  }
404
413
  }
405
414
  myStatus.message = "".concat(myStatus.successes, "/").concat(myStatus.total, " providers imported.");
406
- (0, _Console.stopProgressIndicator)(myStatus.message);
407
415
  } catch (error) {
408
416
  myStatus.failures += 1;
409
417
  (0, _Console.printMessage)("\nError importing providers ".concat(error.message), 'error');
@@ -1 +1 @@
1
- {"version":3,"file":"Saml2Ops.js","names":["roleMap","identityProvider","serviceProvider","attributeQueryProvider","xacmlPolicyEnforcementPoint","createSaml2ExportTemplate","meta","getMetadata","script","saml","hosted","remote","metadata","getSaml2ProviderStubs","result","getProviders","getProviderByLocationAndId","location","entityId64","_getProviderByLocationAndId","getProviderMetadataUrl","entityId","_getProviderMetadataUrl","getProviderMetadata","_getProviderMetadata","exportDependencies","providerData","fileData","attrMapperScriptId","_","get","scriptData","getScript","convertBase64TextToArray","idpAdapterScriptId","metaDataResponse","_id","convertBase64UrlTextToArray","encodeBase64Url","getSaml2ProviderStub","debugMessage","found","findProviders","resultCount","Error","getSaml2Provider","stub","id","deleteSaml2Provider","deleteProviderByLocationAndId","deleteSaml2Providers","providers","stubs","provider","push","length","exportSaml2Provider","exportData","exportSaml2Providers","importDependencies","convertTextArrayToBase64","putScript","getLocation","data","Saml2ProiderLocation","HOSTED","REMOTE","undefined","importSaml2Provider","importData","encode","metaData","convertTextArrayToBase64Url","createProvider","importSaml2Providers","myStatus","total","successes","warnings","failures","hostedIds","Object","keys","remoteIds","providerIds","concat","createProgressIndicator","decodeBase64Url","includes","decode","importDependenciesErr","printMessage","response","updateProgressIndicator","createProviderErr","message","stopProgressIndicator","error","deleteRawSaml2Provider","deleteRawProvider","deleteRawSaml2Providers","applicationList","getRawSaml2Providers","deleteApplicationPromises","forEach","item","deleteApplicationResult","Promise","all","_getRawProviders","getRawSaml2Provider","_getRawProvider","putRawSaml2Provider","entityData","_putRawProvider"],"sources":["ops/Saml2Ops.ts"],"sourcesContent":["import _ from 'lodash';\nimport {\n Saml2ProiderLocation,\n Saml2ProviderSkeleton,\n Saml2ProviderStub,\n} from '../api/ApiTypes';\nimport {\n createProvider,\n deleteRawProvider,\n findProviders,\n getProviderByLocationAndId as _getProviderByLocationAndId,\n getProviderMetadata as _getProviderMetadata,\n getProviderMetadataUrl as _getProviderMetadataUrl,\n getRawProvider as _getRawProvider,\n getProviders,\n getRawProviders as _getRawProviders,\n putRawProvider as _putRawProvider,\n deleteProviderByLocationAndId,\n} from '../api/Saml2Api';\nimport { getScript } from '../api/ScriptApi';\nimport {\n decode,\n decodeBase64Url,\n encode,\n encodeBase64Url,\n} from '../api/utils/Base64';\nimport { MultiOpStatusInterface, Saml2ExportInterface } from './OpsTypes';\nimport { putScript } from './ScriptOps';\nimport {\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n convertBase64TextToArray,\n convertBase64UrlTextToArray,\n convertTextArrayToBase64,\n convertTextArrayToBase64Url,\n getMetadata,\n} from './utils/ExportImportUtils';\n\nexport const roleMap = {\n identityProvider: 'IDP',\n serviceProvider: 'SP',\n attributeQueryProvider: 'AttrQuery',\n xacmlPolicyEnforcementPoint: 'XACML PEP',\n};\n\n// use a function vs a template variable to avoid problems in loops\nexport function createSaml2ExportTemplate(): Saml2ExportInterface {\n return {\n meta: getMetadata(),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n },\n } as Saml2ExportInterface;\n}\n\n/**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getSaml2ProviderStubs(): Promise<Saml2ProviderStub[]> {\n const { result } = await getProviders();\n return result;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId(\n location: string,\n entityId64: string\n) {\n return _getProviderByLocationAndId(location, entityId64);\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl(entityId: string): string {\n return _getProviderMetadataUrl(entityId);\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata(entityId) {\n return _getProviderMetadata(entityId);\n}\n\n/**\n * Include dependencies in the export file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(providerData, fileData) {\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n const scriptData = await getScript(attrMapperScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[attrMapperScriptId] = scriptData;\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n const scriptData = await getScript(idpAdapterScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[idpAdapterScriptId] = scriptData;\n }\n const metaDataResponse = await getProviderMetadata(providerData.entityId);\n // eslint-disable-next-line no-param-reassign\n fileData.saml.metadata[providerData._id] = convertBase64UrlTextToArray(\n encodeBase64Url(metaDataResponse)\n );\n}\n\n/**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2ProviderStub(\n entityId: string\n): Promise<Saml2ProviderStub> {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: start [entityId=${entityId}]`);\n const found = await findProviders(`entityId eq '${entityId}'`);\n switch (found.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: end [entityId=${entityId}]`);\n return found.result[0];\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.getSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.getSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await deleteProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\nexport async function deleteSaml2Providers(): Promise<Saml2ProviderSkeleton[]> {\n debugMessage(`Saml2Ops.deleteSaml2Providers: start`);\n const providers: Saml2ProviderSkeleton[] = [];\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const provider = await deleteProviderByLocationAndId(\n stub.location,\n stub._id\n );\n providers.push(provider);\n }\n debugMessage(\n `Saml2Ops.deleteSaml2Providers: end [deleted ${providers.length} providers]`\n );\n return providers;\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Provider(\n entityId: string\n): Promise<Saml2ExportInterface> {\n debugMessage(`Saml2Ops.exportSaml2Provider: start [entityId=${entityId}]`);\n const exportData = createSaml2ExportTemplate();\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n exportData.saml[stub.location][providerData._id] = providerData;\n await exportDependencies(providerData, exportData);\n debugMessage(`Saml2Ops.exportSaml2Provider: end [entityId=${entityId}]`);\n return exportData;\n}\n\n/**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Providers(): Promise<Saml2ExportInterface> {\n const fileData = createSaml2ExportTemplate();\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const providerData = await getProviderByLocationAndId(\n stub.location,\n stub._id\n );\n await exportDependencies(providerData, fileData);\n fileData.saml[stub.location][providerData._id] = providerData;\n }\n return fileData;\n}\n\n/**\n * Include dependencies from the import file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to read dependencies from\n */\nasync function importDependencies(providerData, fileData) {\n debugMessage(`Saml2Ops.importDependencies: start`);\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: attributeMapperScript=${attrMapperScriptId}`\n );\n const scriptData = _.get(fileData, ['script', attrMapperScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(attrMapperScriptId, scriptData);\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: idpAdapterScript=${idpAdapterScriptId}`\n );\n const scriptData = _.get(fileData, ['script', idpAdapterScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(idpAdapterScriptId, scriptData);\n }\n debugMessage(`Saml2Ops.importDependencies: end`);\n}\n\n/**\n * Find provider in import file and return its location\n * @param {string} entityId64 Base64-encoded provider entity id\n * @param {Saml2ExportInterface} data Import file json data\n * @returns {string} 'hosted' or 'remote' if found, undefined otherwise\n */\nfunction getLocation(\n entityId64: string,\n data: Saml2ExportInterface\n): Saml2ProiderLocation {\n if (data.saml.hosted[entityId64]) {\n return Saml2ProiderLocation.HOSTED;\n }\n if (data.saml.remote[entityId64]) {\n return Saml2ProiderLocation.REMOTE;\n }\n return undefined;\n}\n\n/**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Provider(\n entityId: string,\n importData: Saml2ExportInterface\n): Promise<boolean> {\n debugMessage(`Saml2Ops.importSaml2Provider: start`);\n const entityId64 = encode(entityId, false);\n const location = getLocation(entityId64, importData);\n if (location) {\n const providerData = importData.saml[location][entityId64];\n await importDependencies(providerData, importData);\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n await createProvider(location, providerData, metaData);\n } else {\n throw new Error(`Provider ${entityId} not found in import data!`);\n }\n debugMessage(`Saml2Ops.importSaml2Provider: end`);\n return true;\n}\n\n/**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Providers(\n importData: Saml2ExportInterface\n): Promise<MultiOpStatusInterface> {\n debugMessage(`Saml2Ops.importSaml2Providers: start`);\n const myStatus: MultiOpStatusInterface = {\n total: 0,\n successes: 0,\n warnings: 0,\n failures: 0,\n };\n try {\n // find providers in hosted and in remote and map locations\n const hostedIds = Object.keys(importData.saml.hosted);\n const remoteIds = Object.keys(importData.saml.remote);\n const providerIds = hostedIds.concat(remoteIds);\n myStatus.total = providerIds.length;\n createProgressIndicator(providerIds.length, 'Importing providers...');\n for (const entityId64 of providerIds) {\n debugMessage(\n `Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(entityId64)}`\n );\n const location = hostedIds.includes(entityId64)\n ? Saml2ProiderLocation.HOSTED\n : Saml2ProiderLocation.REMOTE;\n const entityId = decode(entityId64);\n const providerData = importData.saml[location][entityId64];\n try {\n await importDependencies(providerData, importData);\n } catch (importDependenciesErr) {\n myStatus.warnings += 1;\n printMessage(\n `\\nWarning importing dependencies for ${entityId}`,\n 'warn'\n );\n printMessage(importDependenciesErr.response.data, 'error');\n }\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider(location, providerData, metaData);\n myStatus.successes += 1;\n updateProgressIndicator(`Imported ${entityId}`);\n } catch (createProviderErr) {\n myStatus.failures += 1;\n printMessage(`\\nError importing provider ${entityId}`, 'error');\n printMessage(createProviderErr, 'error');\n }\n }\n myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;\n stopProgressIndicator(myStatus.message);\n } catch (error) {\n myStatus.failures += 1;\n printMessage(`\\nError importing providers ${error.message}`, 'error');\n }\n debugMessage(`Saml2Ops.importSaml2Providers: end`);\n return myStatus;\n}\n\n// Contributions using legacy APIs. Need to investigate if those will be deprecated in the future\n\n/**\n * Deletes entity provider\n * @param {string} entityId The entity id for the entity to be deleted\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteRawSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const response = await deleteRawProvider(entityId);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return response;\n}\n\n/**\n * Deletes all entity providers.\n */\nexport async function deleteRawSaml2Providers(): Promise<\n Saml2ProviderSkeleton[]\n> {\n const applicationList = (await getRawSaml2Providers()).result;\n const deleteApplicationPromises = [];\n applicationList.forEach((item) => {\n printMessage(`Deleting Application ${item._id}`, 'error');\n deleteApplicationPromises.push(deleteRawProvider(item._id));\n });\n const deleteApplicationResult = await Promise.all(deleteApplicationPromises);\n if (deleteApplicationResult.length == applicationList.length) {\n printMessage('SAML Entity cleanup done', 'info');\n }\n return deleteApplicationResult;\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Providers() {\n return _getRawProviders();\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @param {string} entityId The entity provider id\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Provider(entityId: string) {\n return _getRawProvider(entityId);\n}\n\n/**\n * Stores a new SAML2 entity provider\n * @param {string} entityId The entity provider id\n * @param {string} entityData The actual data containing the entity provider configuration\n * @returns {Promise} Promise that resolves to a provider object\n */\nexport async function putRawSaml2Provider(entityId: string, entityData) {\n return _putRawProvider(entityId, entityData);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAKA;AAaA;AACA;AAOA;AACA;AAOA;AAMmC;AAAA;AAAA;AAE5B,IAAMA,OAAO,GAAG;EACrBC,gBAAgB,EAAE,KAAK;EACvBC,eAAe,EAAE,IAAI;EACrBC,sBAAsB,EAAE,WAAW;EACnCC,2BAA2B,EAAE;AAC/B,CAAC;;AAED;AAAA;AACO,SAASC,yBAAyB,GAAyB;EAChE,OAAO;IACLC,IAAI,EAAE,IAAAC,8BAAW,GAAE;IACnBC,MAAM,EAAE,CAAC,CAAC;IACVC,IAAI,EAAE;MACJC,MAAM,EAAE,CAAC,CAAC;MACVC,MAAM,EAAE,CAAC,CAAC;MACVC,QAAQ,EAAE,CAAC;IACb;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AAHA,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,"file":"Saml2Ops.js","names":["roleMap","identityProvider","serviceProvider","attributeQueryProvider","xacmlPolicyEnforcementPoint","createSaml2ExportTemplate","meta","getMetadata","script","saml","hosted","remote","metadata","getSaml2ProviderStubs","result","getProviders","getProviderByLocationAndId","location","entityId64","_getProviderByLocationAndId","getProviderMetadataUrl","entityId","_getProviderMetadataUrl","getProviderMetadata","_getProviderMetadata","exportDependencies","providerData","fileData","attrMapperScriptId","_","get","scriptData","getScript","convertBase64TextToArray","idpAdapterScriptId","metaDataResponse","_id","convertBase64UrlTextToArray","encodeBase64Url","getSaml2ProviderStub","debugMessage","found","findProviders","resultCount","Error","getSaml2Provider","stub","id","deleteSaml2Provider","deleteProviderByLocationAndId","deleteSaml2Providers","providers","stubs","provider","push","length","exportSaml2Provider","exportData","exportSaml2Providers","importDependencies","convertTextArrayToBase64","putScript","getLocation","data","Saml2ProiderLocation","HOSTED","REMOTE","undefined","importSaml2Provider","importData","encode","metaData","convertTextArrayToBase64Url","createProvider","error","updateProvider","importSaml2Providers","myStatus","total","successes","warnings","failures","hostedIds","Object","keys","remoteIds","providerIds","concat","decodeBase64Url","includes","decode","importDependenciesErr","printMessage","response","createProviderErr","updateProviderError","message","deleteRawSaml2Provider","deleteRawProvider","deleteRawSaml2Providers","applicationList","getRawSaml2Providers","deleteApplicationPromises","forEach","item","deleteApplicationResult","Promise","all","_getRawProviders","getRawSaml2Provider","_getRawProvider","putRawSaml2Provider","entityData","_putRawProvider"],"sources":["ops/Saml2Ops.ts"],"sourcesContent":["import _ from 'lodash';\nimport {\n Saml2ProiderLocation,\n Saml2ProviderSkeleton,\n Saml2ProviderStub,\n} from '../api/ApiTypes';\nimport {\n createProvider,\n updateProvider,\n deleteRawProvider,\n findProviders,\n getProviderByLocationAndId as _getProviderByLocationAndId,\n getProviderMetadata as _getProviderMetadata,\n getProviderMetadataUrl as _getProviderMetadataUrl,\n getRawProvider as _getRawProvider,\n getProviders,\n getRawProviders as _getRawProviders,\n putRawProvider as _putRawProvider,\n deleteProviderByLocationAndId,\n} from '../api/Saml2Api';\nimport { getScript } from '../api/ScriptApi';\nimport {\n decode,\n decodeBase64Url,\n encode,\n encodeBase64Url,\n} from '../api/utils/Base64';\nimport { MultiOpStatusInterface, Saml2ExportInterface } from './OpsTypes';\nimport { putScript } from './ScriptOps';\nimport { debugMessage, printMessage } from './utils/Console';\nimport {\n convertBase64TextToArray,\n convertBase64UrlTextToArray,\n convertTextArrayToBase64,\n convertTextArrayToBase64Url,\n getMetadata,\n} from './utils/ExportImportUtils';\n\nexport const roleMap = {\n identityProvider: 'IDP',\n serviceProvider: 'SP',\n attributeQueryProvider: 'AttrQuery',\n xacmlPolicyEnforcementPoint: 'XACML PEP',\n};\n\n// use a function vs a template variable to avoid problems in loops\nexport function createSaml2ExportTemplate(): Saml2ExportInterface {\n return {\n meta: getMetadata(),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n },\n } as Saml2ExportInterface;\n}\n\n/**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getSaml2ProviderStubs(): Promise<Saml2ProviderStub[]> {\n const { result } = await getProviders();\n return result;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId(\n location: string,\n entityId64: string\n) {\n return _getProviderByLocationAndId(location, entityId64);\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl(entityId: string): string {\n return _getProviderMetadataUrl(entityId);\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata(entityId) {\n return _getProviderMetadata(entityId);\n}\n\n/**\n * Include dependencies in the export file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(providerData, fileData) {\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n const scriptData = await getScript(attrMapperScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[attrMapperScriptId] = scriptData;\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n const scriptData = await getScript(idpAdapterScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[idpAdapterScriptId] = scriptData;\n }\n const metaDataResponse = await getProviderMetadata(providerData.entityId);\n // eslint-disable-next-line no-param-reassign\n fileData.saml.metadata[providerData._id] = convertBase64UrlTextToArray(\n encodeBase64Url(metaDataResponse)\n );\n}\n\n/**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2ProviderStub(\n entityId: string\n): Promise<Saml2ProviderStub> {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: start [entityId=${entityId}]`);\n const found = await findProviders(`entityId eq '${entityId}'`);\n switch (found.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: end [entityId=${entityId}]`);\n return found.result[0];\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.getSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.getSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await deleteProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\nexport async function deleteSaml2Providers(): Promise<Saml2ProviderSkeleton[]> {\n debugMessage(`Saml2Ops.deleteSaml2Providers: start`);\n const providers: Saml2ProviderSkeleton[] = [];\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const provider = await deleteProviderByLocationAndId(\n stub.location,\n stub._id\n );\n providers.push(provider);\n }\n debugMessage(\n `Saml2Ops.deleteSaml2Providers: end [deleted ${providers.length} providers]`\n );\n return providers;\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Provider(\n entityId: string\n): Promise<Saml2ExportInterface> {\n debugMessage(`Saml2Ops.exportSaml2Provider: start [entityId=${entityId}]`);\n const exportData = createSaml2ExportTemplate();\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n exportData.saml[stub.location][providerData._id] = providerData;\n await exportDependencies(providerData, exportData);\n debugMessage(`Saml2Ops.exportSaml2Provider: end [entityId=${entityId}]`);\n return exportData;\n}\n\n/**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Providers(): Promise<Saml2ExportInterface> {\n const fileData = createSaml2ExportTemplate();\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const providerData = await getProviderByLocationAndId(\n stub.location,\n stub._id\n );\n await exportDependencies(providerData, fileData);\n fileData.saml[stub.location][providerData._id] = providerData;\n }\n return fileData;\n}\n\n/**\n * Include dependencies from the import file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to read dependencies from\n */\nasync function importDependencies(providerData, fileData) {\n debugMessage(`Saml2Ops.importDependencies: start`);\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: attributeMapperScript=${attrMapperScriptId}`\n );\n const scriptData = _.get(fileData, ['script', attrMapperScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(attrMapperScriptId, scriptData);\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: idpAdapterScript=${idpAdapterScriptId}`\n );\n const scriptData = _.get(fileData, ['script', idpAdapterScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(idpAdapterScriptId, scriptData);\n }\n debugMessage(`Saml2Ops.importDependencies: end`);\n}\n\n/**\n * Find provider in import file and return its location\n * @param {string} entityId64 Base64-encoded provider entity id\n * @param {Saml2ExportInterface} data Import file json data\n * @returns {string} 'hosted' or 'remote' if found, undefined otherwise\n */\nfunction getLocation(\n entityId64: string,\n data: Saml2ExportInterface\n): Saml2ProiderLocation {\n if (data.saml.hosted[entityId64]) {\n return Saml2ProiderLocation.HOSTED;\n }\n if (data.saml.remote[entityId64]) {\n return Saml2ProiderLocation.REMOTE;\n }\n return undefined;\n}\n\n/**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Provider(\n entityId: string,\n importData: Saml2ExportInterface\n): Promise<boolean> {\n debugMessage(`Saml2Ops.importSaml2Provider: start`);\n const entityId64 = encode(entityId, false);\n const location = getLocation(entityId64, importData);\n debugMessage(\n `Saml2Ops.importSaml2Provider: entityId=${entityId}, entityId64=${entityId64}, location=${location}`\n );\n if (location) {\n const providerData = importData.saml[location][entityId64];\n await importDependencies(providerData, importData);\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider(location, providerData, metaData);\n } catch (error) {\n await updateProvider(location, providerData);\n }\n } else {\n throw new Error(`Provider ${entityId} not found in import data!`);\n }\n debugMessage(`Saml2Ops.importSaml2Provider: end`);\n return true;\n}\n\n/**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Providers(\n importData: Saml2ExportInterface\n): Promise<MultiOpStatusInterface> {\n debugMessage(`Saml2Ops.importSaml2Providers: start`);\n const myStatus: MultiOpStatusInterface = {\n total: 0,\n successes: 0,\n warnings: 0,\n failures: 0,\n };\n try {\n // find providers in hosted and in remote and map locations\n const hostedIds = Object.keys(importData.saml.hosted);\n const remoteIds = Object.keys(importData.saml.remote);\n const providerIds = hostedIds.concat(remoteIds);\n myStatus.total = providerIds.length;\n for (const entityId64 of providerIds) {\n debugMessage(\n `Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(entityId64)}`\n );\n const location = hostedIds.includes(entityId64)\n ? Saml2ProiderLocation.HOSTED\n : Saml2ProiderLocation.REMOTE;\n const entityId = decode(entityId64);\n const providerData = importData.saml[location][entityId64];\n try {\n await importDependencies(providerData, importData);\n } catch (importDependenciesErr) {\n myStatus.warnings += 1;\n printMessage(\n `\\nWarning importing dependencies for ${entityId}`,\n 'warn'\n );\n printMessage(importDependenciesErr.response.data, 'error');\n }\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider(location, providerData, metaData);\n myStatus.successes += 1;\n } catch (createProviderErr) {\n try {\n await updateProvider(location, providerData);\n myStatus.successes += 1;\n } catch (updateProviderError) {\n myStatus.failures += 1;\n printMessage(\n `\\nError importing provider ${entityId}: ${updateProviderError.message}`,\n 'error'\n );\n printMessage(updateProviderError.response?.data, 'error');\n }\n }\n }\n myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;\n } catch (error) {\n myStatus.failures += 1;\n printMessage(`\\nError importing providers ${error.message}`, 'error');\n }\n debugMessage(`Saml2Ops.importSaml2Providers: end`);\n return myStatus;\n}\n\n// Contributions using legacy APIs. Need to investigate if those will be deprecated in the future\n\n/**\n * Deletes entity provider\n * @param {string} entityId The entity id for the entity to be deleted\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteRawSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const response = await deleteRawProvider(entityId);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return response;\n}\n\n/**\n * Deletes all entity providers.\n */\nexport async function deleteRawSaml2Providers(): Promise<\n Saml2ProviderSkeleton[]\n> {\n const applicationList = (await getRawSaml2Providers()).result;\n const deleteApplicationPromises = [];\n applicationList.forEach((item) => {\n printMessage(`Deleting Application ${item._id}`, 'error');\n deleteApplicationPromises.push(deleteRawProvider(item._id));\n });\n const deleteApplicationResult = await Promise.all(deleteApplicationPromises);\n if (deleteApplicationResult.length == applicationList.length) {\n printMessage('SAML Entity cleanup done', 'info');\n }\n return deleteApplicationResult;\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Providers() {\n return _getRawProviders();\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @param {string} entityId The entity provider id\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Provider(entityId: string) {\n return _getRawProvider(entityId);\n}\n\n/**\n * Stores a new SAML2 entity provider\n * @param {string} entityId The entity provider id\n * @param {string} entityData The actual data containing the entity provider configuration\n * @returns {Promise} Promise that resolves to a provider object\n */\nexport async function putRawSaml2Provider(entityId: string, entityData) {\n return _putRawProvider(entityId, entityData);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAKA;AAcA;AACA;AAOA;AACA;AACA;AAMmC;AAAA;AAAA;AAE5B,IAAMA,OAAO,GAAG;EACrBC,gBAAgB,EAAE,KAAK;EACvBC,eAAe,EAAE,IAAI;EACrBC,sBAAsB,EAAE,WAAW;EACnCC,2BAA2B,EAAE;AAC/B,CAAC;;AAED;AAAA;AACO,SAASC,yBAAyB,GAAyB;EAChE,OAAO;IACLC,IAAI,EAAE,IAAAC,8BAAW,GAAE;IACnBC,MAAM,EAAE,CAAC,CAAC;IACVC,IAAI,EAAE;MACJC,MAAM,EAAE,CAAC,CAAC;MACVC,MAAM,EAAE,CAAC,CAAC;MACVC,QAAQ,EAAE,CAAC;IACb;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AAHA,SAIsBC,qBAAqB;EAAA;AAAA;A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AC;EAAA;AAAA;AAAA,SAQqB0F,mBAAmB;EAAA;AAAA;AAAA;EAAA,yCAAlC,WAAmC1F,QAAgB,EAAE2F,UAAU,EAAE;IACtE,OAAO,IAAAC,wBAAe,EAAC5F,QAAQ,EAAE2F,UAAU,CAAC;EAC9C,CAAC;EAAA;AAAA"}
package/esm/index.mjs CHANGED
@@ -46,6 +46,7 @@ export * as Types from './ops/OpsTypes';
46
46
  export * as Variables from './ops/cloud/VariablesOps';
47
47
  // TODO: revisit if there are better ways
48
48
  export * as Utils from './ops/utils/OpsUtils';
49
+ export * as Base64 from './api/utils/Base64';
49
50
  export * as ValidationUtils from './ops/utils/ValidationUtils';
50
51
  export * as LibVersion from './ops/utils/Version';
51
52
  export * as ExportImportUtils from './ops/utils/ExportImportUtils';
@@ -1,10 +1,10 @@
1
1
  import _ from 'lodash';
2
2
  import { Saml2ProiderLocation } from '../api/ApiTypes';
3
- import { createProvider, deleteRawProvider, findProviders, getProviderByLocationAndId as _getProviderByLocationAndId, getProviderMetadata as _getProviderMetadata, getProviderMetadataUrl as _getProviderMetadataUrl, getRawProvider as _getRawProvider, getProviders, getRawProviders as _getRawProviders, putRawProvider as _putRawProvider, deleteProviderByLocationAndId } from '../api/Saml2Api';
3
+ import { createProvider, updateProvider, deleteRawProvider, findProviders, getProviderByLocationAndId as _getProviderByLocationAndId, getProviderMetadata as _getProviderMetadata, getProviderMetadataUrl as _getProviderMetadataUrl, getRawProvider as _getRawProvider, getProviders, getRawProviders as _getRawProviders, putRawProvider as _putRawProvider, deleteProviderByLocationAndId } from '../api/Saml2Api';
4
4
  import { getScript } from '../api/ScriptApi';
5
5
  import { decode, decodeBase64Url, encode, encodeBase64Url } from '../api/utils/Base64';
6
6
  import { putScript } from './ScriptOps';
7
- import { createProgressIndicator, debugMessage, printMessage, stopProgressIndicator, updateProgressIndicator } from './utils/Console';
7
+ import { debugMessage, printMessage } from './utils/Console';
8
8
  import { convertBase64TextToArray, convertBase64UrlTextToArray, convertTextArrayToBase64, convertTextArrayToBase64Url, getMetadata } from './utils/ExportImportUtils';
9
9
  export const roleMap = {
10
10
  identityProvider: 'IDP',
@@ -245,6 +245,7 @@ export async function importSaml2Provider(entityId, importData) {
245
245
  debugMessage(`Saml2Ops.importSaml2Provider: start`);
246
246
  const entityId64 = encode(entityId, false);
247
247
  const location = getLocation(entityId64, importData);
248
+ debugMessage(`Saml2Ops.importSaml2Provider: entityId=${entityId}, entityId64=${entityId64}, location=${location}`);
248
249
  if (location) {
249
250
  const providerData = importData.saml[location][entityId64];
250
251
  await importDependencies(providerData, importData);
@@ -252,7 +253,11 @@ export async function importSaml2Provider(entityId, importData) {
252
253
  if (location === Saml2ProiderLocation.REMOTE) {
253
254
  metaData = convertTextArrayToBase64Url(importData.saml.metadata[entityId64]);
254
255
  }
255
- await createProvider(location, providerData, metaData);
256
+ try {
257
+ await createProvider(location, providerData, metaData);
258
+ } catch (error) {
259
+ await updateProvider(location, providerData);
260
+ }
256
261
  } else {
257
262
  throw new Error(`Provider ${entityId} not found in import data!`);
258
263
  }
@@ -278,7 +283,6 @@ export async function importSaml2Providers(importData) {
278
283
  const remoteIds = Object.keys(importData.saml.remote);
279
284
  const providerIds = hostedIds.concat(remoteIds);
280
285
  myStatus.total = providerIds.length;
281
- createProgressIndicator(providerIds.length, 'Importing providers...');
282
286
  for (const entityId64 of providerIds) {
283
287
  debugMessage(`Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(entityId64)}`);
284
288
  const location = hostedIds.includes(entityId64) ? Saml2ProiderLocation.HOSTED : Saml2ProiderLocation.REMOTE;
@@ -298,15 +302,19 @@ export async function importSaml2Providers(importData) {
298
302
  try {
299
303
  await createProvider(location, providerData, metaData);
300
304
  myStatus.successes += 1;
301
- updateProgressIndicator(`Imported ${entityId}`);
302
305
  } catch (createProviderErr) {
303
- myStatus.failures += 1;
304
- printMessage(`\nError importing provider ${entityId}`, 'error');
305
- printMessage(createProviderErr, 'error');
306
+ try {
307
+ await updateProvider(location, providerData);
308
+ myStatus.successes += 1;
309
+ } catch (updateProviderError) {
310
+ var _updateProviderError$;
311
+ myStatus.failures += 1;
312
+ printMessage(`\nError importing provider ${entityId}: ${updateProviderError.message}`, 'error');
313
+ printMessage((_updateProviderError$ = updateProviderError.response) === null || _updateProviderError$ === void 0 ? void 0 : _updateProviderError$.data, 'error');
314
+ }
306
315
  }
307
316
  }
308
317
  myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;
309
- stopProgressIndicator(myStatus.message);
310
318
  } catch (error) {
311
319
  myStatus.failures += 1;
312
320
  printMessage(`\nError importing providers ${error.message}`, 'error');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rockcarver/frodo-lib",
3
- "version": "0.18.2-0",
3
+ "version": "0.18.2",
4
4
  "type": "commonjs",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.mjs",
package/types/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export * as Theme from './ops/ThemeOps';
36
36
  export * as Types from './ops/OpsTypes';
37
37
  export * as Variables from './ops/cloud/VariablesOps';
38
38
  export * as Utils from './ops/utils/OpsUtils';
39
+ export * as Base64 from './api/utils/Base64';
39
40
  export * as ValidationUtils from './ops/utils/ValidationUtils';
40
41
  export * as LibVersion from './ops/utils/Version';
41
42
  export * as ExportImportUtils from './ops/utils/ExportImportUtils';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,0BAA0B,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KA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xC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAC","file":"index.d.ts","sourcesContent":["import Color from 'colors';\n\nColor.enable();\n\n// Api Layer\nexport * as AgentRaw from './api/AgentApi';\nexport * as AuthenticateRaw from './api/AuthenticateApi';\nexport * as NodeRaw from './api/NodeApi';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\nexport * as SecretsRaw from './api/cloud/SecretsApi';\nexport * as SocialIdentityProvidersRaw from './api/SocialIdentityProvidersApi';\nexport * as StartupRaw from './api/cloud/StartupApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as TypesRaw from './api/ApiTypes';\nexport * as VariablesRaw from './api/cloud/VariablesApi';\nexport * as IdmConfigRaw from './api/IdmConfigApi';\n\n// Ops Layer\nexport * as Admin from './ops/AdminOps';\nexport * as Agent from './ops/AgentOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Info from './ops/InfoOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Jose from './ops/JoseOps';\nexport * as Log from './ops/cloud/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as Node from './ops/NodeOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Service from './ops/ServiceOps';\nexport * as Secrets from './ops/cloud/SecretsOps';\nexport * as ServiceAccount from './ops/cloud/ServiceAccountOps';\nexport * as Startup from './ops/cloud/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Types from './ops/OpsTypes';\nexport * as Variables from './ops/cloud/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\nexport * as ValidationUtils from './ops/utils/ValidationUtils';\nexport * as LibVersion from './ops/utils/Version';\nexport * as ExportImportUtils from './ops/utils/ExportImportUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './shared/State';\nexport * as constants from './storage/StaticStorage';\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,0BAA0B,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,gBA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UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAC","file":"index.d.ts","sourcesContent":["import Color from 'colors';\n\nColor.enable();\n\n// Api Layer\nexport * as AgentRaw from './api/AgentApi';\nexport * as AuthenticateRaw from './api/AuthenticateApi';\nexport * as NodeRaw from './api/NodeApi';\n// TODO: need to figure out if this is the right approach or if we should even\n// use a public oauth2/oidc library. might be ok for now since there is only\n// one place where the cli needs to execute an oauth flow.\nexport * as OAuth2OIDCApi from './api/OAuth2OIDCApi';\nexport * as SecretsRaw from './api/cloud/SecretsApi';\nexport * as SocialIdentityProvidersRaw from './api/SocialIdentityProvidersApi';\nexport * as StartupRaw from './api/cloud/StartupApi';\nexport * as TreeRaw from './api/TreeApi';\nexport * as TypesRaw from './api/ApiTypes';\nexport * as VariablesRaw from './api/cloud/VariablesApi';\nexport * as IdmConfigRaw from './api/IdmConfigApi';\n\n// Ops Layer\nexport * as Admin from './ops/AdminOps';\nexport * as Agent from './ops/AgentOps';\nexport * as Authenticate from './ops/AuthenticateOps';\nexport * as CirclesOfTrust from './ops/CirclesOfTrustOps';\nexport * as ConnectionProfile from './ops/ConnectionProfileOps';\nexport * as EmailTemplate from './ops/EmailTemplateOps';\nexport * as Idp from './ops/IdpOps';\nexport * as Idm from './ops/IdmOps';\nexport * as Info from './ops/InfoOps';\nexport * as Journey from './ops/JourneyOps';\nexport * as Jose from './ops/JoseOps';\nexport * as Log from './ops/cloud/LogOps';\nexport * as ManagedObject from './ops/ManagedObjectOps';\nexport * as Node from './ops/NodeOps';\nexport * as OAuth2Client from './ops/OAuth2ClientOps';\nexport * as Organization from './ops/OrganizationOps';\nexport * as Realm from './ops/RealmOps';\nexport * as Saml2 from './ops/Saml2Ops';\nexport * as Script from './ops/ScriptOps';\nexport * as Service from './ops/ServiceOps';\nexport * as Secrets from './ops/cloud/SecretsOps';\nexport * as ServiceAccount from './ops/cloud/ServiceAccountOps';\nexport * as Startup from './ops/cloud/StartupOps';\nexport * as Theme from './ops/ThemeOps';\nexport * as Types from './ops/OpsTypes';\nexport * as Variables from './ops/cloud/VariablesOps';\n// TODO: revisit if there are better ways\nexport * as Utils from './ops/utils/OpsUtils';\nexport * as Base64 from './api/utils/Base64';\nexport * as ValidationUtils from './ops/utils/ValidationUtils';\nexport * as LibVersion from './ops/utils/Version';\nexport * as ExportImportUtils from './ops/utils/ExportImportUtils';\n// TODO: reconsider the aproach to pass in state from client\n// lib should be stateless, an aplication should own its state\nexport * as state from './shared/State';\nexport * as constants from './storage/StaticStorage';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ops/Saml2Ops.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAqBzB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAiB1E,eAAO,MAAM,OAAO;;;;;CAKnB,CAAC;AAGF,wBAAgB,yBAAyB,IAAI,oBAAoB,CAUhE;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAG1E;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,gBAGnB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,KAAA,gBAEjD;AAuCD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,iBAAiB,CAAC,CAa5B;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,CAAC,CAQhC;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,CAAC,CAQhC;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAe7E;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,oBAAoB,CAAC,CAW/B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAY1E;AA2DD;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,oBAAoB,GAC/B,OAAO,CAAC,OAAO,CAAC,CAmBlB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,oBAAoB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CA0DjC;AAID;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,CAAC,CAKhC;AAED;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CACtD,qBAAqB,EAAE,CACxB,CAYA;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,iBAEzC;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,gBAEzD;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,KAAA,gBAErE","file":"Saml2Ops.d.ts","sourcesContent":["import _ from 'lodash';\nimport {\n Saml2ProiderLocation,\n Saml2ProviderSkeleton,\n Saml2ProviderStub,\n} from '../api/ApiTypes';\nimport {\n createProvider,\n deleteRawProvider,\n findProviders,\n getProviderByLocationAndId as _getProviderByLocationAndId,\n getProviderMetadata as _getProviderMetadata,\n getProviderMetadataUrl as _getProviderMetadataUrl,\n getRawProvider as _getRawProvider,\n getProviders,\n getRawProviders as _getRawProviders,\n putRawProvider as _putRawProvider,\n deleteProviderByLocationAndId,\n} from '../api/Saml2Api';\nimport { getScript } from '../api/ScriptApi';\nimport {\n decode,\n decodeBase64Url,\n encode,\n encodeBase64Url,\n} from '../api/utils/Base64';\nimport { MultiOpStatusInterface, Saml2ExportInterface } from './OpsTypes';\nimport { putScript } from './ScriptOps';\nimport {\n createProgressIndicator,\n debugMessage,\n printMessage,\n stopProgressIndicator,\n updateProgressIndicator,\n} from './utils/Console';\nimport {\n convertBase64TextToArray,\n convertBase64UrlTextToArray,\n convertTextArrayToBase64,\n convertTextArrayToBase64Url,\n getMetadata,\n} from './utils/ExportImportUtils';\n\nexport const roleMap = {\n identityProvider: 'IDP',\n serviceProvider: 'SP',\n attributeQueryProvider: 'AttrQuery',\n xacmlPolicyEnforcementPoint: 'XACML PEP',\n};\n\n// use a function vs a template variable to avoid problems in loops\nexport function createSaml2ExportTemplate(): Saml2ExportInterface {\n return {\n meta: getMetadata(),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n },\n } as Saml2ExportInterface;\n}\n\n/**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getSaml2ProviderStubs(): Promise<Saml2ProviderStub[]> {\n const { result } = await getProviders();\n return result;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId(\n location: string,\n entityId64: string\n) {\n return _getProviderByLocationAndId(location, entityId64);\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl(entityId: string): string {\n return _getProviderMetadataUrl(entityId);\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata(entityId) {\n return _getProviderMetadata(entityId);\n}\n\n/**\n * Include dependencies in the export file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(providerData, fileData) {\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n const scriptData = await getScript(attrMapperScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[attrMapperScriptId] = scriptData;\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n const scriptData = await getScript(idpAdapterScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[idpAdapterScriptId] = scriptData;\n }\n const metaDataResponse = await getProviderMetadata(providerData.entityId);\n // eslint-disable-next-line no-param-reassign\n fileData.saml.metadata[providerData._id] = convertBase64UrlTextToArray(\n encodeBase64Url(metaDataResponse)\n );\n}\n\n/**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2ProviderStub(\n entityId: string\n): Promise<Saml2ProviderStub> {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: start [entityId=${entityId}]`);\n const found = await findProviders(`entityId eq '${entityId}'`);\n switch (found.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: end [entityId=${entityId}]`);\n return found.result[0];\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.getSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.getSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await deleteProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\nexport async function deleteSaml2Providers(): Promise<Saml2ProviderSkeleton[]> {\n debugMessage(`Saml2Ops.deleteSaml2Providers: start`);\n const providers: Saml2ProviderSkeleton[] = [];\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const provider = await deleteProviderByLocationAndId(\n stub.location,\n stub._id\n );\n providers.push(provider);\n }\n debugMessage(\n `Saml2Ops.deleteSaml2Providers: end [deleted ${providers.length} providers]`\n );\n return providers;\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Provider(\n entityId: string\n): Promise<Saml2ExportInterface> {\n debugMessage(`Saml2Ops.exportSaml2Provider: start [entityId=${entityId}]`);\n const exportData = createSaml2ExportTemplate();\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n exportData.saml[stub.location][providerData._id] = providerData;\n await exportDependencies(providerData, exportData);\n debugMessage(`Saml2Ops.exportSaml2Provider: end [entityId=${entityId}]`);\n return exportData;\n}\n\n/**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Providers(): Promise<Saml2ExportInterface> {\n const fileData = createSaml2ExportTemplate();\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const providerData = await getProviderByLocationAndId(\n stub.location,\n stub._id\n );\n await exportDependencies(providerData, fileData);\n fileData.saml[stub.location][providerData._id] = providerData;\n }\n return fileData;\n}\n\n/**\n * Include dependencies from the import file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to read dependencies from\n */\nasync function importDependencies(providerData, fileData) {\n debugMessage(`Saml2Ops.importDependencies: start`);\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: attributeMapperScript=${attrMapperScriptId}`\n );\n const scriptData = _.get(fileData, ['script', attrMapperScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(attrMapperScriptId, scriptData);\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: idpAdapterScript=${idpAdapterScriptId}`\n );\n const scriptData = _.get(fileData, ['script', idpAdapterScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(idpAdapterScriptId, scriptData);\n }\n debugMessage(`Saml2Ops.importDependencies: end`);\n}\n\n/**\n * Find provider in import file and return its location\n * @param {string} entityId64 Base64-encoded provider entity id\n * @param {Saml2ExportInterface} data Import file json data\n * @returns {string} 'hosted' or 'remote' if found, undefined otherwise\n */\nfunction getLocation(\n entityId64: string,\n data: Saml2ExportInterface\n): Saml2ProiderLocation {\n if (data.saml.hosted[entityId64]) {\n return Saml2ProiderLocation.HOSTED;\n }\n if (data.saml.remote[entityId64]) {\n return Saml2ProiderLocation.REMOTE;\n }\n return undefined;\n}\n\n/**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Provider(\n entityId: string,\n importData: Saml2ExportInterface\n): Promise<boolean> {\n debugMessage(`Saml2Ops.importSaml2Provider: start`);\n const entityId64 = encode(entityId, false);\n const location = getLocation(entityId64, importData);\n if (location) {\n const providerData = importData.saml[location][entityId64];\n await importDependencies(providerData, importData);\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n await createProvider(location, providerData, metaData);\n } else {\n throw new Error(`Provider ${entityId} not found in import data!`);\n }\n debugMessage(`Saml2Ops.importSaml2Provider: end`);\n return true;\n}\n\n/**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Providers(\n importData: Saml2ExportInterface\n): Promise<MultiOpStatusInterface> {\n debugMessage(`Saml2Ops.importSaml2Providers: start`);\n const myStatus: MultiOpStatusInterface = {\n total: 0,\n successes: 0,\n warnings: 0,\n failures: 0,\n };\n try {\n // find providers in hosted and in remote and map locations\n const hostedIds = Object.keys(importData.saml.hosted);\n const remoteIds = Object.keys(importData.saml.remote);\n const providerIds = hostedIds.concat(remoteIds);\n myStatus.total = providerIds.length;\n createProgressIndicator(providerIds.length, 'Importing providers...');\n for (const entityId64 of providerIds) {\n debugMessage(\n `Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(entityId64)}`\n );\n const location = hostedIds.includes(entityId64)\n ? Saml2ProiderLocation.HOSTED\n : Saml2ProiderLocation.REMOTE;\n const entityId = decode(entityId64);\n const providerData = importData.saml[location][entityId64];\n try {\n await importDependencies(providerData, importData);\n } catch (importDependenciesErr) {\n myStatus.warnings += 1;\n printMessage(\n `\\nWarning importing dependencies for ${entityId}`,\n 'warn'\n );\n printMessage(importDependenciesErr.response.data, 'error');\n }\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider(location, providerData, metaData);\n myStatus.successes += 1;\n updateProgressIndicator(`Imported ${entityId}`);\n } catch (createProviderErr) {\n myStatus.failures += 1;\n printMessage(`\\nError importing provider ${entityId}`, 'error');\n printMessage(createProviderErr, 'error');\n }\n }\n myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;\n stopProgressIndicator(myStatus.message);\n } catch (error) {\n myStatus.failures += 1;\n printMessage(`\\nError importing providers ${error.message}`, 'error');\n }\n debugMessage(`Saml2Ops.importSaml2Providers: end`);\n return myStatus;\n}\n\n// Contributions using legacy APIs. Need to investigate if those will be deprecated in the future\n\n/**\n * Deletes entity provider\n * @param {string} entityId The entity id for the entity to be deleted\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteRawSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const response = await deleteRawProvider(entityId);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return response;\n}\n\n/**\n * Deletes all entity providers.\n */\nexport async function deleteRawSaml2Providers(): Promise<\n Saml2ProviderSkeleton[]\n> {\n const applicationList = (await getRawSaml2Providers()).result;\n const deleteApplicationPromises = [];\n applicationList.forEach((item) => {\n printMessage(`Deleting Application ${item._id}`, 'error');\n deleteApplicationPromises.push(deleteRawProvider(item._id));\n });\n const deleteApplicationResult = await Promise.all(deleteApplicationPromises);\n if (deleteApplicationResult.length == applicationList.length) {\n printMessage('SAML Entity cleanup done', 'info');\n }\n return deleteApplicationResult;\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Providers() {\n return _getRawProviders();\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @param {string} entityId The entity provider id\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Provider(entityId: string) {\n return _getRawProvider(entityId);\n}\n\n/**\n * Stores a new SAML2 entity provider\n * @param {string} entityId The entity provider id\n * @param {string} entityData The actual data containing the entity provider configuration\n * @returns {Promise} Promise that resolves to a provider object\n */\nexport async function putRawSaml2Provider(entityId: string, entityData) {\n return _putRawProvider(entityId, entityData);\n}\n"]}
1
+ {"version":3,"sources":["../src/ops/Saml2Ops.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAsBzB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAW1E,eAAO,MAAM,OAAO;;;;;CAKnB,CAAC;AAGF,wBAAgB,yBAAyB,IAAI,oBAAoB,CAUhE;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAG1E;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,gBAGnB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE/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AErE","file":"Saml2Ops.d.ts","sourcesContent":["import _ from 'lodash';\nimport {\n Saml2ProiderLocation,\n Saml2ProviderSkeleton,\n Saml2ProviderStub,\n} from '../api/ApiTypes';\nimport {\n createProvider,\n updateProvider,\n deleteRawProvider,\n findProviders,\n getProviderByLocationAndId as _getProviderByLocationAndId,\n getProviderMetadata as _getProviderMetadata,\n getProviderMetadataUrl as _getProviderMetadataUrl,\n getRawProvider as _getRawProvider,\n getProviders,\n getRawProviders as _getRawProviders,\n putRawProvider as _putRawProvider,\n deleteProviderByLocationAndId,\n} from '../api/Saml2Api';\nimport { getScript } from '../api/ScriptApi';\nimport {\n decode,\n decodeBase64Url,\n encode,\n encodeBase64Url,\n} from '../api/utils/Base64';\nimport { MultiOpStatusInterface, Saml2ExportInterface } from './OpsTypes';\nimport { putScript } from './ScriptOps';\nimport { debugMessage, printMessage } from './utils/Console';\nimport {\n convertBase64TextToArray,\n convertBase64UrlTextToArray,\n convertTextArrayToBase64,\n convertTextArrayToBase64Url,\n getMetadata,\n} from './utils/ExportImportUtils';\n\nexport const roleMap = {\n identityProvider: 'IDP',\n serviceProvider: 'SP',\n attributeQueryProvider: 'AttrQuery',\n xacmlPolicyEnforcementPoint: 'XACML PEP',\n};\n\n// use a function vs a template variable to avoid problems in loops\nexport function createSaml2ExportTemplate(): Saml2ExportInterface {\n return {\n meta: getMetadata(),\n script: {},\n saml: {\n hosted: {},\n remote: {},\n metadata: {},\n },\n } as Saml2ExportInterface;\n}\n\n/**\n * Get SAML2 entity provider stubs\n * @returns {Promise<Saml2ProviderStub[]>} a promise that resolves to an array of saml2 entity stubs\n */\nexport async function getSaml2ProviderStubs(): Promise<Saml2ProviderStub[]> {\n const { result } = await getProviders();\n return result;\n}\n\n/**\n * Geta SAML2 entity provider by location and id\n * @param {string} location Entity provider location (hosted or remote)\n * @param {string} entityId64 Base64-encoded-without-padding provider entity id\n * @returns {Promise} a promise that resolves to a saml2 entity provider object\n */\nexport async function getProviderByLocationAndId(\n location: string,\n entityId64: string\n) {\n return _getProviderByLocationAndId(location, entityId64);\n}\n\n/**\n * Get a SAML2 entity provider's metadata URL by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {string} the URL to get the metadata from\n */\nexport function getProviderMetadataUrl(entityId: string): string {\n return _getProviderMetadataUrl(entityId);\n}\n\n/**\n * Get a SAML2 entity provider's metadata by entity id\n * @param {string} entityId SAML2 entity id\n * @returns {Promise<object>} a promise that resolves to an object containing a SAML2 metadata\n */\nexport async function getProviderMetadata(entityId) {\n return _getProviderMetadata(entityId);\n}\n\n/**\n * Include dependencies in the export file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to add dependencies to\n */\nasync function exportDependencies(providerData, fileData) {\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n const scriptData = await getScript(attrMapperScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[attrMapperScriptId] = scriptData;\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n const scriptData = await getScript(idpAdapterScriptId);\n scriptData.script = convertBase64TextToArray(scriptData.script);\n // eslint-disable-next-line no-param-reassign\n fileData.script[idpAdapterScriptId] = scriptData;\n }\n const metaDataResponse = await getProviderMetadata(providerData.entityId);\n // eslint-disable-next-line no-param-reassign\n fileData.saml.metadata[providerData._id] = convertBase64UrlTextToArray(\n encodeBase64Url(metaDataResponse)\n );\n}\n\n/**\n *\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderStub>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2ProviderStub(\n entityId: string\n): Promise<Saml2ProviderStub> {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: start [entityId=${entityId}]`);\n const found = await findProviders(`entityId eq '${entityId}'`);\n switch (found.resultCount) {\n case 0:\n throw new Error(`No provider with entity id '${entityId}' found`);\n case 1: {\n debugMessage(`Saml2Ops.getSaml2ProviderStub: end [entityId=${entityId}]`);\n return found.result[0];\n }\n default:\n throw new Error(`Multiple providers with entity id '${entityId}' found`);\n }\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function getSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.getSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.getSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete an entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await deleteProviderByLocationAndId(location, id);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return providerData;\n}\n\n/**\n * Delete all entity providers.\n * @returns {Promise<Saml2ProviderSkeleton[]>} Promise resolving to an array of Saml2ProviderSkeleton objects.\n */\nexport async function deleteSaml2Providers(): Promise<Saml2ProviderSkeleton[]> {\n debugMessage(`Saml2Ops.deleteSaml2Providers: start`);\n const providers: Saml2ProviderSkeleton[] = [];\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const provider = await deleteProviderByLocationAndId(\n stub.location,\n stub._id\n );\n providers.push(provider);\n }\n debugMessage(\n `Saml2Ops.deleteSaml2Providers: end [deleted ${providers.length} providers]`\n );\n return providers;\n}\n\n/**\n * Export a single entity provider. The response can be saved to file as is.\n * @param {string} entityId Provider entity id\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Provider(\n entityId: string\n): Promise<Saml2ExportInterface> {\n debugMessage(`Saml2Ops.exportSaml2Provider: start [entityId=${entityId}]`);\n const exportData = createSaml2ExportTemplate();\n const stub = await getSaml2ProviderStub(entityId);\n const { location } = stub;\n const id = stub._id;\n const providerData = await getProviderByLocationAndId(location, id);\n exportData.saml[stub.location][providerData._id] = providerData;\n await exportDependencies(providerData, exportData);\n debugMessage(`Saml2Ops.exportSaml2Provider: end [entityId=${entityId}]`);\n return exportData;\n}\n\n/**\n * Export all entity providers. The response can be saved to file as is.\n * @returns {Promise<Saml2ExportInterface>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function exportSaml2Providers(): Promise<Saml2ExportInterface> {\n const fileData = createSaml2ExportTemplate();\n const stubs = await getSaml2ProviderStubs();\n for (const stub of stubs) {\n const providerData = await getProviderByLocationAndId(\n stub.location,\n stub._id\n );\n await exportDependencies(providerData, fileData);\n fileData.saml[stub.location][providerData._id] = providerData;\n }\n return fileData;\n}\n\n/**\n * Include dependencies from the import file\n * @param {object} providerData Object representing a SAML entity provider\n * @param {object} fileData File data object to read dependencies from\n */\nasync function importDependencies(providerData, fileData) {\n debugMessage(`Saml2Ops.importDependencies: start`);\n const attrMapperScriptId = _.get(providerData, [\n 'identityProvider',\n 'assertionProcessing',\n 'attributeMapper',\n 'attributeMapperScript',\n ]);\n if (attrMapperScriptId && attrMapperScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: attributeMapperScript=${attrMapperScriptId}`\n );\n const scriptData = _.get(fileData, ['script', attrMapperScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(attrMapperScriptId, scriptData);\n }\n const idpAdapterScriptId = _.get(providerData, [\n 'identityProvider',\n 'advanced',\n 'idpAdapter',\n 'idpAdapterScript',\n ]);\n if (idpAdapterScriptId && idpAdapterScriptId !== '[Empty]') {\n debugMessage(\n `Saml2Ops.importDependencies: idpAdapterScript=${idpAdapterScriptId}`\n );\n const scriptData = _.get(fileData, ['script', idpAdapterScriptId]);\n scriptData.script = convertTextArrayToBase64(scriptData.script);\n await putScript(idpAdapterScriptId, scriptData);\n }\n debugMessage(`Saml2Ops.importDependencies: end`);\n}\n\n/**\n * Find provider in import file and return its location\n * @param {string} entityId64 Base64-encoded provider entity id\n * @param {Saml2ExportInterface} data Import file json data\n * @returns {string} 'hosted' or 'remote' if found, undefined otherwise\n */\nfunction getLocation(\n entityId64: string,\n data: Saml2ExportInterface\n): Saml2ProiderLocation {\n if (data.saml.hosted[entityId64]) {\n return Saml2ProiderLocation.HOSTED;\n }\n if (data.saml.remote[entityId64]) {\n return Saml2ProiderLocation.REMOTE;\n }\n return undefined;\n}\n\n/**\n * Import a SAML entity provider\n * @param {string} entityId Provider entity id\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Provider(\n entityId: string,\n importData: Saml2ExportInterface\n): Promise<boolean> {\n debugMessage(`Saml2Ops.importSaml2Provider: start`);\n const entityId64 = encode(entityId, false);\n const location = getLocation(entityId64, importData);\n debugMessage(\n `Saml2Ops.importSaml2Provider: entityId=${entityId}, entityId64=${entityId64}, location=${location}`\n );\n if (location) {\n const providerData = importData.saml[location][entityId64];\n await importDependencies(providerData, importData);\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider(location, providerData, metaData);\n } catch (error) {\n await updateProvider(location, providerData);\n }\n } else {\n throw new Error(`Provider ${entityId} not found in import data!`);\n }\n debugMessage(`Saml2Ops.importSaml2Provider: end`);\n return true;\n}\n\n/**\n * Import SAML entity providers\n * @param {Saml2ExportInterface} importData Import data\n */\nexport async function importSaml2Providers(\n importData: Saml2ExportInterface\n): Promise<MultiOpStatusInterface> {\n debugMessage(`Saml2Ops.importSaml2Providers: start`);\n const myStatus: MultiOpStatusInterface = {\n total: 0,\n successes: 0,\n warnings: 0,\n failures: 0,\n };\n try {\n // find providers in hosted and in remote and map locations\n const hostedIds = Object.keys(importData.saml.hosted);\n const remoteIds = Object.keys(importData.saml.remote);\n const providerIds = hostedIds.concat(remoteIds);\n myStatus.total = providerIds.length;\n for (const entityId64 of providerIds) {\n debugMessage(\n `Saml2Ops.importSaml2Providers: entityId=${decodeBase64Url(entityId64)}`\n );\n const location = hostedIds.includes(entityId64)\n ? Saml2ProiderLocation.HOSTED\n : Saml2ProiderLocation.REMOTE;\n const entityId = decode(entityId64);\n const providerData = importData.saml[location][entityId64];\n try {\n await importDependencies(providerData, importData);\n } catch (importDependenciesErr) {\n myStatus.warnings += 1;\n printMessage(\n `\\nWarning importing dependencies for ${entityId}`,\n 'warn'\n );\n printMessage(importDependenciesErr.response.data, 'error');\n }\n let metaData = null;\n if (location === Saml2ProiderLocation.REMOTE) {\n metaData = convertTextArrayToBase64Url(\n importData.saml.metadata[entityId64]\n );\n }\n try {\n await createProvider(location, providerData, metaData);\n myStatus.successes += 1;\n } catch (createProviderErr) {\n try {\n await updateProvider(location, providerData);\n myStatus.successes += 1;\n } catch (updateProviderError) {\n myStatus.failures += 1;\n printMessage(\n `\\nError importing provider ${entityId}: ${updateProviderError.message}`,\n 'error'\n );\n printMessage(updateProviderError.response?.data, 'error');\n }\n }\n }\n myStatus.message = `${myStatus.successes}/${myStatus.total} providers imported.`;\n } catch (error) {\n myStatus.failures += 1;\n printMessage(`\\nError importing providers ${error.message}`, 'error');\n }\n debugMessage(`Saml2Ops.importSaml2Providers: end`);\n return myStatus;\n}\n\n// Contributions using legacy APIs. Need to investigate if those will be deprecated in the future\n\n/**\n * Deletes entity provider\n * @param {string} entityId The entity id for the entity to be deleted\n * @returns {Promise<Saml2ProviderSkeleton>} Promise resolving to a Saml2ExportInterface object.\n */\nexport async function deleteRawSaml2Provider(\n entityId: string\n): Promise<Saml2ProviderSkeleton> {\n debugMessage(`Saml2Ops.deleteSaml2Provider: start [entityId=${entityId}]`);\n const response = await deleteRawProvider(entityId);\n debugMessage(`Saml2Ops.deleteSaml2Provider: end [entityId=${entityId}]`);\n return response;\n}\n\n/**\n * Deletes all entity providers.\n */\nexport async function deleteRawSaml2Providers(): Promise<\n Saml2ProviderSkeleton[]\n> {\n const applicationList = (await getRawSaml2Providers()).result;\n const deleteApplicationPromises = [];\n applicationList.forEach((item) => {\n printMessage(`Deleting Application ${item._id}`, 'error');\n deleteApplicationPromises.push(deleteRawProvider(item._id));\n });\n const deleteApplicationResult = await Promise.all(deleteApplicationPromises);\n if (deleteApplicationResult.length == applicationList.length) {\n printMessage('SAML Entity cleanup done', 'info');\n }\n return deleteApplicationResult;\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Providers() {\n return _getRawProviders();\n}\n\n/**\n * Retrieves all entity providers using the legacy federation enpoints.\n * @param {string} entityId The entity provider id\n * @returns {Promise} a promise that resolves to an object containing an array of providers\n */\nexport async function getRawSaml2Provider(entityId: string) {\n return _getRawProvider(entityId);\n}\n\n/**\n * Stores a new SAML2 entity provider\n * @param {string} entityId The entity provider id\n * @param {string} entityData The actual data containing the entity provider configuration\n * @returns {Promise} Promise that resolves to a provider object\n */\nexport async function putRawSaml2Provider(entityId: string, entityData) {\n return _putRawProvider(entityId, entityData);\n}\n"]}