I have a service method which will save user data as session data into the spring data redis. Then this generates JWT with session ID.
Suppose I am calling another microservice which has filter where do validation of the JWT and want to validate the session by fetching session id and checking it valid or not.
How can we do this. following is the method where do filter for JWT.
public class RequestValidationFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
String token = request.getHeader("AUTHORIZATION");
if(!token.isEmpty()){
try {
Claims claims = Jwts.parser()
.setSigningKey("superdupersecretkey")
.parseClaimsJws(token).getBody();
String username = String.valueOf(claims.get("username"));
String authorities = (String) claims.get("authorities");
String sessionId = (String) claims.get("sessionId");
Authentication auth = new UsernamePasswordAuthenticationToken(username,null,
AuthorityUtils.commaSeparatedStringToAuthorityList(authorities));
SecurityContextHolder.getContext().setAuthentication(auth);
}catch (Exception e) {
throw new BadCredentialsException("Invalid Token received!");
}
}
filterChain.doFilter(request, response);
}
}
Is there way to get session object and payload from redis cache?
Thanks.