RefreshToken.java
package com.rbctcsworld.ecommerce.auth;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
/** One issued refresh token (only its SHA-256 hash). Tokens of one login share a family id. */
@Entity
@Table(name = "refresh_tokens")
public class RefreshToken {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "token_hash", nullable = false, unique = true, length = 64)
private String tokenHash;
@Column(name = "family_id", nullable = false, length = 36)
private String familyId;
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;
@Column(name = "expires_at", nullable = false)
private LocalDateTime expiresAt;
@Column(name = "revoked_at")
private LocalDateTime revokedAt;
protected RefreshToken() {
}
public RefreshToken(Long userId, String tokenHash, String familyId, LocalDateTime createdAt, LocalDateTime expiresAt) {
this.userId = userId;
this.tokenHash = tokenHash;
this.familyId = familyId;
this.createdAt = createdAt;
this.expiresAt = expiresAt;
}
public Long getId() { return id; }
public Long getUserId() { return userId; }
public String getTokenHash() { return tokenHash; }
public String getFamilyId() { return familyId; }
public LocalDateTime getCreatedAt() { return createdAt; }
public LocalDateTime getExpiresAt() { return expiresAt; }
public LocalDateTime getRevokedAt() { return revokedAt; }
}