File

libs/auth/src/lib/basic-auth/basic-auth-service-maintainer.service.ts

Description

This service maintaines all service urls which are secured with basic auth. The service is used to check for every servie url if it is necessary to work with basic auth. It is possible to register a url and it also checks every dataset url in the settings.

Index

Properties
Methods

Constructor

constructor(settingsService: SettingsService)
Parameters :
Name Type Optional
settingsService SettingsService<Settings> No

Methods

Public getCorrespondingService
getCorrespondingService(url: string)

Checks if a given url is registered as secured with basic auth.

Parameters :
Name Type Optional
url string No
Returns : string
Public registerService
registerService(url: string)

Register an additional service url, which is secured with basic auth.

Parameters :
Name Type Optional
url string No
Returns : void

Properties

Private services
Type : string[]
Default value : []
import { Injectable } from '@angular/core';
import { Settings, SettingsService } from '@helgoland/core';

/**
 * This service maintaines all service urls which are secured with basic auth. The service is used to check for every servie url if it is necessary to work with basic auth. It is possible to
 * register a url and it also checks every dataset url in the settings.
 */
@Injectable()
export class BasicAuthServiceMaintainer {

  private services: string[] = [];

  constructor(
    protected settingsService: SettingsService<Settings>
  ) { }

  /**
   * Register an additional service url, which is secured with basic auth.
   */
  public registerService(url: string) {
    if (this.services.indexOf(url) === -1) {
      this.services.push(url);
    }
  }

  /**
   * Checks if a given url is registered as secured with basic auth.
   */
  public getCorrespondingService(url: string): string {
    const matchedUrl = this.services.find(e => url.startsWith(e));
    if (matchedUrl) {
      return matchedUrl;
    }
    const settings = this.settingsService.getSettings();
    if (settings && settings.datasetApis && Array.isArray(settings.datasetApis)) {
      const api = settings.datasetApis.find((e) => url.startsWith(e.url) && e.basicAuth);
      if (api) {
        return api.url;
      }
    }
  }

}

result-matching ""

    No results matching ""