* @category Class * @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License * @link www.splendidbear.org * @since 2026. 04. 12. */ #[Table(name: 'app_webauthn_credential')] #[Entity(repositoryClass: WebAuthnCredentialRepository::class)] class WebAuthnCredential { #[Id, GeneratedValue, Column] private ?int $id = null; #[ManyToOne(targetEntity: User::class)] #[JoinColumn(nullable: false, onDelete: 'CASCADE')] private ?User $user = null; #[Column(type: Types::TEXT)] private ?string $credentialData = null; #[Column(length: 255)] private ?string $credentialName = null; #[Column(type: Types::DATETIME_MUTABLE)] private ?DateTime $createdAt = null; #[Column(type: Types::DATETIME_MUTABLE, nullable: true)] private ?DateTime $lastUsedAt = null; #[Column] private bool $isBackupEligible = false; #[Column] private bool $isBackupAuthenticated = false; public function __construct() { $this->createdAt = new DateTime(); } public function getId(): ?int { return $this->id; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): self { $this->user = $user; return $this; } public function getCredentialData(): ?string { return $this->credentialData; } public function setCredentialData(?string $credentialData): self { $this->credentialData = $credentialData; return $this; } public function getCredentialName(): ?string { return $this->credentialName; } public function setCredentialName(?string $credentialName): self { $this->credentialName = $credentialName; return $this; } public function getCreatedAt(): ?DateTime { return $this->createdAt; } public function setCreatedAt(?DateTime $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getLastUsedAt(): ?DateTime { return $this->lastUsedAt; } public function setLastUsedAt(?DateTime $lastUsedAt): self { $this->lastUsedAt = $lastUsedAt; return $this; } public function isBackupEligible(): bool { return $this->isBackupEligible; } public function setBackupEligible(bool $isBackupEligible): self { $this->isBackupEligible = $isBackupEligible; return $this; } public function isBackupAuthenticated(): bool { return $this->isBackupAuthenticated; } public function setBackupAuthenticated(bool $isBackupAuthenticated): self { $this->isBackupAuthenticated = $isBackupAuthenticated; return $this; } public function getPublicKeyCredentialSource() { // Return the raw credential data (JSON decoded) if ($this->credentialData === null) { return null; } return json_decode($this->credentialData, true); } public function setPublicKeyCredentialSource($source): self { // Handle both array and object input if (is_array($source)) { $this->credentialData = json_encode($source); } else { $this->credentialData = (string)$source; } return $this; } }