package com.skr.mdm.authentication.user.oaid;

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

import java.util.Collection;

/**
 * @author nfq
 * @date 2021/1/29 15:06
 */
public class OaidAuthenticationToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 2637723175472434118L;
    /**
     * oaid
     */
    private final Object principal;
    private final Object companyId;

    public OaidAuthenticationToken(Object principal, Object companyId) {
        super(null);
        this.principal = principal;
        this.companyId = companyId;
        setAuthenticated(false);
    }

    /**
     * Creates a token with the supplied array of authorities.
     *
     * @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
     *                    represented by this authentication object.
     * @param principal
     */
    public OaidAuthenticationToken(Collection<? extends GrantedAuthority> authorities, Object principal, Object companyId) {
        super(authorities);
        this.principal = principal;
        this.companyId = companyId;
        super.setAuthenticated(true);
    }

    @Override
    public void setAuthenticated(boolean authenticated) {
        super.setAuthenticated(authenticated);
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public void eraseCredentials() {
        super.eraseCredentials();
    }

    public Object getCompanyId() {
        return companyId;
    }
}
