{ "version": 3, "sources": ["../ui/app/mn.security.service.js"], "sourcesContent": ["/*\nCopyright 2020-Present Couchbase, Inc.\n\nUse of this software is governed by the Business Source License included in\nthe file licenses/BSL-Couchbase.txt. As of the Change Date specified in that\nfile, in accordance with the Business Source License, use of this software will\nbe governed by the Apache License, Version 2.0, included in the file\nlicenses/APL2.txt.\n*/\n\n\nimport {Injectable} from '@angular/core';\nimport {HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';\nimport {BehaviorSubject, combineLatest} from 'rxjs';\nimport {switchMap, shareReplay, map, pluck,\n distinctUntilChanged} from 'rxjs/operators';\n\nimport {MnHttpRequest} from './mn.http.request.js';\nimport {MnAdminService} from './mn.admin.service.js';\nimport {MnPoolsService} from './mn.pools.service.js';\nimport {MnPermissions} from './ajs.upgraded.providers.js';\n\nimport {singletonGuard} from './mn.core.js';\n\nexport {MnSecurityService};\n\nclass MnSecurityService {\n static get annotations() { return [\n new Injectable()\n ]}\n\n static get parameters() { return [\n HttpClient,\n MnAdminService,\n MnPoolsService,\n MnPermissions\n ]}\n\n constructor(http, mnAdminService, mnPoolsService, mnPermissions) {\n singletonGuard(MnSecurityService);\n this.http = http;\n\n let isEnterprise = mnPoolsService.stream.isEnterprise;\n let compatVersion55 = mnAdminService.stream.compatVersion55;\n let permissionsStream = mnPermissions.stream;\n let settingsReadStream =\n permissionsStream.pipe(pluck('cluster','settings','read'),\n distinctUntilChanged());\n\n this.stream = {};\n\n this.mnAdminService = mnAdminService;\n\n this.stream.getSaslauthdAuth =\n (new BehaviorSubject()).pipe(\n switchMap(this.getSaslauthdAuth.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getCertificate =\n (new BehaviorSubject()).pipe(\n switchMap(this.getCertificate.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getSettingsSecurity =\n (new BehaviorSubject())\n .pipe(switchMap(this.getSettingsSecurity.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getLogRedaction =\n (new BehaviorSubject()).pipe(\n switchMap(this.getLogRedaction.bind(this)));\n\n this.stream.getClusterEncryption =\n this.stream.getSettingsSecurity\n .pipe(pluck('clusterEncryptionLevel'));\n\n this.stream.getClientCertAuth =\n (new BehaviorSubject()).pipe(\n switchMap(this.getClientCertAuth.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getAudit =\n (new BehaviorSubject()).pipe(\n switchMap(this.getAudit.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getAuditDescriptors =\n (new BehaviorSubject()).pipe(\n switchMap(this.getAuditDescriptors.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getAuditNonFilterableDescriptors =\n (new BehaviorSubject()).pipe(\n switchMap(this.getAuditNonFilterableDescriptors.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.postLogRedaction =\n new MnHttpRequest(this.postLogRedaction.bind(this))\n .addSuccess()\n .addError();\n\n this.stream.postSettingsSecurity =\n new MnHttpRequest(this.postSettingsSecurity.bind(this))\n .addSuccess()\n .addError();\n\n this.stream.postClientCertAuth =\n new MnHttpRequest(this.postClientCertAuth.bind(this))\n .addSuccess()\n .addError();\n\n this.stream.postAuditValidation =\n new MnHttpRequest(this.postAudit(true).bind(this))\n .addSuccess()\n .addError();\n\n this.stream.postAudit =\n new MnHttpRequest(this.postAudit(false).bind(this))\n .addSuccess()\n .addError();\n\n this.stream.prepareOtherSettingsFormValues =\n combineLatest([\n isEnterprise,\n compatVersion55,\n settingsReadStream\n ])\n .pipe(switchMap(this.getOtherSettingsSources.bind(this)),\n map(this.getOtherSettings.bind(this)),\n shareReplay({refCount: true, bufferSize: 1}));\n }\n\n postAudit(validate) {\n return (data) => {\n return this.http.post(\"/settings/audit\", data, {\n params: new HttpParams().set(\"just_validate\", validate ? 1 : 0)\n });\n }\n }\n\n postSettingsSecurity(data) {\n return this.http.post(\"/settings/security\", data);\n }\n\n getSettingsSecurity() {\n return this.http.get(\"/settings/security\");\n }\n\n getAuditDescriptors() {\n return this.http.get(\"/settings/audit/descriptors\");\n }\n\n getAuditNonFilterableDescriptors() {\n return this.http\n .get(\"/settings/audit/nonFilterableDescriptors\")\n .pipe(map(data => data.map((desc) => {\n desc.nonFilterable = true;\n return desc;\n })));\n }\n\n getAudit() {\n return this.http.get(\"/settings/audit\");\n }\n\n getSaslauthdAuth() {\n return this.http.get(\"/settings/saslauthdAuth\");\n }\n\n getClientCertAuth() {\n return this.http.get(\"/settings/clientCertAuth\");\n }\n\n postClientCertAuth(data) {\n return this.http.post(\"/settings/clientCertAuth\", data[0], {\n headers: new HttpHeaders().set(\"isNotForm\", data[1])\n });\n }\n\n getLogRedaction() {\n return this.http.get(\"/settings/logRedaction\");\n }\n\n postLogRedaction(data) {\n return this.http.post(\"/settings/logRedaction\", data);\n }\n\n getCertificate() {\n return this.http.get(\"/pools/default/certificate\", {\n params: new HttpParams().set(\"extended\", true)\n });\n }\n\n getOtherSettingsSources([isEnterprise, compatVersion55, settingsRead]) {\n let sources = [\n this.mnAdminService.stream.uiSessionTimeout\n ];\n if (isEnterprise) {\n sources.push(this.stream.getClusterEncryption);\n if (compatVersion55 && settingsRead) {\n sources.push(this.stream.getLogRedaction);\n }\n }\n return combineLatest(sources);\n }\n\n getOtherSettings([session, encryption, redaction]) {\n return {\n logRedactionLevel: {\n logRedactionLevel: redaction ? redaction['logRedactionLevel'] : null\n },\n settingsSecurity: {\n uiSessionTimeout: (Number(session) / 60) || 0,\n clusterEncryptionLevel: (encryption || 'control')\n }\n }\n }\n}\n"], "mappings": "wdA0BA,2BAAwB,WACX,cAAc,CAAE,MAAO,CAChC,GAAI,uBAGK,aAAa,CAAE,MAAO,CAC/B,WACA,eACA,eACA,eAGF,YAAY,KAAM,eAAgB,eAAgB,cAAe,CAC/D,eAAe,mBACf,KAAK,KAAO,KAEZ,GAAI,cAAe,eAAe,OAAO,aACrC,gBAAkB,eAAe,OAAO,gBAExC,mBACA,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