Projekt

Obecné

Profil

Stáhnout (2.06 KB) Statistiky
| Větev: | Revize:
1
package vldc.aswi.model.login;
2

    
3
import java.util.Collection;
4
import java.util.LinkedList;
5
import java.util.stream.Collectors;
6

    
7
import org.springframework.security.core.GrantedAuthority;
8
import org.springframework.security.core.authority.SimpleGrantedAuthority;
9
import org.springframework.security.core.userdetails.UserDetails;
10

    
11
/**
12
 * Model used in spring security representing user credentials saved in session.
13
 */
14
public class WebCredentials implements UserDetails {
15

    
16
	private static final long serialVersionUID = 26298569253774237L;
17

    
18
	private final String username;
19
	private final String password;
20
	private Collection<String> roles;
21

    
22
	/**
23
	 * Constructor.
24
	 * @param username Username of user.
25
	 * @param password Password of user.
26
	 */
27
	public WebCredentials(String username, String password) {
28
		this.username = username;
29
		this.password = password;
30
		this.roles = new LinkedList<>();
31
	}
32

    
33
	/**
34
	 * Get authorities for logged User.
35
	 * @return List of roles.
36
	 */
37
	@Override
38
	public Collection<? extends GrantedAuthority> getAuthorities() {
39
		return this.roles
40
		.stream()
41
		.map(SimpleGrantedAuthority::new)
42
		.collect(Collectors.toList());
43
	}
44

    
45
	/**
46
	 * Get logged user password.
47
	 * @return User password.
48
	 */
49
	@Override
50
	public String getPassword() {
51
		return this.password;
52
	}
53

    
54
	/**
55
	 * Get logged user username.
56
	 * @return User username.
57
	 */
58
	@Override
59
	public String getUsername() {
60
		return this.username;
61
	}
62

    
63
	/**
64
	 * Check if account is non expired.
65
	 * @return True.
66
	 */
67
	@Override
68
	public boolean isAccountNonExpired() {
69
		return true;
70
	}
71

    
72
	/**
73
	 * Check if account is non locked.
74
	 * @return True.
75
	 */
76
	@Override
77
	public boolean isAccountNonLocked() {
78
		return true;
79
	}
80

    
81
	/**
82
	 * Check if Credentials non expired.
83
	 * @return True.
84
	 */
85
	@Override
86
	public boolean isCredentialsNonExpired() {
87
		return true;
88
	}
89

    
90
	/**
91
	 * Check if user is enabled.
92
	 * @return True.
93
	 */
94
	@Override
95
	public boolean isEnabled() {
96
		return true;
97
	}
98

    
99
	/**
100
	 * Add role for user in webcredentials object.
101
	 * @param role new role for user.
102
	 */
103
	public void addRole(String role) {
104
		this.roles.add(role);
105
	}
106

    
107
}
    (1-1/1)