WebAuthn4j Adapter 設計ガイド
概要
idp-server-webauthn4j-adapter は、WebAuthn/FIDO2 認証機能を提供するアダプターモジュールです。
webauthn4j ライブラリをラップし、idp-server のアーキテクチャに統合します。
このドキュメントでは、WebAuthn4j Adapter の設計思想と実装パターンを解説します。
アーキテクチャ
モジュール構成
┌─────────────────────────────────────────────────────────────────┐
│ idp-server-authentication-interactors │
│ (Fido2*Interactor: ビジネスロジック層) │
├─────────────────────────────────────────────────────────────────┤
│ idp-server-webauthn4j-adapter │
│ (WebAuthn4j*Executor: WebAuthn処理層) │
├─────────────────────────────────────────────────────────────────┤
│ webauthn4j (外部ライブラリ) │
│ (WebAuthnManager: 暗号検証・データパース) │
└─────────────────────────────────────────────────────────────────┘
責務分離
| レイヤー | モジュール | 責務 |
|---|---|---|
| Interactor | idp-server-authentication-interactors | 認証フロー制御、トランザクション管理 |
| Executor | idp-server-webauthn4j-adapter | WebAuthn処理、クレデンシャル管理 |
| Library | webauthn4j | 暗号検証、データ構造パース |
設計原則: ライブラリ依存の分離
// ❌ 悪い例: コアモジュールがwebauthn4jに直接依存
// idp-server-core 内
import com.webauthn4j.WebAuthnManager; // ← NG: 外部ライブラリ依存
// ✅ 良い例: アダプター経由でアクセス
// idp-server-authentication-interactors 内
AuthenticationExecutor executor = executors.get("webauthn4j_authentication");
AuthenticationExecutionResult result = executor.execute(...);
理由:
- webauthn4j ライブラリのバージョンアップに対する影響を局所化
- 将来的に別のWebAuthnライブラリへの差し替えを可能に
- コアモジュールの外部依存を最小化
DDL設計: Core + JSONB パタ ーン
設計思想
WebAuthn仕様は継続的に進化しています(Level 2 → Level 3 → Level 4...)。 新しい仕様が追加されるたびにDDL変更が必要になることを避けるため、Core + JSONB パターンを採用しています。
┌─────────────────────────────────────────────────────────────────┐
│ webauthn_credentials テーブル │
├─────────────────────────────────────────────────────────────────┤
│ 【Core Columns】検索・ポリシー判定に使用 │
│ - id, user_id, rp_id, aaguid │
│ - sign_count, rk, backup_eligible, backup_state │
├─────────────────────────────────────────────────────────────────┤
│ 【JSONB Columns】拡張データ・将来の仕様追加用 │
│ - authenticator: {"transports": [...], "attachment": "..."} │
│ - attestation: {"type": "...", "format": "..."} │
│ - extensions: {"cred_protect": 2, "prf": {...}} │
│ - device: {"name": "...", "registered_ip": "..."} │
│ - metadata: {} (将来の拡張用) │
└─────────────────────────────────────────────────────────────────┘