web-vuln-scanner
Version:
Advanced, lightweight web vulnerability scanner with smart detection and easy-to-use interface
115 lines (101 loc) • 2.66 kB
JavaScript
/**
* Authentication Module Entry Point
* Enterprise-grade authentication and authorization system
*/
const { JWTManager } = require('./jwt-manager');
const { RBACManager, PERMISSIONS, DEFAULT_ROLES } = require('./rbac-manager');
const { APIKeyManager } = require('./apikey-manager');
const { AuthMiddleware } = require('./auth-middleware');
const { UserService } = require('./user-service');
const { AuthRouter } = require('./auth-router');
/**
* Authentication System Factory
* Creates and configures the complete authentication system
*/
class AuthenticationSystem {
constructor(config) {
this.config = config;
this.jwtManager = null;
this.rbacManager = null;
this.apiKeyManager = null;
this.middleware = null;
this.userService = null;
this.router = null;
this.initialized = false;
}
/**
* Initialize the authentication system
*/
async initialize() {
try {
if (this.initialized) {
return this;
}
// Initialize components with config
this.jwtManager = new JWTManager(this.config);
this.rbacManager = new RBACManager();
this.apiKeyManager = new APIKeyManager(this.config);
this.userService = new UserService(this.config);
// Initialize middleware and router (they handle their own dependencies)
this.middleware = new AuthMiddleware();
this.router = new AuthRouter();
this.initialized = true;
return this;
} catch (error) {
throw new Error(`Failed to initialize authentication system: ${error.message}`);
}
}
/**
* Get all components
*/
getComponents() {
return {
jwtManager: this.jwtManager,
rbacManager: this.rbacManager,
apiKeyManager: this.apiKeyManager,
middleware: this.middleware,
userService: this.userService,
router: this.router
};
}
/**
* Get authentication middleware for Express
*/
getMiddleware() {
return this.middleware;
}
/**
* Get authentication router for Express
*/
getRouter() {
return this.router;
}
/**
* Get total user count (mock implementation)
*/
async getTotalUserCount() {
// Mock implementation - replace with actual database query
return 1;
}
/**
* Get active user count (mock implementation)
*/
async getActiveUserCount() {
// Mock implementation - replace with actual database query
return 1;
}
}
module.exports = {
// Main system
AuthenticationSystem,
// Individual components
JWTManager,
RBACManager,
APIKeyManager,
AuthMiddleware,
UserService,
AuthRouter,
// Constants
PERMISSIONS,
DEFAULT_ROLES
};