content: package io.zhc1.realworld.config;
  
  import java.util.Collection;
  
  import org.springframework.core.convert.converter.Converter;
  import org.springframework.lang.NonNull;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.oauth2.jwt.Jwt;
  import org.springframework.security.oauth2.jwt.JwtClaimNames;
  import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
  import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
  
  class AuthTokenConverter implements Converter<Jwt, AuthToken> {
      private final Converter<Jwt, Collection<GrantedAuthority>> jwtGrantedAuthoritiesConverter =
              new JwtGrantedAuthoritiesConverter();
  
      @Override
      public final AuthToken convert(@NonNull Jwt jwt) {
          Collection<GrantedAuthority> authorities = this.jwtGrantedAuthoritiesConverter.convert(jwt);
          String principalClaimValue = jwt.getClaimAsString(JwtClaimNames.SUB);
          return new AuthToken(jwt, new JwtAuthenticationToken(jwt, authorities, principalClaimValue));
      }
  }
  