Skip to main content
Module

x/mandarinets/main-core/mandarine-native/security/authenticationManagerBuilderDefault.ts

Mandarine.TS is a typescript, decorator-driven framework that allows you to create server-side applications. Mandarine.TS provides a range of built-in solutions such as Dependency Injection, Components, ORM and more. Under its umbrella, Mandarine.TS has 4 modules: Core, Data, Security and MVC, these modules will offer you the requirements to build a Mandarine-powered application.
Latest
File
// Copyright 2020-2020 The Mandarine.TS Framework authors. All rights reserved. MIT license.
import { BcryptEncoder } from "../../../security-core/encoders/bcryptEncoder.ts";import { ApplicationContext } from "../../application-context/mandarineApplicationContext.ts";import { MandarineSecurityException } from "../../exceptions/mandarineSecurityException.ts";import type { Mandarine } from "../../Mandarine.ns.ts";import type { ClassType } from "../../utils/utilTypes.ts";
/** * The `AuthenticationManagerBuilder` class is responsible for handling two necessary properties in order for Mandarine built-in auth to work. * `userDetails` & `passwordEncoder` are required. By using such methods, you are able to plug in the implementations that will be used by Mandarine to execute authentication. */export class AuthenticationManagerBuilder implements Mandarine.Security.Auth.AuthenticationManagerBuilder { private _userDetailsServiceType: ClassType | undefined = undefined; private _passwordEncoder: Mandarine.Security.Crypto.PasswordEncoder = new BcryptEncoder();
public userDetailsService(userdetailsServiceType: ClassType): AuthenticationManagerBuilder { if(!userdetailsServiceType) throw new MandarineSecurityException(MandarineSecurityException.INVALID_USER_DETAILS_SERVICE); if(!userdetailsServiceType.prototype.loadUserByUsername) throw new MandarineSecurityException(MandarineSecurityException.USER_DETAILS_SERVICE_INCOMPLETE);
this._userDetailsServiceType = userdetailsServiceType; return this; }
public passwordEncoder(passwordEncoderImpl: Mandarine.Security.Crypto.PasswordEncoder): AuthenticationManagerBuilder { if(!passwordEncoderImpl) throw new Error("A password encoder implementation must not be defined"); this._passwordEncoder = passwordEncoderImpl; return this; }
public getUserDetailsService() { return this._userDetailsServiceType ? ApplicationContext.getInstance().getDIFactory().getDependency(this._userDetailsServiceType) : undefined; }
public getPasswordEncoder(): Mandarine.Security.Crypto.PasswordEncoder { return this._passwordEncoder; }
}