All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.capitalone.dashboard.auth.apitoken.ApiTokenAuthenticationToken Maven / Gradle / Ivy

There is a newer version: 3.7.33
Show newest version
package com.capitalone.dashboard.auth.apitoken;

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

import java.util.Collection;

public class ApiTokenAuthenticationToken extends AbstractAuthenticationToken {

	private final Object principal;
	private Object credentials;

	@SuppressWarnings("PMD")
	public ApiTokenAuthenticationToken(Object principal, Object credentials) {
		super(null);
		this.principal = principal;
		this.credentials = credentials;
		setAuthenticated(false);
	}

	@SuppressWarnings("PMD")
	public ApiTokenAuthenticationToken(Object principal, Object credentials,
									   Collection 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 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");
		}

		super.setAuthenticated(false);
	}

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy