nis2-agile/application/config/config.php
DevEnv nis2-agile 6933e1d3fb [INTEG] Provisioning B2B automatico + fix JWT helpers
- POST /api/services/provision: onboarding automatico tenant da lg231
  - X-Provision-Secret auth (master secret, non org-specific)
  - Crea org (con tutti i dati lg231: P.IVA, ATECO, sede, PEC, fatturato)
  - Crea admin user con password temporanea (must_change_password=1)
  - Genera API Key scope [read:all, write:all, admin:org, sso:login]
  - Emette JWT 2h per apertura immediata UI
  - Callback webhook a lg231 con api_key
  - Idempotent: stessa P.IVA → restituisce org esistente
  - Audit: org.provisioned severity=critical
- config.php: PROVISION_SECRET (env var)
- BaseController: base64UrlEncode/Decode da private → protected
- Migration 011: colonne provisioning + must_change_password + indexes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 15:02:11 +01:00

89 lines
6.6 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],
]);
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));
// ═══════════════════════════════════════════════════════════════════════════
// TIMEZONE
// ═══════════════════════════════════════════════════════════════════════════
date_default_timezone_set('Europe/Rome');