Package com.mindstore.backend.service
Class JwtService
java.lang.Object
com.mindstore.backend.service.JwtService
service class for jwt token
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TextractClaim(String token, Function<io.jsonwebtoken.Claims, T> claimsResolver) function: extract claim from tokenextractExpiration(String token) function: returns expiration from tokenextractUsername(String token) function: get the username, used in the jwtAuthenticationFiltergenerateToken(Map<String, Object> extraClaims, org.springframework.security.core.userdetails.UserDetails userDetails) function: generate tokengenerateToken(Map<String, Object> extraClaims, org.springframework.security.core.userdetails.UserDetails userDetails, Long expiration) function: generate tokengenerateToken(org.springframework.security.core.userdetails.UserDetails userDetails) function: generates tokenlongfunction: used for the /auth/check controller methodbooleanisTokenValid(String token, org.springframework.security.core.userdetails.UserDetails userDetails) function: check token validity
-
Constructor Details
-
JwtService
public JwtService()Default constructor.
-
-
Method Details
-
extractUsername
function: get the username, used in the jwtAuthenticationFilter- Parameters:
token- in string format- Returns:
- the claim (info about the jwt token)
-
extractClaim
function: extract claim from token- Type Parameters:
T- type of claim- Parameters:
token- the JWT token that we extract the claim fromclaimsResolver- - a function that resolves the claim- Returns:
- the extracted claim
-
generateToken
function: generates token- Parameters:
userDetails- details to include in the token- Returns:
- the generated token
-
generateToken
public String generateToken(Map<String, Object> extraClaims, org.springframework.security.core.userdetails.UserDetails userDetails) function: generate token- Parameters:
extraClaims- additional claims to includeuserDetails- - the userDetails for the token- Returns:
- the generated token
-
generateToken
public String generateToken(Map<String, Object> extraClaims, org.springframework.security.core.userdetails.UserDetails userDetails, Long expiration) function: generate token- Parameters:
extraClaims- additional claims to includeuserDetails- the userDetails for the tokenexpiration- expiration time in miliseconds- Returns:
- the generated token
-
getExpirationTime
public long getExpirationTime()function: used for the /auth/check controller method- Returns:
- the remaining time until expiration
-
isTokenValid
public boolean isTokenValid(String token, org.springframework.security.core.userdetails.UserDetails userDetails) function: check token validity- Parameters:
token- - the token that needs validationuserDetails- the userDetails that we expect the token to have- Returns:
- true if the token is valid and not expired --> else false
-
extractExpiration
function: returns expiration from token- Parameters:
token- the token we are checking- Returns:
- the expiration date
-