Jwt Role Based Authorization - Spring Security

I am a beginner in Spring Boot and trying to implement Jwt Role Based Authorization. For this, I followed this tutorial


I have been able to understand most of the code but there is this one method that I cant seem to figure out its purpose. The first three lines of code are used for validating the token but what is the purpose of getauthentication method. What is this jwt parser and claims doing?


 public Boolean validateToken(String token, UserDetails userDetails) {
    final String username = getUsernameFromToken(token);
    return (
                && !isTokenExpired(token));

UsernamePasswordAuthenticationToken getAuthentication(final String token, final Authentication 
    existingAuth, final UserDetails userDetails) {

    final JwtParser jwtParser = Jwts.parser().setSigningKey(SIGNING_KEY);

    final Jws<Claims> claimsJws = jwtParser.parseClaimsJws(token);

    final Claims claims = claimsJws.getBody();

    final Collection<? extends GrantedAuthority> authorities =

    return new UsernamePasswordAuthenticationToken(userDetails, "", authorities);

If anyone can explain these lines of code to me step by step It would mean alot. Thanks.