io.quarkus.elytron.security.oauth2.runtime.auth.ElytronOAuth2CallerPrincipal Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-elytron-security-oauth2 Show documentation
Show all versions of quarkus-elytron-security-oauth2 Show documentation
Secure your applications with OAuth2 opaque tokens
package io.quarkus.elytron.security.oauth2.runtime.auth;
import java.security.Principal;
import java.util.Map;
import java.util.Optional;
/**
* An implementation of ElytronOAuth2CallerPrincipal that builds on the Elytron attributes
*/
public class ElytronOAuth2CallerPrincipal implements Principal {
private Map claims;
private String customPrincipalName;
public ElytronOAuth2CallerPrincipal(final String customPrincipalName, final Map claims) {
this.claims = claims;
this.customPrincipalName = customPrincipalName;
}
public ElytronOAuth2CallerPrincipal(final Map claims) {
this("username", claims);
}
public Map getClaims() {
return claims;
}
@Override
public String getName() {
return getClaimValueAsString(customPrincipalName).orElseGet(() -> getClaimValueAsString("client_id").orElse(null));
}
private Optional getClaimValueAsString(String key) {
if (getClaims().containsKey(key)) {
return Optional.of((String) getClaims().get(key));
}
return Optional.empty();
}
}