File

src/app/shared/model/about/security-info.model.ts

Description

Contains meta data about the state of security.

Implements

Serializable

Example

Index

Properties
Methods

Methods

Public canAccess
canAccess(appRoles: string[])
Parameters :
Name Type Optional Description
appRoles string[]
Returns : boolean
Public deserialize
deserialize(input: )
Parameters :
Name Type Optional Description
input
Returns : this
Public hasAnyRoleOf
hasAnyRoleOf(rolesToCheckFor: string[])

Perform a check of the passed in collection of roles against the colection of roles of the SecurityInfo object.

Any occurrence of a single role will result in true being returned.

Parameters :
Name Type Optional Description
rolesToCheckFor string[]
Returns : boolean
Public reset
reset()

Set the SecurityInfo object to default values.

Returns : void

Properties

Public isAuthenticated
isAuthenticated:
Default value : false
Public isAuthenticationEnabled
isAuthenticationEnabled:
Default value : true
Public roles
roles: string[]
Type : string[]
Public username
username:
import { Serializable } from '../serialization/serializable.model';
/**
 * Contains meta data about the state of security.
 *
 * @author Gunnar Hillert
 */
export class SecurityInfo implements Serializable<SecurityInfo> {

  public isAuthenticationEnabled = true;
  public isAuthenticated = false;
  public username = '';
  public roles: string[] = [];

  /**
   * Set the SecurityInfo object to default values.
   */
  public reset() {
    this.isAuthenticationEnabled = true;
    this.isAuthenticated = false;
    this.username = '';
    this.roles = [];
  }

  public deserialize(input) {
    this.isAuthenticationEnabled = input.authenticationEnabled,
    this.isAuthenticated = input.authenticated,
    this.username = input.username,
    this.roles = input.roles as string[];
    return this;
  }

  /**
   * Perform a check of the passed in collection of roles
   * against the colection of roles of the SecurityInfo object.
   *
   * Any occurrence of a single role will result in true
   * being returned.
   *
   * @param rolesToCheckFor
   */
  public hasAnyRoleOf(rolesToCheckFor: string[]): boolean {
    if (this.roles && this.roles.length > 0) {
      const foundRole = this.roles.find(securityInfoRole => {
        if (rolesToCheckFor.find(passedInRole => securityInfoRole === passedInRole)) {
          return true;
        } else {
          return false;
        }
      });

      return foundRole ? true : false;
    } else {
      return false;
    }
  }

  public canAccess(appRoles: string[]): boolean {
    let found = false;
    if (!this.isAuthenticationEnabled) {
      found = true;
    } else {
      if (this.isAuthenticated) {
          if (this.hasAnyRoleOf(appRoles)) {
            found = true;
          }
      } else {
        found = false;
      }
    }
    return found;
  }
}

results matching ""

    No results matching ""