-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomUserDetails.java
More file actions
65 lines (53 loc) · 1.93 KB
/
CustomUserDetails.java
File metadata and controls
65 lines (53 loc) · 1.93 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
package com.podzilla.auth.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Set;
import java.util.UUID;
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder
@Getter
@NoArgsConstructor(force = true)
@AllArgsConstructor
public class CustomUserDetails implements UserDetails {
private String username;
private UUID id;
@JsonIgnore
private String password;
@JsonDeserialize(contentAs = CustomGrantedAuthority.class)
private Set<GrantedAuthority> authorities;
private final boolean accountNonExpired;
private final boolean accountNonLocked;
private final boolean credentialsNonExpired;
private final boolean enabled;
public void eraseCredentials() {
this.password = null;
}
public int hashCode() {
return this.username.hashCode();
}
public boolean equals(final Object obj) {
if (obj instanceof CustomUserDetails) {
return this.username
.equals(((CustomUserDetails) obj).getUsername());
} else {
return false;
}
}
public String toString() {
return this.getClass().getName() + " ["
+ "Username=" + this.username + ", "
+ "Password=[PROTECTED], "
+ "Enabled=" + this.enabled + ", "
+ "AccountNonExpired=" + this.accountNonExpired + ", "
+ "CredentialsNonExpired=" + this.credentialsNonExpired + ", "
+ "AccountNonLocked=" + this.accountNonLocked + ", "
+ "Granted Authorities=" + this.authorities + "]";
}
}