content: package co.airy.spring.auth.token;
  
  import lombok.Data;
  import org.springframework.security.core.Authentication;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  
  import java.util.Collection;
  import java.util.stream.Collectors;
  
  @Data
  public class TokenAuth implements Authentication {
      private final TokenProfile profile;
      private boolean isAuthenticated = false;
  
      public TokenAuth(TokenProfile profile) {
          this.profile = profile;
      }
  
      @Override
      public Collection<? extends GrantedAuthority> getAuthorities() {
          return profile.getRoles().stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());
      }
  
      @Override
      public Object getCredentials() {
          return null;
      }
  
      @Override
      public Object getDetails() {
          return null;
      }
  
      @Override
      public TokenProfile getPrincipal() {
          return profile;
      }
  
      @Override
      public boolean isAuthenticated() {
          return this.isAuthenticated;
      }
  
      @Override
      public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
          this.isAuthenticated = true;
      }
  
      @Override
      public String getName() {
          return profile.getName();
      }
  }
  