source: src/main/java/com/example/fooddeliverysystem/model/userssecurity/UserPrincipal.java

Last change on this file was 8d11f8c, checked in by jovanmanchev <jovanmanchev3003@…>, 20 months ago

code added, trial 2

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package com.example.fooddeliverysystem.model.userssecurity;
2
3import com.example.fooddeliverysystem.model.User;
4import org.springframework.security.core.GrantedAuthority;
5import org.springframework.security.core.authority.SimpleGrantedAuthority;
6import org.springframework.security.core.userdetails.UserDetails;
7
8import java.util.ArrayList;
9import java.util.Collection;
10import java.util.List;
11
12public class UserPrincipal implements UserDetails {
13
14 private final User user;
15
16 public UserPrincipal(User user) {
17 this.user = user;
18 }
19
20 @Override
21 public Collection<? extends GrantedAuthority> getAuthorities() {
22 List<GrantedAuthority> authorityList = new ArrayList<>();
23 authorityList.add(new SimpleGrantedAuthority("ROLE_" + this.user.getUserRole().name()));
24 return authorityList;
25 }
26
27 @Override
28 public String getPassword() {
29 return this.user.getPassword();
30 }
31
32 @Override
33 public String getUsername() {
34 return this.user.getUsername();
35 }
36
37 @Override
38 public boolean isAccountNonExpired() {
39 return true;
40 }
41
42 @Override
43 public boolean isAccountNonLocked() {
44 return true;
45 }
46
47 @Override
48 public boolean isCredentialsNonExpired() {
49 return true;
50 }
51
52 @Override
53 public boolean isEnabled() {
54 return true;
55 }
56}
Note: See TracBrowser for help on using the repository browser.