import { Component, Value, Autowired } from '@malagu/core'; import { SecurityContextStore, SecurityContext, SecurityContextStrategy } from './context-protocol'; import { Context } from '@malagu/web/lib/node'; @Component(SecurityContextStore) export class SessionSecurityContextStore implements SecurityContextStore { @Value('malagu.security') protected readonly options: any; @Autowired(SecurityContextStrategy) protected readonly securityContextStrategy: SecurityContextStrategy; async load(): Promise { const context = Context.getSession()[this.options.contextKey]; if (!context) { return this.securityContextStrategy.create(); } return context; } async save(context: SecurityContext): Promise { Context.getSession()[this.options.contextKey] = context; } }