Phase 1: DB 기반 구축 - trigger_audit_logs 테이블 (RANGE 파티셔닝 15개, 3개 인덱스) - 789개 MySQL AFTER 트리거 (263 테이블 × INSERT/UPDATE/DELETE) - SetAuditSessionVariables 미들웨어 (@sam_actor_id, @sam_session_info) Phase 2: 복구 메커니즘 - TriggerAuditLog 모델, TriggerAuditLogService, AuditRollbackService - 6개 API 엔드포인트 (index, show, stats, history, rollback-preview, rollback) - FormRequest 검증 (TriggerAuditLogIndexRequest, TriggerAuditRollbackRequest) Phase 3: 관리 도구 - v_unified_audit VIEW (APP + TRIGGER 통합, COLLATE 처리) - audit:partitions 커맨드 (파티션 추가/삭제, dry-run) - audit:triggers 커맨드 (트리거 재생성, 테이블별/전체) - 월 1회 파티션 자동 관리 스케줄러 등록 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
54 lines
2.3 KiB
PHP
54 lines
2.3 KiB
PHP
<?php
|
|
|
|
use App\Exceptions\Handler;
|
|
use App\Http\Middleware\ApiKeyMiddleware;
|
|
use App\Http\Middleware\ApiRateLimiter;
|
|
use App\Http\Middleware\ApiVersionMiddleware;
|
|
use App\Http\Middleware\CheckPermission;
|
|
use App\Http\Middleware\CheckSwaggerAuth;
|
|
use App\Http\Middleware\CorsMiddleware;
|
|
use App\Http\Middleware\LogApiRequest;
|
|
use App\Http\Middleware\PermMapper;
|
|
use App\Http\Middleware\SetAuditSessionVariables;
|
|
use Illuminate\Contracts\Debug\ExceptionHandler;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
|
|
|
$app = Application::configure(basePath: dirname(__DIR__))
|
|
->withRouting(
|
|
web: __DIR__.'/../routes/web.php',
|
|
api: __DIR__.'/../routes/api.php',
|
|
commands: __DIR__.'/../routes/console.php',
|
|
health: '/up',
|
|
)
|
|
->withMiddleware(function (Middleware $middleware) {
|
|
// 글로벌 미들웨어 (모든 요청에 적용, 순서 중요)
|
|
$middleware->append(CorsMiddleware::class);
|
|
$middleware->append(ApiRateLimiter::class); // 1. Rate Limiting 먼저 체크
|
|
$middleware->append(ApiKeyMiddleware::class); // 2. API Key 검증
|
|
$middleware->append(ApiVersionMiddleware::class); // 3. API 버전 해석 및 폴백
|
|
|
|
// API 미들웨어 그룹에 로깅 + 감사 세션변수 추가
|
|
$middleware->appendToGroup('api', LogApiRequest::class);
|
|
$middleware->appendToGroup('api', SetAuditSessionVariables::class);
|
|
|
|
$middleware->alias([
|
|
'auth.apikey' => ApiKeyMiddleware::class, // 인증: apikey + basic auth (alias 유지)
|
|
'api.version' => ApiVersionMiddleware::class, // API 버전 해석 및 폴백
|
|
'swagger.auth' => CheckSwaggerAuth::class,
|
|
'perm.map' => PermMapper::class, // 전처리: 라우트명 → perm 키 생성/주입
|
|
'permission' => CheckPermission::class, // 검사: perm 키로 접근 허용/차단
|
|
'log.api' => LogApiRequest::class, // API 요청/응답 로깅 (선택적 사용용)
|
|
]);
|
|
})
|
|
->withExceptions(function (Exceptions $exceptions) {
|
|
// 이건 비워두세요
|
|
})
|
|
->create();
|
|
|
|
// 🔥 핵심: create() 이후에 반드시 등록
|
|
$app->singleton(ExceptionHandler::class, Handler::class);
|
|
|
|
return $app;
|