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

io.quarkus.elytron.security.oauth2.runtime.auth.ElytronOAuth2CallerPrincipal Maven / Gradle / Ivy

There is a newer version: 3.17.0
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy