congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Jwk
Code IndexAdd Tabnine to your IDE (free)

How to use
Jwk
in
com.auth0.jwk

Best Java code snippets using com.auth0.jwk.Jwk (Showing top 18 results out of 315)

origin: com.kumuluz.ee.jwt/kumuluzee-jwt-auth

@Override
public RSAPublicKey getPublicKeyById(String keyId) {
  try {
    final PublicKey publicKey = jwkProvider.get(keyId).getPublicKey();
    if (!(publicKey instanceof RSAPublicKey)) {
      throw new IllegalArgumentException(String.format("Key with ID '%s' was found in JWKS but is not a RSA-key.", keyId));
    }
    return (RSAPublicKey) publicKey;
  } catch (JwkException e) {
    throw new IllegalArgumentException(String.format("Key with ID '%s' couldn't be fetched from JWKS.", keyId), e);
  }
}
origin: auth0/jwks-rsa-java

private List<Jwk> getAll() throws SigningKeyNotFoundException {
  List<Jwk> jwks = Lists.newArrayList();
  @SuppressWarnings("unchecked") final List<Map<String, Object>> keys = (List<Map<String, Object>>) getJwks().get("keys");
  if (keys == null || keys.isEmpty()) {
    throw new SigningKeyNotFoundException("No keys found in " + url.toString(), null);
  }
  try {
    for (Map<String, Object> values : keys) {
      jwks.add(Jwk.fromValues(values));
    }
  } catch (IllegalArgumentException e) {
    throw new SigningKeyNotFoundException("Failed to parse jwk from json", e);
  }
  return jwks;
}
origin: auth0/jwks-rsa-java

  @Override
  public Jwk get(String keyId) throws JwkException {
    final List<Jwk> jwks = getAll();
    if (keyId == null && jwks.size() == 1) {
      return jwks.get(0);
    }
    if (keyId != null) {
      for (Jwk jwk : jwks) {
        if (keyId.equals(jwk.getId())) {
          return jwk;
        }
      }
    }
    throw new SigningKeyNotFoundException("No key found in " + url.toString() + " with kid " + keyId, null);
  }
}
origin: Microsoft/botbuilder-java

  @SuppressWarnings("unchecked")
  private OpenIdMetadataKey findKey(String keyId) {
    try {
      Jwk jwk = this.cacheKeys.get(keyId);
      OpenIdMetadataKey key = new OpenIdMetadataKey();
      key.key = (RSAPublicKey) jwk.getPublicKey();
      key.endorsements = (List<String>) jwk.getAdditionalAttributes().get("endorsements");
      return key;
    } catch (JwkException e) {
      String errorDescription = String.format("Failed to load keys: %s", e.getMessage());
      LOGGER.log(Level.WARNING, errorDescription);
    }
    return null;
  }
}
origin: auth0/jwks-rsa-java

@Test
public void shouldReturnPublicKeyForEmptyKeyOpsParam() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, Lists.newArrayList());
  Jwk jwk = Jwk.fromValues(values);
  assertThat(jwk.getPublicKey(), notNullValue());
  assertThat(jwk.getOperationsAsList(), notNullValue());
  assertThat(jwk.getOperationsAsList().size(), equalTo(0));
  assertThat(jwk.getOperations(), nullValue());
}
origin: auth0/jwks-rsa-java

@Test
public void shouldBuildWithMap() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, KEY_OPS_LIST);
  Jwk jwk = Jwk.fromValues(values);
  assertThat(jwk.getId(), equalTo(kid));
  assertThat(jwk.getAlgorithm(), equalTo(RS_256));
  assertThat(jwk.getType(), equalTo(RSA));
  assertThat(jwk.getUsage(), equalTo(SIG));
  assertThat(jwk.getOperationsAsList(), equalTo(KEY_OPS_LIST));
  assertThat(jwk.getOperations(), is(KEY_OPS_STRING));
  assertThat(jwk.getCertificateThumbprint(), equalTo(THUMBPRINT));
  assertThat(jwk.getCertificateChain(), contains(CERT_CHAIN));
}
origin: auth0/jwks-rsa-java

@Test
public void shouldReturnKeyWithMissingAlgParam() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, KEY_OPS_LIST);
  values.remove("alg");
  Jwk jwk = Jwk.fromValues(values);
  assertThat(jwk.getPublicKey(), notNullValue());
}
origin: auth0/jwks-rsa-java

@SuppressWarnings("unchecked")
static Jwk fromValues(Map<String, Object> map) {
  Map<String, Object> values = Maps.newHashMap(map);
  String kid = (String) values.remove("kid");
  String kty = (String) values.remove("kty");
  String alg = (String) values.remove("alg");
  String use = (String) values.remove("use");
  Object keyOps = values.remove("key_ops");
  String x5u = (String) values.remove("x5u");
  List<String> x5c = (List<String>) values.remove("x5c");
  String x5t = (String) values.remove("x5t");
  if (kty == null) {
    throw new IllegalArgumentException("Attributes " + map + " are not from a valid jwk");
  }
  if (keyOps instanceof String) {
    return new Jwk(kid, kty, alg, use, (String) keyOps, x5u, x5c, x5t, values);
  } else {
    return new Jwk(kid, kty, alg, use, (List<String>) keyOps, x5u, x5c, x5t, values);
  }
}
origin: auth0/jwks-rsa-java

