com.osomapps.pt.auth.CustomUserDetails   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 30
dl 0
loc 48
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getPtUser() 0 2 1
A CustomUserDetails(PtUser) 0 2 1
A isEnabled() 0 3 1
A getAuthorities() 0 6 1
A getPassword() 0 3 1
A isAccountNonLocked() 0 3 1
A isAccountNonExpired() 0 3 1
A getUsername() 0 3 1
A isCredentialsNonExpired() 0 3 1
1
package com.osomapps.pt.auth;
2
3
import com.osomapps.pt.admin.ptuser.PtUser;
4
import java.util.Collection;
5
import java.util.stream.Collectors;
6
import org.springframework.security.core.GrantedAuthority;
7
import org.springframework.security.core.authority.AuthorityUtils;
8
import org.springframework.security.core.userdetails.UserDetails;
9
10
class CustomUserDetails implements UserDetails {
11
12
    private final PtUser ptUser;
13
14
    CustomUserDetails(PtUser ptUser) {
15
        this.ptUser = ptUser;
16
    }
17
18
    public PtUser getPtUser() {
19
        return ptUser;
20
    }
21
22
    @Override
23
    public Collection<? extends GrantedAuthority> getAuthorities() {
24
        return AuthorityUtils.commaSeparatedStringToAuthorityList(
25
                ptUser.getPtRoles().stream()
26
                        .map(ptRole -> ptRole.getName())
27
                        .collect(Collectors.joining(",")));
28
    }
29
30
    @Override
31
    public String getPassword() {
32
        return ptUser.getPassword();
33
    }
34
35
    @Override
36
    public String getUsername() {
37
        return ptUser.getName();
38
    }
39
40
    @Override
41
    public boolean isAccountNonExpired() {
42
        return true;
43
    }
44
45
    @Override
46
    public boolean isAccountNonLocked() {
47
        return true;
48
    }
49
50
    @Override
51
    public boolean isCredentialsNonExpired() {
52
        return true;
53
    }
54
55
    @Override
56
    public boolean isEnabled() {
57
        return !ptUser.getIs_deleted();
58
    }
59
}
60