Api related to logout,reset and change password in user api controller
This commit is contained in:
@@ -48,6 +48,7 @@ public class TokenProvider {
|
||||
|
||||
public static final String INVALID_USER = "invalid_user";
|
||||
static final String AUTH_SECRET = "X-Api-Secret";
|
||||
private final Set<String> invalidatedTokens = new HashSet<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
@@ -113,6 +114,10 @@ public class TokenProvider {
|
||||
|
||||
public boolean validateToken(String authToken) {
|
||||
try {
|
||||
if (isTokenInvalid(authToken)) {
|
||||
log.warn("Token is invalidated.");
|
||||
return false;
|
||||
}
|
||||
Jwts.parserBuilder()
|
||||
.setSigningKey(key)
|
||||
.build()
|
||||
@@ -124,6 +129,15 @@ public class TokenProvider {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void invalidateToken(String token) {
|
||||
invalidatedTokens.add(token);
|
||||
log.info("Token invalidated: {}", token);
|
||||
}
|
||||
|
||||
public boolean isTokenInvalid(String token) {
|
||||
return invalidatedTokens.contains(token);
|
||||
}
|
||||
public Map<String, Object> getUserInfoAndUserIdFromToken(HttpServletRequest request) {
|
||||
Map<String, Object> userInfo = new HashMap<>();
|
||||
String authSecretHeader=request.getHeader(AUTH_SECRET);
|
||||
@@ -196,4 +210,12 @@ public class TokenProvider {
|
||||
Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
|
||||
return claims.getSubject();
|
||||
}
|
||||
public String extractTokenFromRequest(HttpServletRequest request) {
|
||||
String bearerToken = request.getHeader("Authorization");
|
||||
if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
|
||||
return bearerToken.substring(7); // Remove "Bearer " prefix
|
||||
}
|
||||
return null; // Return null if token is not found or not in Bearer format
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user