/** * Creates a new JWS verification key selector. * * @param jwsAlg The expected JWS algorithm for the objects to be * verified. Must not be {@code null}. */ public DelegateSelectorFactory(JWSAlgorithm jwsAlg) { super(jwsAlg, (jwkSelector, context) -> { throw new KeySourceException("JWKSelectorFactory is only intended for creating a selector"); }); }
@Override public String convertToDatabaseColumn(EncryptionMethod attribute) { if (attribute != null) { return attribute.getName(); } else { return null; } }
@Override public EncryptionMethod convertToEntityAttribute(String dbData) { if (dbData != null) { return EncryptionMethod.parse(dbData); } else { return null; } } }
@Override public AuthDataPair decrypt(String encrypted, PrivateKey privateKey) { try { RSADecrypter decrypter = new RSADecrypter(privateKey); JWEObject object = JWEObject.parse(encrypted); object.decrypt(decrypter); return objectMapper.readValue(object.getPayload().toString(), AuthDataPair.class); } catch (IOException | ParseException | JOSEException e) { throw new SecurityException("Error decrypting auth tokens", e); } } }
@Override public JWSAlgorithm convertToEntityAttribute(String dbData) { if (dbData != null) { return JWSAlgorithm.parse(dbData); } else { return null; } } }
public String getDefaultSigningAlgorithmName() { if (defaultAlgorithm != null) { return defaultAlgorithm.getName(); } else { return null; } }
@Override public String apply(Algorithm alg) { if (alg == null) { return null; } else { return alg.getName(); } } };
@Override public String convertToDatabaseColumn(JWEAlgorithm attribute) { if (attribute != null) { return attribute.getName(); } else { return null; } }
@Override public JWEAlgorithm convertToEntityAttribute(String dbData) { if (dbData != null) { return JWEAlgorithm.parse(dbData); } else { return null; } } }
@Override public Collection<JWEAlgorithm> getAllEncryptionAlgsSupported() { Set<JWEAlgorithm> algs = new HashSet<>(); for (JWEEncrypter encrypter : encrypters.values()) { algs.addAll(encrypter.supportedJWEAlgorithms()); } for (JWEDecrypter decrypter : decrypters.values()) { algs.addAll(decrypter.supportedJWEAlgorithms()); } return algs; }
@Override public Collection<EncryptionMethod> getAllEncryptionEncsSupported() { Set<EncryptionMethod> encs = new HashSet<>(); for (JWEEncrypter encrypter : encrypters.values()) { encs.addAll(encrypter.supportedEncryptionMethods()); } for (JWEDecrypter decrypter : decrypters.values()) { encs.addAll(decrypter.supportedEncryptionMethods()); } return encs; }
@Override public Collection<JWSAlgorithm> getAllSigningAlgsSupported() { Set<JWSAlgorithm> algs = new HashSet<>(); for (JWSSigner signer : signers.values()) { algs.addAll(signer.supportedJWSAlgorithms()); } for (JWSVerifier verifier : verifiers.values()) { algs.addAll(verifier.supportedJWSAlgorithms()); } return algs; }
public void setDefaultSigningAlgorithmName(String algName) { defaultAlgorithm = JWSAlgorithm.parse(algName); }
@Override public String convertToDatabaseColumn(JWSAlgorithm attribute) { if (attribute != null) { return attribute.getName(); } else { return null; } }
/** * Gets the value of the given member as a JWE Encryption Method, null if it doesn't exist */ public static EncryptionMethod getAsJweEncryptionMethod(JsonObject o, String member) { String s = getAsString(o, member); if (s != null) { return EncryptionMethod.parse(s); } else { return null; } }
/** * Gets the value of the given member as a JWE Algorithm, null if it doesn't exist */ public static JWEAlgorithm getAsJweAlgorithm(JsonObject o, String member) { String s = getAsString(o, member); if (s != null) { return JWEAlgorithm.parse(s); } else { return null; } }
/** * Use the given signing * <a href="https://tools.ietf.org/html/rfc7515#section-4.1.1" target="_blank">algorithm</a>. * * @param jwsAlgorithm the algorithm to use * @return a {@link JwtProcessors} for further configurations */ public JwkSetUriJwtProcessorBuilder jwsAlgorithm(String jwsAlgorithm) { Assert.hasText(jwsAlgorithm, "jwsAlgorithm cannot be empty"); this.jwsAlgorithm = JWSAlgorithm.parse(jwsAlgorithm); return this; }
/** * Use the given signing * <a href="https://tools.ietf.org/html/rfc7515#section-4.1.1" target="_blank">algorithm</a>. * * The value should be one of * <a href="https://tools.ietf.org/html/rfc7518#section-3.3" target="_blank">RS256, RS384, or RS512</a>. * * @param jwsAlgorithm the algorithm to use * @return a {@link JwtProcessors} for further configurations */ public PublicKeyJwtProcessorBuilder jwsAlgorithm(String jwsAlgorithm) { Assert.hasText(jwsAlgorithm, "jwsAlgorithm cannot be empty"); this.jwsAlgorithm = JWSAlgorithm.parse(jwsAlgorithm); return this; }
private PublicKeyJwtProcessorBuilder(RSAPublicKey key) { Assert.notNull(key, "key cannot be null"); this.jwsAlgorithm = JWSAlgorithm.parse(JwsAlgorithms.RS256); this.key = rsaKey(key); }
/** * Gets the value of the given member as a JWS Algorithm, null if it doesn't exist */ public static JWSAlgorithm getAsJwsAlgorithm(JsonObject o, String member) { String s = getAsString(o, member); if (s != null) { return JWSAlgorithm.parse(s); } else { return null; } }