nis2-agile/application/config/config.php
DevEnv nis2-agile e4f9e9179e [FEAT] Allineamento NIS2 ↔ TRPG (Fasi 1-5): SSO + Sessions + Reset + Impersonate + Branding
Implementazione completa del progetto allineamento alla suite Evix (TRPG/lg231),
basato sul doc canonico docs/GAP_TRPG_NIS2_ALIGNMENT.md (5 fasi, 18 gap).

Version 1.0.0 → 1.5.0

Fase 1 — SSO Federation (v1.1.0)
- Migration 015_sso_columns: users.sso_identity_id + password_version
- application/services/SsoHelper.php (client SSO dual-mode, cURL nativo, zero deps)
- AuthController::login() + changePassword() conditional SSO (SSO_MODE=local default)

Fase 2 — Multi-device Sessions (v1.2.0)
- Migration 016_active_sessions: tabella + refresh_tokens.session_jti
- BaseController::requireAuth() verifica jti + last_activity throttle + parseDeviceLabel
- login() genera jti, logout/changePassword revoca selettiva
- GET/DELETE /auth/sessions[/{id}]
- UI settings.html tab Sicurezza con lista device + revoca

Fase 3 — Password Reset + Tenant Switcher (v1.3.0)
- Migration 017_password_reset_tokens (TTL 30min, single-use)
- POST /auth/forgot-password (risposta opaca) + reset-password
- Pagine forgot-password.html + reset-password.html (con strength bar)
- EmailService::sendPasswordReset
- POST /auth/switchContext con rotazione JWT + organization_id claim
- Dropdown tenant in sidebar esposto a tutti gli utenti con ≥2 org

Fase 4 — Impersonate + Preferences + Versioning UI (v1.4.0)
- POST /auth/impersonate (super_admin o consulente stesso firm, TTL 1h, audit)
- Migration 018_user_preferences: users.theme/timezone/notif_email/notif_inapp
- GET/PUT /auth/preferences
- Sidebar footer mostra versione + changelog modal su click

Fase 5 — Branding white-label + Auth-gate (v1.5.0)
- Migration 019_firm_branding (logo/colori/brand_name per consulting firm)
- BrandingController GET /branding/current (auth opzionale) + PUT
- common.js auto-applica CSS variables al boot
- public/js/auth-gate.js (gate password client-side per docs riservati, da TRPG)

Skip motivati:
- G15 demo login: simulator esistenti coprono
- G18 refactor controllers: rinviato (~5gg, valore tecnico solo)

Cron sync SSO: AgileHub Ticket #220 aperto a team AGILEHUB per estendere
sso-password-sync.sh al DB nis2_agile_db. Prerequisito per switch SSO_MODE=dual.

Backup files: tutti i file modificati hanno .bak.pre-{fase}-{ts} sia in DEV
sia in /var/www/nis2-agile/.backups/ su Hetzner (rollback ready).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 13:18:35 +02:00

109 lines
8.4 KiB
PHP

