// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved. // Node module: @loopback/example-access-control-migration // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT import {AuthenticationComponent} from '@loopback/authentication'; import {AuthorizationComponent} from '@loopback/authorization'; import {BootMixin} from '@loopback/boot'; import {ApplicationConfig, BindingKey} from '@loopback/core'; import {RepositoryMixin} from '@loopback/repository'; import {RestApplication} from '@loopback/rest'; import {RestExplorerComponent} from '@loopback/rest-explorer'; import {ServiceMixin} from '@loopback/service-proxy'; import path from 'path'; import {CasbinAuthorizationComponent} from './components/casbin-authorization'; import { JWTAuthenticationComponent, SECURITY_SCHEME_SPEC, } from '@loopback/authentication-jwt'; import {MySequence} from './sequence'; export {ApplicationConfig}; /** * Information from package.json */ export interface PackageInfo { name: string; version: string; description: string; } export const PackageKey = BindingKey.create('application.package'); export class AccessControlApplication extends BootMixin( ServiceMixin(RepositoryMixin(RestApplication)), ) { constructor(options: ApplicationConfig = {}) { super(options); // Set up the custom sequence this.sequence(MySequence); // Set up default home page this.static('/', path.join(__dirname, '../public')); this.addSecuritySpec(); this.component(RestExplorerComponent); // Bind authentication and authorization related elements this.component(AuthenticationComponent); this.component(AuthorizationComponent); this.component(JWTAuthenticationComponent); this.component(CasbinAuthorizationComponent); this.projectRoot = __dirname; // Customize @loopback/boot Booter Conventions here this.bootOptions = { controllers: { // Customize ControllerBooter Conventions here dirs: ['controllers'], extensions: ['.controller.js'], nested: true, }, }; } addSecuritySpec(): void { this.api({ openapi: '3.0.0', info: { title: 'access-control-example', version: require('.././package.json').version, }, paths: {}, components: {securitySchemes: SECURITY_SCHEME_SPEC}, security: [ { jwt: [], }, ], servers: [{url: '/'}], }); } }