Package org.localify.auth
Class JwtServiceImpl
java.lang.Object
org.localify.auth.JwtServiceImpl
- All Implemented Interfaces:
JwtService
Implementation of the
JwtService interface.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a signed JWT. -
Constructor Summary
ConstructorsConstructorDescriptionJwtServiceImpl(RefreshTokenRepository refreshTokenRepository, io.jsonwebtoken.JwtParser jwtParser, Key key, LocalifyProperties properties, jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.persistence.EntityManager entityManager) Constructs a new JwtServiceImpl. -
Method Summary
Modifier and TypeMethodDescriptiondecodeAuthStateJwt(String jwt) doRefreshToken(String token) Refreshes a token, invalidating the refresh token.doUserLogin(User user) Logs a user in.io.jsonwebtoken.ClaimsSeeJwtParser.parseClaimsJws(String)for more detailed exception information.static KeygetKeyForToken(String token) Gets the key for a given token.
-
Constructor Details
-
JwtServiceImpl
public JwtServiceImpl(RefreshTokenRepository refreshTokenRepository, io.jsonwebtoken.JwtParser jwtParser, Key key, LocalifyProperties properties, jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.persistence.EntityManager entityManager) Constructs a new JwtServiceImpl.- Parameters:
refreshTokenRepository- The repository for refresh tokens.jwtParser- The JWT parser.key- The signing key.properties- The application properties.servletRequest- The HTTP servlet request.entityManager- The entity manager.
-
-
Method Details
-
getClaims
SeeJwtParser.parseClaimsJws(String)for more detailed exception information.- Specified by:
getClaimsin interfaceJwtService- Parameters:
token- the jwt token- Returns:
- the Claims. Never null.
- Throws:
io.jsonwebtoken.JwtException- if the token is invalid in some way (see link above)IllegalArgumentException- if the token is null/empty/whitespace.
-
doUserLogin
Description copied from interface:JwtServiceLogs a user in. Generates new authentication and refresh credentials.- Specified by:
doUserLoginin interfaceJwtService- Parameters:
user- the user to generate credentials for.- Returns:
- a DTO containing the auth and refresh token.
-
doRefreshToken
Description copied from interface:JwtServiceRefreshes a token, invalidating the refresh token.- Specified by:
doRefreshTokenin interfaceJwtService- Parameters:
token- the refresh token- Returns:
- newly generated auth and refresh token
-
generateAuthStateJwt
- Specified by:
generateAuthStateJwtin interfaceJwtService
-
decodeAuthStateJwt
- Specified by:
decodeAuthStateJwtin interfaceJwtService
-
getKeyForToken
Gets the key for a given token.- Parameters:
token- The token string.- Returns:
- The key.
-