mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-29 04:17:41 +02:00
[SM-88] [BEEEP] Add support for chrome.storage.managed for environment urls (#3120)
* Add managed_schema * Add note on login page which server you are logging into. * Implement it * Remove caching logic since it seems unecessary * Add error * Handle error in hasManagedEnvironment * Fix compile
This commit is contained in:
parent
c263eacd88
commit
af371af6e1
@ -1976,5 +1976,23 @@
|
|||||||
},
|
},
|
||||||
"cardBrandMir": {
|
"cardBrandMir": {
|
||||||
"message": "Mir"
|
"message": "Mir"
|
||||||
|
},
|
||||||
|
"loggingInTo": {
|
||||||
|
"message": "Logging in to $DOMAIN$",
|
||||||
|
"placeholders": {
|
||||||
|
"domain": {
|
||||||
|
"content": "$1",
|
||||||
|
"example": "example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settingsEdited": {
|
||||||
|
"message": "Settings have been edited"
|
||||||
|
},
|
||||||
|
"environmentEditedClick": {
|
||||||
|
"message": "Click here"
|
||||||
|
},
|
||||||
|
"environmentEditedReset": {
|
||||||
|
"message": "to reset to pre-configured settings"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/abs
|
|||||||
import { CollectionService as CollectionServiceAbstraction } from "@bitwarden/common/abstractions/collection.service";
|
import { CollectionService as CollectionServiceAbstraction } from "@bitwarden/common/abstractions/collection.service";
|
||||||
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.service";
|
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.service";
|
||||||
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/abstractions/cryptoFunction.service";
|
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/abstractions/cryptoFunction.service";
|
||||||
import { EnvironmentService as EnvironmentServiceAbstraction } from "@bitwarden/common/abstractions/environment.service";
|
|
||||||
import { EventService as EventServiceAbstraction } from "@bitwarden/common/abstractions/event.service";
|
import { EventService as EventServiceAbstraction } from "@bitwarden/common/abstractions/event.service";
|
||||||
import { ExportService as ExportServiceAbstraction } from "@bitwarden/common/abstractions/export.service";
|
import { ExportService as ExportServiceAbstraction } from "@bitwarden/common/abstractions/export.service";
|
||||||
import { FileUploadService as FileUploadServiceAbstraction } from "@bitwarden/common/abstractions/fileUpload.service";
|
import { FileUploadService as FileUploadServiceAbstraction } from "@bitwarden/common/abstractions/fileUpload.service";
|
||||||
@ -50,7 +49,6 @@ import { CollectionService } from "@bitwarden/common/services/collection.service
|
|||||||
import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service";
|
import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service";
|
||||||
import { ContainerService } from "@bitwarden/common/services/container.service";
|
import { ContainerService } from "@bitwarden/common/services/container.service";
|
||||||
import { EncryptService } from "@bitwarden/common/services/encrypt.service";
|
import { EncryptService } from "@bitwarden/common/services/encrypt.service";
|
||||||
import { EnvironmentService } from "@bitwarden/common/services/environment.service";
|
|
||||||
import { EventService } from "@bitwarden/common/services/event.service";
|
import { EventService } from "@bitwarden/common/services/event.service";
|
||||||
import { ExportService } from "@bitwarden/common/services/export.service";
|
import { ExportService } from "@bitwarden/common/services/export.service";
|
||||||
import { FileUploadService } from "@bitwarden/common/services/fileUpload.service";
|
import { FileUploadService } from "@bitwarden/common/services/fileUpload.service";
|
||||||
@ -84,6 +82,7 @@ import { PopupUtilsService } from "../popup/services/popup-utils.service";
|
|||||||
import { AutofillService as AutofillServiceAbstraction } from "../services/abstractions/autofill.service";
|
import { AutofillService as AutofillServiceAbstraction } from "../services/abstractions/autofill.service";
|
||||||
import { StateService as StateServiceAbstraction } from "../services/abstractions/state.service";
|
import { StateService as StateServiceAbstraction } from "../services/abstractions/state.service";
|
||||||
import AutofillService from "../services/autofill.service";
|
import AutofillService from "../services/autofill.service";
|
||||||
|
import { BrowserEnvironmentService } from "../services/browser-environment.service";
|
||||||
import { BrowserCryptoService } from "../services/browserCrypto.service";
|
import { BrowserCryptoService } from "../services/browserCrypto.service";
|
||||||
import BrowserLocalStorageService from "../services/browserLocalStorage.service";
|
import BrowserLocalStorageService from "../services/browserLocalStorage.service";
|
||||||
import BrowserMessagingService from "../services/browserMessaging.service";
|
import BrowserMessagingService from "../services/browserMessaging.service";
|
||||||
@ -119,7 +118,7 @@ export default class MainBackground {
|
|||||||
tokenService: TokenServiceAbstraction;
|
tokenService: TokenServiceAbstraction;
|
||||||
appIdService: AppIdServiceAbstraction;
|
appIdService: AppIdServiceAbstraction;
|
||||||
apiService: ApiServiceAbstraction;
|
apiService: ApiServiceAbstraction;
|
||||||
environmentService: EnvironmentServiceAbstraction;
|
environmentService: BrowserEnvironmentService;
|
||||||
settingsService: SettingsServiceAbstraction;
|
settingsService: SettingsServiceAbstraction;
|
||||||
cipherService: CipherServiceAbstraction;
|
cipherService: CipherServiceAbstraction;
|
||||||
folderService: InternalFolderServiceAbstraction;
|
folderService: InternalFolderServiceAbstraction;
|
||||||
@ -253,7 +252,7 @@ export default class MainBackground {
|
|||||||
);
|
);
|
||||||
this.tokenService = new TokenService(this.stateService);
|
this.tokenService = new TokenService(this.stateService);
|
||||||
this.appIdService = new AppIdService(this.storageService);
|
this.appIdService = new AppIdService(this.storageService);
|
||||||
this.environmentService = new EnvironmentService(this.stateService);
|
this.environmentService = new BrowserEnvironmentService(this.stateService, this.logService);
|
||||||
this.apiService = new ApiService(
|
this.apiService = new ApiService(
|
||||||
this.tokenService,
|
this.tokenService,
|
||||||
this.platformUtilsService,
|
this.platformUtilsService,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
||||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
||||||
@ -6,6 +5,8 @@ import { NotificationsService } from "@bitwarden/common/abstractions/notificatio
|
|||||||
import { SystemService } from "@bitwarden/common/abstractions/system.service";
|
import { SystemService } from "@bitwarden/common/abstractions/system.service";
|
||||||
import { Utils } from "@bitwarden/common/misc/utils";
|
import { Utils } from "@bitwarden/common/misc/utils";
|
||||||
|
|
||||||
|
import { BrowserEnvironmentService } from "src/services/browser-environment.service";
|
||||||
|
|
||||||
import { BrowserApi } from "../browser/browserApi";
|
import { BrowserApi } from "../browser/browserApi";
|
||||||
import { AutofillService } from "../services/abstractions/autofill.service";
|
import { AutofillService } from "../services/abstractions/autofill.service";
|
||||||
import BrowserPlatformUtilsService from "../services/browserPlatformUtils.service";
|
import BrowserPlatformUtilsService from "../services/browserPlatformUtils.service";
|
||||||
@ -26,7 +27,7 @@ export default class RuntimeBackground {
|
|||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
private systemService: SystemService,
|
private systemService: SystemService,
|
||||||
private environmentService: EnvironmentService,
|
private environmentService: BrowserEnvironmentService,
|
||||||
private messagingService: MessagingService,
|
private messagingService: MessagingService,
|
||||||
private logService: LogService
|
private logService: LogService
|
||||||
) {
|
) {
|
||||||
@ -227,6 +228,10 @@ export default class RuntimeBackground {
|
|||||||
if (this.onInstalledReason != null) {
|
if (this.onInstalledReason != null) {
|
||||||
if (this.onInstalledReason === "install") {
|
if (this.onInstalledReason === "install") {
|
||||||
BrowserApi.createNewTab("https://bitwarden.com/browser-start/");
|
BrowserApi.createNewTab("https://bitwarden.com/browser-start/");
|
||||||
|
|
||||||
|
if (await this.environmentService.hasManagedEnvironment()) {
|
||||||
|
await this.environmentService.setUrlsToManagedEnvironment();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onInstalledReason = null;
|
this.onInstalledReason = null;
|
||||||
|
20
apps/browser/src/managed_schema.json
Normal file
20
apps/browser/src/managed_schema.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"environment": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"base": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Base url, typically only this value needs to be set"
|
||||||
|
},
|
||||||
|
"webVault": { "type": "string" },
|
||||||
|
"api": { "type": "string" },
|
||||||
|
"identity": { "type": "string" },
|
||||||
|
"icons": { "type": "string" },
|
||||||
|
"notifications": { "type": "string" },
|
||||||
|
"events": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -119,5 +119,8 @@
|
|||||||
"default_title": "Bitwarden",
|
"default_title": "Bitwarden",
|
||||||
"default_panel": "popup/index.html?uilocation=sidebar",
|
"default_panel": "popup/index.html?uilocation=sidebar",
|
||||||
"default_icon": "images/icon19.png"
|
"default_icon": "images/icon19.png"
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"managed_schema": "managed_schema.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<main tabindex="-1">
|
<main tabindex="-1">
|
||||||
|
<app-callout
|
||||||
|
type="info"
|
||||||
|
title="{{ 'settingsEdited' | i18n }}"
|
||||||
|
*ngIf="showEditedManagedSettings"
|
||||||
|
>
|
||||||
|
<a href="#" appStopClick (click)="resetEnvironment()">
|
||||||
|
{{ "environmentEditedClick" | i18n }}
|
||||||
|
</a>
|
||||||
|
{{ "environmentEditedReset" | i18n }}
|
||||||
|
</app-callout>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2 class="box-header">
|
<h2 class="box-header">
|
||||||
{{ "selfHostedEnvironment" | i18n }}
|
{{ "selfHostedEnvironment" | i18n }}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component, OnInit } from "@angular/core";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
|
|
||||||
import { EnvironmentComponent as BaseEnvironmentComponent } from "@bitwarden/angular/components/environment.component";
|
import { EnvironmentComponent as BaseEnvironmentComponent } from "@bitwarden/angular/components/environment.component";
|
||||||
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
||||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
||||||
|
|
||||||
|
import { BrowserEnvironmentService } from "../../services/browser-environment.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-environment",
|
selector: "app-environment",
|
||||||
templateUrl: "environment.component.html",
|
templateUrl: "environment.component.html",
|
||||||
})
|
})
|
||||||
export class EnvironmentComponent extends BaseEnvironmentComponent {
|
export class EnvironmentComponent extends BaseEnvironmentComponent implements OnInit {
|
||||||
|
showEditedManagedSettings = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
environmentService: EnvironmentService,
|
public environmentService: BrowserEnvironmentService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {
|
) {
|
||||||
@ -21,6 +24,22 @@ export class EnvironmentComponent extends BaseEnvironmentComponent {
|
|||||||
this.showCustom = true;
|
this.showCustom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async ngOnInit() {
|
||||||
|
this.showEditedManagedSettings = await this.environmentService.settingsHaveChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
async resetEnvironment() {
|
||||||
|
const urls = await this.environmentService.getManagedEnvironment();
|
||||||
|
|
||||||
|
this.baseUrl = urls.base;
|
||||||
|
this.webVaultUrl = urls.webVault;
|
||||||
|
this.apiUrl = urls.api;
|
||||||
|
this.iconsUrl = urls.icons;
|
||||||
|
this.identityUrl = urls.identity;
|
||||||
|
this.notificationsUrl = urls.notifications;
|
||||||
|
this.iconsUrl = urls.icons;
|
||||||
|
}
|
||||||
|
|
||||||
saved() {
|
saved() {
|
||||||
super.saved();
|
super.saved();
|
||||||
this.router.navigate([""]);
|
this.router.navigate([""]);
|
||||||
|
@ -63,6 +63,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="text-center text-muted" *ngIf="selfHostedDomain">
|
||||||
|
{{ "loggingInTo" | i18n: selfHostedDomain }}
|
||||||
|
</p>
|
||||||
<p class="text-center">
|
<p class="text-center">
|
||||||
<button type="button" routerLink="/hint">{{ "getMasterPasswordHint" | i18n }}</button>
|
<button type="button" routerLink="/hint">{{ "getMasterPasswordHint" | i18n }}</button>
|
||||||
</p>
|
</p>
|
||||||
|
@ -56,6 +56,7 @@ import MainBackground from "../../background/main.background";
|
|||||||
import { BrowserApi } from "../../browser/browserApi";
|
import { BrowserApi } from "../../browser/browserApi";
|
||||||
import { AutofillService } from "../../services/abstractions/autofill.service";
|
import { AutofillService } from "../../services/abstractions/autofill.service";
|
||||||
import { StateService as StateServiceAbstraction } from "../../services/abstractions/state.service";
|
import { StateService as StateServiceAbstraction } from "../../services/abstractions/state.service";
|
||||||
|
import { BrowserEnvironmentService } from "../../services/browser-environment.service";
|
||||||
import { BrowserFileDownloadService } from "../../services/browserFileDownloadService";
|
import { BrowserFileDownloadService } from "../../services/browserFileDownloadService";
|
||||||
import BrowserMessagingService from "../../services/browserMessaging.service";
|
import BrowserMessagingService from "../../services/browserMessaging.service";
|
||||||
import BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service";
|
import BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service";
|
||||||
@ -172,6 +173,10 @@ function getBgService<T>(service: keyof MainBackground) {
|
|||||||
useFactory: getBgService<ConsoleLogService>("logService"),
|
useFactory: getBgService<ConsoleLogService>("logService"),
|
||||||
deps: [],
|
deps: [],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: BrowserEnvironmentService,
|
||||||
|
useExisting: EnvironmentService,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: EnvironmentService,
|
provide: EnvironmentService,
|
||||||
useFactory: getBgService<EnvironmentService>("environmentService"),
|
useFactory: getBgService<EnvironmentService>("environmentService"),
|
||||||
|
67
apps/browser/src/services/browser-environment.service.ts
Normal file
67
apps/browser/src/services/browser-environment.service.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
||||||
|
import { EnvironmentService } from "@bitwarden/common/services/environment.service";
|
||||||
|
|
||||||
|
type GroupPolicyEnvironment = {
|
||||||
|
base?: string;
|
||||||
|
webVault?: string;
|
||||||
|
api?: string;
|
||||||
|
identity?: string;
|
||||||
|
icons?: string;
|
||||||
|
notifications?: string;
|
||||||
|
events?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class BrowserEnvironmentService extends EnvironmentService {
|
||||||
|
constructor(stateService: StateService, private logService: LogService) {
|
||||||
|
super(stateService);
|
||||||
|
}
|
||||||
|
|
||||||
|
async hasManagedEnvironment(): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
return (await this.getManagedEnvironment()) != null;
|
||||||
|
} catch (e) {
|
||||||
|
this.logService.error(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async settingsHaveChanged() {
|
||||||
|
const env = await this.getManagedEnvironment();
|
||||||
|
|
||||||
|
return (
|
||||||
|
env.base != this.baseUrl ||
|
||||||
|
env.webVault != this.webVaultUrl ||
|
||||||
|
env.api != this.webVaultUrl ||
|
||||||
|
env.identity != this.identityUrl ||
|
||||||
|
env.icons != this.iconsUrl ||
|
||||||
|
env.notifications != this.notificationsUrl ||
|
||||||
|
env.events != this.eventsUrl
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getManagedEnvironment(): Promise<GroupPolicyEnvironment> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
chrome.storage.managed.get("environment", (result) => {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
return reject(chrome.runtime.lastError);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(result.environment);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async setUrlsToManagedEnvironment() {
|
||||||
|
const env = await this.getManagedEnvironment();
|
||||||
|
await this.setUrls({
|
||||||
|
base: env.base,
|
||||||
|
webVault: env.webVault,
|
||||||
|
api: env.api,
|
||||||
|
identity: env.identity,
|
||||||
|
icons: env.icons,
|
||||||
|
notifications: env.notifications,
|
||||||
|
events: env.events,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -85,6 +85,7 @@ const plugins = [
|
|||||||
manifestVersion == 3
|
manifestVersion == 3
|
||||||
? { from: "./src/manifest.v3.json", to: "manifest.json" }
|
? { from: "./src/manifest.v3.json", to: "manifest.json" }
|
||||||
: "./src/manifest.json",
|
: "./src/manifest.json",
|
||||||
|
{ from: "./src/managed_schema.json", to: "managed_schema.json" },
|
||||||
{ from: "./src/_locales", to: "_locales" },
|
{ from: "./src/_locales", to: "_locales" },
|
||||||
{ from: "./src/images", to: "images" },
|
{ from: "./src/images", to: "images" },
|
||||||
{ from: "./src/popup/images", to: "popup/images" },
|
{ from: "./src/popup/images", to: "popup/images" },
|
||||||
|
@ -49,6 +49,10 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
|
|||||||
super(environmentService, i18nService, platformUtilsService);
|
super(environmentService, i18nService, platformUtilsService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get selfHostedDomain() {
|
||||||
|
return this.environmentService.hasBaseUrl() ? this.environmentService.getWebVaultUrl() : null;
|
||||||
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
if (this.email == null || this.email === "") {
|
if (this.email == null || this.email === "") {
|
||||||
this.email = await this.stateService.getRememberedEmail();
|
this.email = await this.stateService.getRememberedEmail();
|
||||||
|
@ -11,13 +11,13 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
|||||||
private readonly urlsSubject = new Subject<Urls>();
|
private readonly urlsSubject = new Subject<Urls>();
|
||||||
urls: Observable<Urls> = this.urlsSubject;
|
urls: Observable<Urls> = this.urlsSubject;
|
||||||
|
|
||||||
private baseUrl: string;
|
protected baseUrl: string;
|
||||||
private webVaultUrl: string;
|
protected webVaultUrl: string;
|
||||||
private apiUrl: string;
|
protected apiUrl: string;
|
||||||
private identityUrl: string;
|
protected identityUrl: string;
|
||||||
private iconsUrl: string;
|
protected iconsUrl: string;
|
||||||
private notificationsUrl: string;
|
protected notificationsUrl: string;
|
||||||
private eventsUrl: string;
|
protected eventsUrl: string;
|
||||||
private keyConnectorUrl: string;
|
private keyConnectorUrl: string;
|
||||||
private scimUrl: string = null;
|
private scimUrl: string = null;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user