|
|
|
|
@ -1,74 +1,46 @@
|
|
|
|
|
package kr.re.etri.autoflow.security.services;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
|
|
import kr.re.etri.autoflow.models.User;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.Builder;
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
|
|
|
|
|
|
import kr.re.etri.autoflow.models.User;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
|
@Builder
|
|
|
|
|
public class UserDetailsImpl implements UserDetails {
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
private Long id;
|
|
|
|
|
|
|
|
|
|
private String username;
|
|
|
|
|
|
|
|
|
|
private String email;
|
|
|
|
|
private final Long id;
|
|
|
|
|
private final String username;
|
|
|
|
|
private final String email;
|
|
|
|
|
|
|
|
|
|
@JsonIgnore
|
|
|
|
|
private String password;
|
|
|
|
|
private final String password;
|
|
|
|
|
|
|
|
|
|
private Collection<? extends GrantedAuthority> authorities;
|
|
|
|
|
|
|
|
|
|
public UserDetailsImpl(Long id, String username, String email, String password,
|
|
|
|
|
Collection<? extends GrantedAuthority> authorities) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
this.username = username;
|
|
|
|
|
this.email = email;
|
|
|
|
|
this.password = password;
|
|
|
|
|
this.authorities = authorities;
|
|
|
|
|
}
|
|
|
|
|
private final Collection<? extends GrantedAuthority> authorities;
|
|
|
|
|
|
|
|
|
|
public static UserDetailsImpl build(User user) {
|
|
|
|
|
List<GrantedAuthority> authorities = user.getRoles().stream()
|
|
|
|
|
.map(role -> new SimpleGrantedAuthority(role.getName().name()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
return new UserDetailsImpl(
|
|
|
|
|
user.getId(),
|
|
|
|
|
user.getUsername(),
|
|
|
|
|
user.getEmail(),
|
|
|
|
|
user.getPassword(),
|
|
|
|
|
authorities);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
|
|
|
return authorities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Long getId() {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getEmail() {
|
|
|
|
|
return email;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getPassword() {
|
|
|
|
|
return password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getUsername() {
|
|
|
|
|
return username;
|
|
|
|
|
.map(role -> new SimpleGrantedAuthority(role.getName().name()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
return UserDetailsImpl.builder()
|
|
|
|
|
.id(user.getId())
|
|
|
|
|
.username(user.getUsername())
|
|
|
|
|
.email(user.getEmail())
|
|
|
|
|
.password(user.getPassword())
|
|
|
|
|
.authorities(authorities)
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ -93,11 +65,13 @@ public class UserDetailsImpl implements UserDetails {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
|
if (this == o)
|
|
|
|
|
return true;
|
|
|
|
|
if (o == null || getClass() != o.getClass())
|
|
|
|
|
return false;
|
|
|
|
|
UserDetailsImpl user = (UserDetailsImpl) o;
|
|
|
|
|
return Objects.equals(id, user.id);
|
|
|
|
|
if (this == o) return true;
|
|
|
|
|
if (!(o instanceof UserDetailsImpl that)) return false;
|
|
|
|
|
return Objects.equals(id, that.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int hashCode() {
|
|
|
|
|
return Objects.hash(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|