gongzuming
2024-08-27 f78f3cd1cbc8547896bb4e0956c895780d392c96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.mzl.flower.config.security.token;
 
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
 
import java.util.Collection;
 
public class PhoneAuthenticationToken extends AbstractAuthenticationToken {
    private static final long serialVersionUID = 110L;
    private final Object principal;
    private Object credentials;
    private String userType;
 
    public PhoneAuthenticationToken(Object principal, Object credentials, String userType) {
        super((Collection)null);
        this.principal = principal;
        this.credentials = credentials;
        this.userType = userType;
        this.setAuthenticated(false);
    }
 
    public PhoneAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true);
    }
 
    public Object getCredentials() {
        return this.credentials;
    }
 
    public Object getPrincipal() {
        return this.principal;
    }
 
    public String getUserType() {
        return this.userType;
    }
 
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (isAuthenticated) {
            throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
        } else {
            super.setAuthenticated(false);
        }
    }
 
    public void eraseCredentials() {
        super.eraseCredentials();
        this.credentials = null;
    }
}