aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/security/entities/JuickUser.java
blob: f6d27ddf5883da780c1ee6d29a9b091edb0b8c85 (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
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;

/**
 * Created by aalexeev on 11/21/16.
 */
public class JuickUser implements UserDetails {
    public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
    public static final Collection<? extends GrantedAuthority> USER_AUTHORITY = Collections.singletonList(ROLE_USER);

    private final com.juick.User user;

    public JuickUser(com.juick.User user) {
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return USER_AUTHORITY;
    }

    @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;
    }
}