package org.lingniu.idp.security.token;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

// 基础认证Token
public abstract class BaseAuthenticationToken extends AbstractAuthenticationToken {
    protected final Object principal;
    protected String credentials;
    protected String deviceId;
    protected String deviceType;
    protected String clientId;
    
    public BaseAuthenticationToken(Object principal, Object credentials) {
        super(null);
        this.principal = principal;
        this.credentials = (String) credentials;
        setAuthenticated(false);
    }
    
    public BaseAuthenticationToken(Object principal, Object credentials,
                                   Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = (String) credentials;
        super.setAuthenticated(true);
    }
    
    @Override
    public Object getCredentials() {
        return credentials;
    }
    
    @Override
    public Object getPrincipal() {
        return principal;
    }
    
    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }
    
    public String getDeviceId() {
        return deviceId;
    }
    
    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }
    
    public String getDeviceType() {
        return deviceType;
    }
    
    public void setClientId(String clientId) {
        this.clientId = clientId;
    }
    
    public String getClientId() {
        return clientId;
    }
    
    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
        credentials = null;
    }
}