-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSecurityUserDetails.java
More file actions
93 lines (79 loc) · 2.53 KB
/
SecurityUserDetails.java
File metadata and controls
93 lines (79 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package clap.server.adapter.inbound.security.service;
import clap.server.adapter.outbound.persistense.entity.member.MemberEntity;
import clap.server.adapter.outbound.persistense.entity.member.constant.MemberStatus;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.io.Serial;
import java.util.Collection;
import java.util.List;
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SecurityUserDetails implements UserDetails {
@Serial
private static final long serialVersionUID = 1L;
private Long userId;
private String username;
private Collection<? extends GrantedAuthority> authorities;
private boolean accountNonLocked;
@JsonIgnore
private boolean enabled;
@JsonIgnore
private String password;
@JsonIgnore
private boolean credentialsNonExpired;
@JsonIgnore
private boolean accountNonExpired;
@Builder
public SecurityUserDetails(
Long userId,
String username,
Collection<? extends GrantedAuthority> authorities,
boolean accountNonLocked
) {
this.userId = userId;
this.username = username;
this.authorities = authorities;
this.accountNonLocked = accountNonLocked;
}
public static UserDetails from(MemberEntity member) {
return SecurityUserDetails.builder()
.userId(member.getMemberId())
.username(member.getName())
.authorities(List.of(new CustomGrantedAuthority(member.getRole().name())))
.accountNonLocked(member.getStatus()==MemberStatus.ACTIVE)
.build();
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return authorities;
}
@Override
public String getPassword() {
return null;
}
@Override
public String getUsername() {
return username;
}
@Override
public boolean isAccountNonExpired() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAccountNonLocked() {
return accountNonLocked;
}
@Override
public boolean isCredentialsNonExpired() {
throw new UnsupportedOperationException();
}
@Override
public boolean isEnabled() {
throw new UnsupportedOperationException();
}
}