getPrincipal()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
eloc 3
1
package unicon.matthews.admin;
2
3
import java.util.Collection;
4
5
import org.springframework.security.authentication.AbstractAuthenticationToken;
6
import org.springframework.security.core.GrantedAuthority;
7
8
public class AdminUserAuthenticationToken extends AbstractAuthenticationToken {
0 ignored issues
show
Bug introduced by
Override the "equals" method in this class.
Loading history...
9
  
10
  private static final long serialVersionUID = 1L;
11
  private final Object principal;
0 ignored issues
show
Bug Best Practice introduced by
Fields like principal in a serializable class should either be transient or serializable.
Loading history...
12
  private Object credentials;
0 ignored issues
show
Bug Best Practice introduced by
Fields like credentials in a serializable class should either be transient or serializable.
Loading history...
13
14
  public AdminUserAuthenticationToken(Object principal, Object credentials) {
15
    super(null);
16
    this.principal = principal;
17
    this.credentials = credentials;
18
    setAuthenticated(false);
19
  }
20
21
  public AdminUserAuthenticationToken(Object principal, Object credentials,
22
      Collection<? extends GrantedAuthority> authorities) {
23
    super(authorities);
24
    this.principal = principal;
25
    this.credentials = credentials;
26
    super.setAuthenticated(true); // must use super, as we override
27
  }
28
29
30
  @Override
31
  public Object getCredentials() {
32
    return this.credentials;
33
  }
34
35
  @Override
36
  public Object getPrincipal() {
37
    return this.principal;
38
  }
39
40
  public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
41
    if (isAuthenticated) {
42
      throw new IllegalArgumentException(
43
          "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
44
    }
45
46
    super.setAuthenticated(false);
47
  }
48
49
  @Override
50
  public void eraseCredentials() {
51
    super.eraseCredentials();
52
    credentials = null;
53
  }
54
55
}
56