View Javadoc
1   package net.sumaris.server.http.security;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Server
6    * %%
7    * Copyright (C) 2018 - 2019 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import net.sumaris.server.vo.security.AuthDataVO;
26  import org.springframework.security.core.GrantedAuthority;
27  import org.springframework.security.core.userdetails.UserDetails;
28  
29  import java.util.Collection;
30  import java.util.List;
31  
32  /**
33   * Authenticated user class implementing {@link UserDetails} for Spring security context
34   *
35   * @author peck7 on 03/12/2018.
36   */
37  public class AuthUser implements UserDetails {
38  
39      private final AuthDataVO authData;
40      private final List<? extends GrantedAuthority> authorities;
41  
42      AuthUser(AuthDataVO authData, List<? extends GrantedAuthority> authorities) {
43          this.authData = authData;
44          this.authorities = authorities;
45      }
46  
47      @Override
48      public Collection<? extends GrantedAuthority> getAuthorities() {
49          return authorities;
50      }
51  
52      @Override
53      public String getPassword() {
54          return authData.asToken();
55      }
56  
57      @Override
58      public String getUsername() {
59          return authData.getPubkey();
60      }
61  
62      @Override
63      public boolean isAccountNonExpired() {
64          return true;
65      }
66  
67      @Override
68      public boolean isAccountNonLocked() {
69          return true;
70      }
71  
72      @Override
73      public boolean isCredentialsNonExpired() {
74          return true;
75      }
76  
77      @Override
78      public boolean isEnabled() {
79          return true;
80      }
81  }