mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2024-06-03 06:10:11 +02:00
53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
package stirling.software.SPDF.model;
|
|
|
|
import java.util.Collection;
|
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
|
public class ApiKeyAuthenticationToken extends AbstractAuthenticationToken {
|
|
|
|
private final Object principal;
|
|
private Object credentials;
|
|
|
|
public ApiKeyAuthenticationToken(String apiKey) {
|
|
super(null);
|
|
this.principal = null;
|
|
this.credentials = apiKey;
|
|
setAuthenticated(false);
|
|
}
|
|
|
|
public ApiKeyAuthenticationToken(
|
|
Object principal, String apiKey, Collection<? extends GrantedAuthority> authorities) {
|
|
super(authorities);
|
|
this.principal = principal; // principal can be a UserDetails object
|
|
this.credentials = apiKey;
|
|
super.setAuthenticated(true); // this authentication is trusted
|
|
}
|
|
|
|
@Override
|
|
public Object getCredentials() {
|
|
return credentials;
|
|
}
|
|
|
|
@Override
|
|
public Object getPrincipal() {
|
|
return principal;
|
|
}
|
|
|
|
@Override
|
|
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;
|
|
}
|
|
}
|