@Test
public void shouldReturnPublicKeyForStringKeyOpsParam() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, KEY_OPS_STRING);
  Jwk jwk = Jwk.fromValues(values);
  assertThat(jwk.getPublicKey(), notNullValue());
  assertThat(jwk.getOperationsAsList(), is(KEY_OPS_LIST));
  assertThat(jwk.getOperations(), is(KEY_OPS_STRING));
}
origin: auth0/jwks-rsa-java

@Test
public void shouldThrowForNonRSAKey() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = nonRSAValues(kid);
  Jwk jwk = Jwk.fromValues(values);
  expectedException.expect(InvalidPublicKeyException.class);
  expectedException.expectMessage("The key is not of type RSA");
  jwk.getPublicKey();
}

origin: com.microsoft.bot.connector/bot-connector

  @SuppressWarnings("unchecked")
  private OpenIdMetadataKey findKey(String keyId) {
    try {
      Jwk jwk = cacheKeys.get(keyId);
      OpenIdMetadataKey key = new OpenIdMetadataKey();
      key.key = (RSAPublicKey) jwk.getPublicKey();
      key.endorsements = (List<String>) jwk.getAdditionalAttributes().get("endorsements");
      return key;
    } catch (JwkException e) {
      String errorDescription = String.format("Failed to load keys: %s", e.getMessage());
      LOGGER.log(Level.WARNING, errorDescription);
    }
    return null;
  }
}
origin: auth0/jwks-rsa-java

@Test
public void shouldReturnPublicKeyForNullKeyOpsParam() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, null);
  Jwk jwk = Jwk.fromValues(values);
  assertThat(jwk.getPublicKey(), notNullValue());
  assertThat(jwk.getOperationsAsList(), nullValue());
  assertThat(jwk.getOperations(), nullValue());
}
origin: thomasdarimont/springio18-spring-keycloak

private void verifyJwt(JWT decoded) {
  try {
    Jwk jwk = jwkProvider.get(decoded.getKeyId());
    // TODO check for Algorithm
    JWTVerifier verifier = JWT.require(Algorithm.RSA256((RSAKey) jwk.getPublicKey())).build();
    verifier.verify(decoded.getToken());
  } catch (Exception e) {
    e.printStackTrace();
    throw new IllegalStateException("Bad token!");
  }
}
origin: auth0/jwks-rsa-java

@Test
public void shouldNotThrowInvalidArgumentExceptionOnMissingKidParam() throws Exception {
  //kid is optional - https://tools.ietf.org/html/rfc7517#section-4.5
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, KEY_OPS_LIST);
  values.remove("kid");
  Jwk.fromValues(values);
}
origin: auth0/jwks-rsa-java

@Test
public void shouldReturnPublicKey() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, KEY_OPS_LIST);
  Jwk jwk = Jwk.fromValues(values);
  assertThat(jwk.getPublicKey(), notNullValue());
  assertThat(jwk.getOperationsAsList(), is(KEY_OPS_LIST));
  assertThat(jwk.getOperations(), is(KEY_OPS_STRING));
}
origin: io.interface21/ameba-lib

byte[] publicKeyBytes = jwk.getPublicKey().getEncoded();
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
origin: auth0/jwks-rsa-java

@Test
public void shouldThrowInvalidArgumentExceptionOnMissingKtyParam() throws Exception {
  final String kid = randomKeyId();
  Map<String, Object> values = publicKeyValues(kid, KEY_OPS_LIST);
  values.remove("kty");
  expectedException.expect(IllegalArgumentException.class);
  Jwk.fromValues(values);
}
origin: org.eclipse.che.multiuser/che-multiuser-keycloak-server

 private synchronized PublicKey getJwtPublicKey(JwsHeader<?> header) {
  String kid = header.getKeyId();
  if (header.getKeyId() == null) {
   LOG.warn(
     "'kid' is missing in the JWT token header. This is not possible to validate the token with OIDC provider keys");
   throw new JwtException("'kid' is missing in the JWT token header.");
  }
  try {
   return jwkProvider.get(kid).getPublicKey();
  } catch (JwkException e) {
   throw new JwtException(
     "Error during the retrieval of the public key during JWT token validation", e);
  }
 }
}
com.auth0.jwkJwk

Javadoc

Represents a JSON Web Key (JWK) used to verify the signature of JWTs

Most used methods

  • getPublicKey
  • fromValues
  • getId
  • <init>
    Creates a new Jwk
  • getAdditionalAttributes
  • getAlgorithm
  • getCertificateChain
  • getCertificateThumbprint
  • getOperations
  • getOperationsAsList
  • getType
  • getUsage
  • getType,
  • getUsage,
  • stringValue

Popular in Java

  • Running tasks concurrently on multiple threads
  • getResourceAsStream (ClassLoader)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onCreateOptionsMenu (Activity)
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • JFileChooser (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now