content: package com.codeages.termiusplus.security;
  
  import com.codeages.termiusplus.biz.user.dto.UserAuthedDto;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import lombok.Getter;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.SimpleGrantedAuthority;
  import org.springframework.security.core.userdetails.UserDetails;
  
  import java.util.Collection;
  import java.util.List;
  import java.util.Objects;
  import java.util.stream.Collectors;
  
  public class AuthUser implements UserDetails {
  
      private static final long serialVersionUID = 1L;
  
      private Long id;
  
      private String username;
  
      @JsonIgnore
      private String password;
  
      private Collection<? extends GrantedAuthority> authorities;
  
      private String ip;
  
      @Getter
      private List<Long> roleIds;
  
      public AuthUser(UserAuthedDto userAuthed) {
          id = userAuthed.getId();
          username = userAuthed.getUsername();
          password = userAuthed.getPassword();
          authorities = userAuthed.getRoles().stream()
                  .map(SimpleGrantedAuthority::new)
                  .collect(Collectors.toList());
          roleIds = userAuthed.getRoleIds();
      }
  
      public Long getId() {
          return id;
      }
  
      @Override
      public Collection<? extends GrantedAuthority> getAuthorities() {
          return authorities;
      }
  
      @Override
      public String getPassword() {
          return password;
      }
  
      @Override
      public String getUsername() {
          return username;
      }
  
      @Override
      public boolean isAccountNonExpired() {
          return true;
      }
  
      @Override
      public boolean isAccountNonLocked() {
          return true;
      }
  
      @Override
      public boolean isCredentialsNonExpired() {
          return true;
      }
  
      @Override
      public boolean isEnabled() {
          return true;
      }
  
      @Override
      public boolean equals(Object o) {
          if (this == o)
              return true;
          if (o == null || getClass() != o.getClass())
              return false;
          AuthUser user = (AuthUser) o;
          return Objects.equals(id, user.id);
      }
  
      public String getIp() {
          return ip;
      }
  
      public void setIp(String ip) {
          this.ip = ip;
      }
  }
  