blob: f49be1e27eade3f6fda1cf81ec2929dfb1092a6d (
plain) (
blame)
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
|
package com.juick.server.security.entities;
import com.juick.User;
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.Collections;
import java.util.List;
/**
* Created by aalexeev on 11/21/16.
*/
public class JuickUser implements UserDetails {
static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
static final GrantedAuthority ROLE_ANONYM = new SimpleGrantedAuthority("ROLE_ANONYM");
public static final List<GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER);
public static final List<GrantedAuthority> ANONYM_AUTHORITY = Collections.singletonList(ROLE_ANONYM);
public static final JuickUser ANONYM_USER = new JuickUser(AnonymousUser.INSTANCE, ANONYM_AUTHORITY);
private final com.juick.User user;
private final Collection<? extends GrantedAuthority> authorities;
public JuickUser(com.juick.User user) {
this(user, USER_AUTHORITY);
}
public JuickUser(com.juick.User user, Collection<? extends GrantedAuthority> authorities) {
this.user = user;
this.authorities = authorities;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return authorities;
}
@Override
public String getPassword() {
return user.getCredentials();
}
@Override
public String getUsername() {
return user.getName();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return !user.isBanned();
}
public User getUser() {
return user;
}
}
|