Package com.espacogeek.geek.config
Class JwtConfig
java.lang.Object
com.espacogeek.geek.config.JwtConfig
JWT configuration and helper methods for token generation and validation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseCookiebuildRefreshTokenCookie(String token, jakarta.servlet.http.HttpServletRequest request) Build the HttpOnlyrefreshTokenSet-Cookie using the request for SameSite/Secure detection.org.springframework.http.ResponseCookiebuildRefreshTokenCookie(String token, String originHeader, URI serverUri) Build the HttpOnlyrefreshTokenSet-Cookie using Origin/server URI for SameSite/Secure detection.org.springframework.http.ResponseCookieclearRefreshTokenCookie(jakarta.servlet.http.HttpServletRequest request) Clear the HttpOnlyrefreshTokencookie.org.springframework.http.ResponseCookieclearRefreshTokenCookie(String originHeader, URI serverUri) Clear the HttpOnlyrefreshTokencookie using Origin/server URI for SameSite/Secure detection.generateAccessToken(UserModel user) Generate a short-lived access token (15 min by default) for the given user.Generate a long-lived refresh token (7 days by default) for the given user.generateToken(UserModel user) Generate a signed JWT access token for the given user.booleanChecks if a token is valid.Get the name of the refresh token HttpOnly cookie.io.jsonwebtoken.ClaimsValidate a token and return its claims if valid.
-
Constructor Details
-
JwtConfig
public JwtConfig()
-
-
Method Details
-
generateAccessToken
Generate a short-lived access token (15 min by default) for the given user. The token carriestype=accessand is intended to be returned in the JSON payload.- Parameters:
user- the authenticated user- Returns:
- compact JWT string
-
generateRefreshToken
Generate a long-lived refresh token (7 days by default) for the given user. The token carriestype=refreshand is stored in the database; it is delivered to the client via an HttpOnly cookie namedrefreshToken.- Parameters:
user- the authenticated user- Returns:
- compact JWT string
-
generateToken
Generate a signed JWT access token for the given user. Delegates togenerateAccessToken(UserModel). Retained for backward compatibility with test code that calls this method directly.- Parameters:
user- the authenticated user- Returns:
- compact JWT string
-
validate
Validate a token and return its claims if valid.- Parameters:
token- JWT string- Returns:
- claims or null if invalid
-
isValid
Checks if a token is valid. -
refreshTokenCookieName
Get the name of the refresh token HttpOnly cookie. -
buildRefreshTokenCookie
public org.springframework.http.ResponseCookie buildRefreshTokenCookie(String token, jakarta.servlet.http.HttpServletRequest request) Build the HttpOnlyrefreshTokenSet-Cookie using the request for SameSite/Secure detection. The cookie is scoped to Path=/ so it is sent to the server on every request, but since only therefreshTokenmutation reads it, it is safe. -
clearRefreshTokenCookie
public org.springframework.http.ResponseCookie clearRefreshTokenCookie(jakarta.servlet.http.HttpServletRequest request) Clear the HttpOnlyrefreshTokencookie. -
buildRefreshTokenCookie
public org.springframework.http.ResponseCookie buildRefreshTokenCookie(String token, String originHeader, URI serverUri) Build the HttpOnlyrefreshTokenSet-Cookie using Origin/server URI for SameSite/Secure detection. Used byGraphQlCookieInterceptorwhich has access to theWebGraphQlRequestheaders and URI but not to the rawHttpServletRequest. -
clearRefreshTokenCookie
public org.springframework.http.ResponseCookie clearRefreshTokenCookie(String originHeader, URI serverUri) Clear the HttpOnlyrefreshTokencookie using Origin/server URI for SameSite/Secure detection.
-