[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:
Oscar Hinton 2022-08-08 13:40:09 +02:00 committed by GitHub
parent c263eacd88
commit af371af6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 173 additions and 18 deletions

View File

@ -1971,10 +1971,28 @@
"organizationIsDisabled": {
"message": "Organization is disabled."
},
"disabledOrganizationFilterError" : {
"disabledOrganizationFilterError": {
"message" : "Items in disabled Organizations cannot be accessed. Contact your Organization owner for assistance."
},
"cardBrandMir": {
"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"
}
}

View File

@ -6,7 +6,6 @@ import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/abs
import { CollectionService as CollectionServiceAbstraction } from "@bitwarden/common/abstractions/collection.service";
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.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 { ExportService as ExportServiceAbstraction } from "@bitwarden/common/abstractions/export.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 { ContainerService } from "@bitwarden/common/services/container.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 { ExportService } from "@bitwarden/common/services/export.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 { StateService as StateServiceAbstraction } from "../services/abstractions/state.service";
import AutofillService from "../services/autofill.service";
import { BrowserEnvironmentService } from "../services/browser-environment.service";
import { BrowserCryptoService } from "../services/browserCrypto.service";
import BrowserLocalStorageService from "../services/browserLocalStorage.service";
import BrowserMessagingService from "../services/browserMessaging.service";
@ -119,7 +118,7 @@ export default class MainBackground {
tokenService: TokenServiceAbstraction;
appIdService: AppIdServiceAbstraction;
apiService: ApiServiceAbstraction;
environmentService: EnvironmentServiceAbstraction;
environmentService: BrowserEnvironmentService;
settingsService: SettingsServiceAbstraction;
cipherService: CipherServiceAbstraction;
folderService: InternalFolderServiceAbstraction;
@ -253,7 +252,7 @@ export default class MainBackground {
);
this.tokenService = new TokenService(this.stateService);
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.tokenService,
this.platformUtilsService,

View File

@ -1,4 +1,3 @@
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.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 { Utils } from "@bitwarden/common/misc/utils";
import { BrowserEnvironmentService } from "src/services/browser-environment.service";
import { BrowserApi } from "../browser/browserApi";
import { AutofillService } from "../services/abstractions/autofill.service";
import BrowserPlatformUtilsService from "../services/browserPlatformUtils.service";
@ -26,7 +27,7 @@ export default class RuntimeBackground {
private i18nService: I18nService,
private notificationsService: NotificationsService,
private systemService: SystemService,
private environmentService: EnvironmentService,
private environmentService: BrowserEnvironmentService,
private messagingService: MessagingService,
private logService: LogService
) {
@ -227,6 +228,10 @@ export default class RuntimeBackground {
if (this.onInstalledReason != null) {
if (this.onInstalledReason === "install") {
BrowserApi.createNewTab("https://bitwarden.com/browser-start/");
if (await this.environmentService.hasManagedEnvironment()) {
await this.environmentService.setUrlsToManagedEnvironment();
}
}
this.onInstalledReason = null;

View 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" }
}
}
}
}

View File

@ -119,5 +119,8 @@
"default_title": "Bitwarden",
"default_panel": "popup/index.html?uilocation=sidebar",
"default_icon": "images/icon19.png"
},
"storage": {
"managed_schema": "managed_schema.json"
}
}

View File

@ -14,6 +14,17 @@
</div>
</header>
<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">
<h2 class="box-header">
{{ "selfHostedEnvironment" | i18n }}

View File

@ -1,19 +1,22 @@
import { Component } from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
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 { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { BrowserEnvironmentService } from "../../services/browser-environment.service";
@Component({
selector: "app-environment",
templateUrl: "environment.component.html",
})
export class EnvironmentComponent extends BaseEnvironmentComponent {
export class EnvironmentComponent extends BaseEnvironmentComponent implements OnInit {
showEditedManagedSettings = false;
constructor(
platformUtilsService: PlatformUtilsService,
environmentService: EnvironmentService,
public environmentService: BrowserEnvironmentService,
i18nService: I18nService,
private router: Router
) {
@ -21,6 +24,22 @@ export class EnvironmentComponent extends BaseEnvironmentComponent {
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() {
super.saved();
this.router.navigate([""]);

View File

@ -63,6 +63,9 @@
</div>
</div>
</div>
<p class="text-center text-muted" *ngIf="selfHostedDomain">
{{ "loggingInTo" | i18n: selfHostedDomain }}
</p>
<p class="text-center">
<button type="button" routerLink="/hint">{{ "getMasterPasswordHint" | i18n }}</button>
</p>

View File

@ -56,6 +56,7 @@ import MainBackground from "../../background/main.background";
import { BrowserApi } from "../../browser/browserApi";
import { AutofillService } from "../../services/abstractions/autofill.service";
import { StateService as StateServiceAbstraction } from "../../services/abstractions/state.service";
import { BrowserEnvironmentService } from "../../services/browser-environment.service";
import { BrowserFileDownloadService } from "../../services/browserFileDownloadService";
import BrowserMessagingService from "../../services/browserMessaging.service";
import BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service";
@ -172,6 +173,10 @@ function getBgService<T>(service: keyof MainBackground) {
useFactory: getBgService<ConsoleLogService>("logService"),
deps: [],
},
{
provide: BrowserEnvironmentService,
useExisting: EnvironmentService,
},
{
provide: EnvironmentService,
useFactory: getBgService<EnvironmentService>("environmentService"),

View 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,
});
}
}

View File

@ -85,6 +85,7 @@ const plugins = [
manifestVersion == 3
? { from: "./src/manifest.v3.json", to: "manifest.json" }
: "./src/manifest.json",
{ from: "./src/managed_schema.json", to: "managed_schema.json" },
{ from: "./src/_locales", to: "_locales" },
{ from: "./src/images", to: "images" },
{ from: "./src/popup/images", to: "popup/images" },

View File

@ -49,6 +49,10 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
super(environmentService, i18nService, platformUtilsService);
}
get selfHostedDomain() {
return this.environmentService.hasBaseUrl() ? this.environmentService.getWebVaultUrl() : null;
}
async ngOnInit() {
if (this.email == null || this.email === "") {
this.email = await this.stateService.getRememberedEmail();

View File

@ -11,13 +11,13 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
private readonly urlsSubject = new Subject<Urls>();
urls: Observable<Urls> = this.urlsSubject;
private baseUrl: string;
private webVaultUrl: string;
private apiUrl: string;
private identityUrl: string;
private iconsUrl: string;
private notificationsUrl: string;
private eventsUrl: string;
protected baseUrl: string;
protected webVaultUrl: string;
protected apiUrl: string;
protected identityUrl: string;
protected iconsUrl: string;
protected notificationsUrl: string;
protected eventsUrl: string;
private keyConnectorUrl: string;
private scimUrl: string = null;