Revize dfe45987
Přidáno uživatelem Jakub Danek před více než 5 roky(ů)
server/src/main/java/org/danekja/ymanager/domain/User.java | ||
---|---|---|
4 | 4 |
import org.danekja.ymanager.dto.UserRole; |
5 | 5 |
import org.slf4j.Logger; |
6 | 6 |
import org.slf4j.LoggerFactory; |
7 |
import org.springframework.security.core.GrantedAuthority; |
|
8 |
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
9 |
import org.springframework.security.core.userdetails.UserDetails; |
|
7 | 10 |
|
8 | 11 |
import java.time.LocalDateTime; |
9 | 12 |
import java.time.LocalTime; |
13 |
import java.util.Collection; |
|
14 |
import java.util.Collections; |
|
10 | 15 |
|
11 | 16 |
import static java.time.temporal.ChronoUnit.MINUTES; |
12 | 17 |
|
... | ... | |
14 | 19 |
* The domain class {@code User} represents a single record in the 'end_user' table of a database. |
15 | 20 |
* User holds all informations about a user which is logged to the application. |
16 | 21 |
*/ |
17 |
public class User { |
|
22 |
public class User implements UserDetails {
|
|
18 | 23 |
/** |
19 | 24 |
* The maximal length of a name. |
20 | 25 |
*/ |
... | ... | |
100 | 105 |
*/ |
101 | 106 |
private Status status; |
102 | 107 |
|
108 |
public User() { |
|
109 |
} |
|
110 |
|
|
111 |
public User(Long id, String firstName, String lastName, Float vacationCount, Integer totalSickDayCount, Integer takenSickDayCount, LocalDateTime notification, String token, String email, String photo, LocalDateTime creationDate, UserRole role, Status status) { |
|
112 |
this.id = id; |
|
113 |
this.firstName = firstName; |
|
114 |
this.lastName = lastName; |
|
115 |
this.vacationCount = vacationCount; |
|
116 |
this.totalSickDayCount = totalSickDayCount; |
|
117 |
this.takenSickDayCount = takenSickDayCount; |
|
118 |
this.notification = notification; |
|
119 |
this.token = token; |
|
120 |
this.email = email; |
|
121 |
this.photo = photo; |
|
122 |
this.creationDate = creationDate; |
|
123 |
this.role = role; |
|
124 |
this.status = status; |
|
125 |
} |
|
126 |
|
|
127 |
/* |
|
128 |
########################### UserDetails API ################################# |
|
129 |
*/ |
|
130 |
@Override |
|
131 |
public Collection<? extends GrantedAuthority> getAuthorities() { |
|
132 |
//TODO do not create collection on each call |
|
133 |
return Collections.singleton(new SimpleGrantedAuthority(role.name())); |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
public String getPassword() { |
|
138 |
return null; |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
public String getUsername() { |
|
143 |
return getEmail(); |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public boolean isAccountNonExpired() { |
|
148 |
//unsupported functionality |
|
149 |
return true; |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public boolean isAccountNonLocked() { |
|
154 |
//unsupported functionality |
|
155 |
return true; |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
public boolean isCredentialsNonExpired() { |
|
160 |
//unsupported functionality |
|
161 |
return true; |
|
162 |
} |
|
163 |
|
|
164 |
@Override |
|
165 |
public boolean isEnabled() { |
|
166 |
return status == Status.ACCEPTED; |
|
167 |
} |
|
168 |
|
|
169 |
/* |
|
170 |
################# UserDetails API (END) ######################### |
|
171 |
*/ |
|
172 |
|
|
173 |
|
|
103 | 174 |
/** |
104 | 175 |
* Returns the user's ID. |
105 | 176 |
* |
Také k dispozici: Unified diff
re #37 User domain class now implements Spring Security's UserDetails interface