Class JWTServiceImpl
java.lang.Object
com.example.blogs.app.api.auth.service.JWTServiceImpl
- All Implemented Interfaces:
JWTService
Delegates to JWTHelper with application-configured expiration durations for access and refresh tokens.
-
Constructor Summary
ConstructorsConstructorDescriptionJWTServiceImpl(JWTHelper jwtHelper, Duration accessTokenExpiration, Duration refreshTokenExpiration) Constructs a JWTServiceImpl with configured dependencies and token expiration durations. -
Method Summary
Modifier and TypeMethodDescriptiongenerateAccessToken(String subject) Generates an access token with short-lived expiration.generateAccessToken(String subject, Map<String, Object> claims) Generates an access token with short-lived expiration.generateRefreshToken(String subject) Generates a refresh token with extended expiration.generateRefreshToken(String subject, Map<String, Object> claims) Generates a refresh token with extended expiration.parseClaims(String token) Parses and extracts claims from a JWT token.
-
Constructor Details
-
JWTServiceImpl
public JWTServiceImpl(JWTHelper jwtHelper, @Value("${jwt.access-token-expiration}") Duration accessTokenExpiration, @Value("${jwt.refresh-token-expiration}") Duration refreshTokenExpiration) Constructs a JWTServiceImpl with configured dependencies and token expiration durations.- Parameters:
jwtHelper- helper for generating JWT tokensaccessTokenExpiration- duration for access token validityrefreshTokenExpiration- duration for refresh token validity
-
-
Method Details
-
generateAccessToken
Generates an access token with short-lived expiration.- Specified by:
generateAccessTokenin interfaceJWTService- Parameters:
subject- the subject of the tokenclaims- additional claims to include in the token- Returns:
- signed JWT access token
-
generateRefreshToken
Generates a refresh token with extended expiration.- Specified by:
generateRefreshTokenin interfaceJWTService- Parameters:
subject- the subject of the token- Returns:
- signed JWT refresh token
-
generateRefreshToken
Generates a refresh token with extended expiration.- Specified by:
generateRefreshTokenin interfaceJWTService- Parameters:
subject- the subject of the tokenclaims- additional claims to include in the token- Returns:
- signed JWT access token
-
generateAccessToken
Generates an access token with short-lived expiration.- Specified by:
generateAccessTokenin interfaceJWTService- Parameters:
subject- the subject of the token- Returns:
- signed JWT access token
-
parseClaims
Parses and extracts claims from a JWT token.- Specified by:
parseClaimsin interfaceJWTService- Parameters:
token- the JWT token to parse- Returns:
- map of claims from the token payload
- Throws:
UnauthorizedException- if token is malformed or signature is invalid
-