b6624229913146ae1e4e62428795b08cb6e485c7
[institute/sw-backend.git] /
1 package com.supwisdom.institute.backend.admin.bff.security.core.userdetails;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.springframework.security.core.GrantedAuthority;
9 import org.springframework.security.core.userdetails.User;
10
11 public class MyUser extends User {
12
13   /**
14    * 
15    */
16   private static final long serialVersionUID = 3195151947212484499L;
17
18   public MyUser(String username, String password, 
19       Collection<? extends GrantedAuthority> authorities, 
20       Map<String, Object> attributes) {
21     this(username, password, true, true, true, true, authorities, attributes);
22   }
23
24   public MyUser(String username, String password, 
25       boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, 
26       Collection<? extends GrantedAuthority> authorities, 
27       Map<String, Object> attributes) {
28     super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
29     
30     this.attributes = attributes;
31   }
32
33   private final Map<String, Object> attributes;
34   public Map<String, Object> getAttributes() {
35     return this.attributes;
36   }
37   
38   public List<String> getRoles() {
39     List<String> roles = new ArrayList<>();
40     for (GrantedAuthority grantedAuthority : this.getAuthorities()) {
41       roles.add(grantedAuthority.getAuthority());
42     }
43     
44     return roles;
45   }
46   
47
48   public Object getAttribute(String key) {
49     if (attributes == null) {
50       return null;
51     }
52     
53     if (!attributes.containsKey(key)) {
54       return null;
55     }
56     
57     return attributes.get(key);
58   }
59   
60 }