103 lines
2.0 KiB
Java
103 lines
2.0 KiB
Java
/*
|
|
* Ardiansyah | http://ard.web.id
|
|
*
|
|
*/
|
|
package id.web.ard.springbootwebfluxjjwt.entity;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import id.web.ard.springbootwebfluxjjwt.security.model.Role;
|
|
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.stream.Collectors;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.NoArgsConstructor;
|
|
import lombok.ToString;
|
|
|
|
/**
|
|
*
|
|
* @author ardiansyah
|
|
*/
|
|
@ToString @AllArgsConstructor @NoArgsConstructor
|
|
public class User implements UserDetails {
|
|
|
|
private String username;
|
|
|
|
private String password;
|
|
|
|
private Boolean enabled;
|
|
|
|
private List<Role> roles;
|
|
|
|
public User(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
@Override
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
//==============================
|
|
@Override
|
|
public boolean isAccountNonExpired() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonLocked() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isCredentialsNonExpired() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnabled() {
|
|
return this.enabled;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
@Override
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
return this.roles.stream().map(authority -> new SimpleGrantedAuthority(authority.name())).collect(Collectors.toList());
|
|
}
|
|
//==============================
|
|
|
|
@JsonIgnore
|
|
@Override
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
@JsonProperty
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
|
|
public Boolean getEnabled() {
|
|
return enabled;
|
|
}
|
|
|
|
public void setEnabled(Boolean enabled) {
|
|
this.enabled = enabled;
|
|
}
|
|
|
|
public List<Role> getRoles() {
|
|
return roles;
|
|
}
|
|
|
|
public void setRoles(List<Role> roles) {
|
|
this.roles = roles;
|
|
}
|
|
|
|
} |