package com.ffii.core.security.authentication;

import com.ffii.core.User;

import org.springframework.security.authentication.AbstractAuthenticationToken;

/**
 * Authentication Token
 *
 * @author Patrick
 */
public class AuthToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 3383254131623375507L;

    private final String token;
    private final User user;

    public AuthToken(String token) {
        super(null);

        this.token = token;
        this.user = null;
        setAuthenticated(false);
    }

    public AuthToken(String token, User user) {
        super(user.getAuthorities());

        this.token = token;
        this.user = user;
        setAuthenticated(true);
    }

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

    @Override
    public Object getPrincipal() {
        return getUser();
    }

    public String getToken() {
        return token;
    }

    public User getUser() {
        return user;
    }
}