<?php
/**
* NIS2 Agile - Configurazione Principale
*/
require_once __DIR__ . '/env.php';
// ═══════════════════════════════════════════════════════════════════════════
// APPLICAZIONE
// ═══════════════════════════════════════════════════════════════════════════
define('APP_ENV', Env::get('APP_ENV', 'development'));
define('APP_DEBUG', APP_ENV === 'development');
define('APP_NAME', Env::get('APP_NAME', 'NIS2 Agile'));
define('APP_VERSION', Env::get('APP_VERSION', '1.0.0'));
define('APP_URL', Env::get('APP_URL', 'http://localhost:8080'));
// ═══════════════════════════════════════════════════════════════════════════
// PERCORSI
// ═══════════════════════════════════════════════════════════════════════════
define('BASE_PATH', dirname(dirname(__DIR__)));
define('APP_PATH', BASE_PATH . '/application');
define('PUBLIC_PATH', BASE_PATH . '/public');
define('UPLOAD_PATH', PUBLIC_PATH . '/uploads');
define('DATA_PATH', APP_PATH . '/data');
// ═══════════════════════════════════════════════════════════════════════════
// AUTENTICAZIONE JWT
// ═══════════════════════════════════════════════════════════════════════════
define('JWT_SECRET', APP_ENV === 'production'
? Env::getRequired('JWT_SECRET')
: Env::get('JWT_SECRET', 'nis2_dev_jwt_secret'));
define('JWT_ALGORITHM', 'HS256');
define('JWT_EXPIRES_IN', Env::int('JWT_EXPIRES_IN', 7200));
define('JWT_REFRESH_EXPIRES_IN', Env::int('JWT_REFRESH_EXPIRES_IN', 604800));
// ═══════════════════════════════════════════════════════════════════════════
// PROVISIONING (B2B — lg231 e altri sistemi Agile)
// ═══════════════════════════════════════════════════════════════════════════
// Secret master per provisioning automatico da sistemi Agile partner.
// lg231 lo usa per POST /api/services/provision (onboarding automatico tenant).
define('PROVISION_SECRET', Env::get('PROVISION_SECRET', 'nis2_prov_dev_secret'));
// ═══════════════════════════════════════════════════════════════════════════
// PASSWORD POLICY
// ═══════════════════════════════════════════════════════════════════════════
define('PASSWORD_MIN_LENGTH', Env::int('PASSWORD_MIN_LENGTH', 8));
define('PASSWORD_REQUIRE_UPPERCASE', Env::bool('PASSWORD_REQUIRE_UPPERCASE', true));
define('PASSWORD_REQUIRE_NUMBER', Env::bool('PASSWORD_REQUIRE_NUMBER', true));
define('PASSWORD_REQUIRE_SPECIAL', Env::bool('PASSWORD_REQUIRE_SPECIAL', true));
// ═══════════════════════════════════════════════════════════════════════════
// CORS
// ═══════════════════════════════════════════════════════════════════════════
define('CORS_ALLOWED_ORIGINS', array_filter([
APP_URL,
APP_ENV !== 'production' ? 'http://localhost:8080' : null,
APP_ENV !== 'production' ? 'http://localhost:3000' : null,
]));
define('CORS_ALLOWED_METHODS', 'GET, POST, PUT, DELETE, OPTIONS');
define('CORS_ALLOWED_HEADERS', 'Content-Type, Authorization, X-Organization-Id, X-Requested-With');
define('CORS_MAX_AGE', '86400');
// ═══════════════════════════════════════════════════════════════════════════
// RATE LIMITING
// ═══════════════════════════════════════════════════════════════════════════
define('RATE_LIMIT_AUTH_LOGIN', [
['max' => 5, 'window_seconds' => 60],
['max' => 20, 'window_seconds' => 3600],
]);
define('RATE_LIMIT_AUTH_REGISTER', [
['max' => 3, 'window_seconds' => 600],
]);
// Password reset (Fase 3 / G08): 3 richieste/h per IP+email
define('RATE_LIMIT_AUTH_FORGOT', [
['max' => 3, 'window_seconds' => 3600],
]);
// TTL token reset password (decisione utente §10.4: 30 min)
define('PASSWORD_RESET_TTL_SECONDS', 1800);
define('RATE_LIMIT_AI', [
['max' => 10, 'window_seconds' => 60],
['max' => 100, 'window_seconds' => 3600],
]);
// ═══════════════════════════════════════════════════════════════════════════
// AI (ANTHROPIC)
// ═══════════════════════════════════════════════════════════════════════════
define('ANTHROPIC_API_KEY', Env::get('ANTHROPIC_API_KEY', ''));
define('ANTHROPIC_MODEL', Env::get('ANTHROPIC_MODEL', 'claude-sonnet-4-5-20250929'));
define('ANTHROPIC_MAX_TOKENS', Env::int('ANTHROPIC_MAX_TOKENS', 4096));
// ═══════════════════════════════════════════════════════════════════════════
// CERTISOURCE (atti-service.php)
// ═══════════════════════════════════════════════════════════════════════════
define('CERTISOURCE_API_URL', Env::get('CERTISOURCE_API_URL', 'https://certisource.it/atti-service.php'));
define('CERTISOURCE_API_KEY', Env::get('CERTISOURCE_API_KEY', '')); // cs_pat_...
define('CERTISOURCE_POLL_MAX', Env::int('CERTISOURCE_POLL_MAX', 30)); // max tentativi polling
define('CERTISOURCE_POLL_SEC', Env::int('CERTISOURCE_POLL_SEC', 3)); // secondi tra poll
// ═══════════════════════════════════════════════════════════════════════════
// FEEDBACK & SEGNALAZIONI
// ═══════════════════════════════════════════════════════════════════════════
define('FEEDBACK_RESOLVE_PASSWORD', Env::get('FEEDBACK_RESOLVE_PASSWORD', ''));
define('FEEDBACK_WORKER_LOG', Env::get('FEEDBACK_WORKER_LOG', '/var/log/nis2/feedback-worker.log'));
// ═══════════════════════════════════════════════════════════════════════════
// TIMEZONE
// ═══════════════════════════════════════════════════════════════════════════
date_default_timezone_set('Europe/Rome');