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

org.entur.jwt.verifier.auth0.JwtKeyProvider Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package org.entur.jwt.verifier.auth0;

import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

import org.entur.jwt.jwk.JwkProvider;

import com.auth0.jwk.InvalidPublicKeyException;
import com.auth0.jwk.Jwk;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.RSAKeyProvider;
import org.entur.jwt.jwk.JwksException;

public class JwtKeyProvider implements RSAKeyProvider {

    private final JwkProvider provider;

    public JwtKeyProvider(JwkProvider provider) {
        super();
        this.provider = provider;
    }

    @Override
    public RSAPublicKey getPublicKeyById(String keyId) {
        try {
            return (RSAPublicKey) provider.getJwk(keyId).getPublicKey();
        } catch (org.entur.jwt.jwk.JwksUnavailableException e) {
            throw new SigningKeyUnavailableException("Problem getting public key id " + keyId, e);
        } catch (JwksException | InvalidPublicKeyException e) {
            throw new JWTVerificationException("Problem getting public key id " + keyId, e);
        }
    }

    @Override
    public RSAPrivateKey getPrivateKey() {
        throw new SecurityException("Attempted to acquire private key from authentication service.");
    }

    @Override
    public String getPrivateKeyId() {
        throw new SecurityException("Attempted to acquire private key id from authentication service.");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy