content: package com.domaindns.auth.service;
  
  import io.jsonwebtoken.*;
  import io.jsonwebtoken.security.Keys;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.stereotype.Service;
  
  import javax.crypto.SecretKey;
  import java.nio.charset.StandardCharsets;
  import java.util.Date;
  import java.util.UUID;
  
  @Service
  public class JwtService {
      @Value("${jwt.secret}")
      private String secret;
      @Value("${jwt.issuer}")
      private String issuer;
      @Value("${jwt.expire-minutes}")
      private long expireMinutes;
  
      private SecretKey key() {
          return Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
      }
  
      public String issueToken(String subject, String role) {
          long now = System.currentTimeMillis();
          Date exp = new Date(now + expireMinutes * 60_000);
          return Jwts.builder()
                  .setIssuer(issuer)
                  .setId(UUID.randomUUID().toString())
                  .setSubject(subject)
                  .claim("role", role)
                  .setIssuedAt(new Date(now))
                  .setExpiration(exp)
                  .signWith(key(), SignatureAlgorithm.HS256)
                  .compact();
      }
  
      public Jws<Claims> parse(String token) {
          return Jwts.parserBuilder().setSigningKey(key()).build().parseClaimsJws(token);
      }
  }
  