@Override public String apply(Algorithm alg) { if (alg == null) { return null; } else { return alg.getName(); } } };
if (!clientAlg.equals(tokenAlg)) { throw new AuthenticationServiceException("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg); if (tokenAlg != null && !tokenAlg.equals(Algorithm.NONE)) { throw new AuthenticationServiceException("Unsigned token received, expected signature with " + tokenAlg); if (tokenAlg.equals(JWSAlgorithm.HS256) || tokenAlg.equals(JWSAlgorithm.HS384) || tokenAlg.equals(JWSAlgorithm.HS512)) {
public class Test2 extends Application { @Override public void start(Stage primaryStage) { Algorithm alg = new Algorithm(); alg.solve(); GUI gui = new GUI(); gui.displaySolution(alg.getSolution()); } // included for the benefit of IDEs that do not support // launching an Application without a main method: public static void main(String[] args) { launch(args); } }
/** * Parses the optional algorithm. * * @param o The JSON object to parse. Must not be {@code null}. * * @return The intended JOSE algorithm, {@code null} if not specified. * * @throws ParseException If parsing failed. */ static Algorithm parseAlgorithm(final JSONObject o) throws ParseException { if (o.containsKey("alg")) { return new Algorithm(JSONObjectUtils.getString(o, "alg")); } else { return null; } }
final Button button3 = new Button("Button 3"); Algorithm algo = new Algorithm() {
@Test public void getWhenMatchThenCreatesKeys() { when(this.matcher.matches(any())).thenReturn(true); List<JWK> keys = this.source.get(this.selector).block(); assertThat(keys).hasSize(2); JWK key1 = keys.get(0); assertThat(key1.getKeyID()).isEqualTo("1923397381d9574bb873202a90c32b7ceeaed027"); assertThat(key1.getAlgorithm().getName()).isEqualTo("RS256"); assertThat(key1.getKeyType()).isEqualTo(KeyType.RSA); assertThat(key1.getKeyUse()).isEqualTo(KeyUse.SIGNATURE); JWK key2 = keys.get(1); assertThat(key2.getKeyID()).isEqualTo("7ddf54d3032d1f0d48c3618892ca74c1ac30ad77"); assertThat(key2.getAlgorithm().getName()).isEqualTo("RS256"); assertThat(key2.getKeyType()).isEqualTo(KeyType.RSA); assertThat(key2.getKeyUse()).isEqualTo(KeyUse.SIGNATURE); }
if (alg.equals(Algorithm.NONE)) { return PlainJWT.parse(s); } else if (alg instanceof JWSAlgorithm) {
private ECPublicKey getKey(String kid, String alg) throws Exception { JWK jwk = keyCache.get(kid); if (jwk == null) { // update cache loading jwk public key data from url JWKSet jwkSet = JWKSet.load(new URL(PUBLIC_KEY_VERIFICATION_URL)); for (JWK key : jwkSet.getKeys()) { keyCache.put(key.getKeyID(), key); } jwk = keyCache.get(kid); } // confirm that algorithm matches if (jwk != null && jwk.getAlgorithm().getName().equals(alg)) { return ECKey.parse(jwk.toJSONString()).toECPublicKey(); } return null; }
/** * Parses a {@link PlainHeader}, {@link JWSHeader} or {@link JWEHeader} * from the specified JSON object. * * @param jsonObject The JSON object to parse. Must not be * {@code null}. * @param parsedBase64URL The original parsed Base64URL, {@code null} * if not applicable. * * @return The header. * * @throws ParseException If the specified JSON object doesn't * represent a valid header. */ public static Header parse(final JSONObject jsonObject, final Base64URL parsedBase64URL) throws ParseException { Algorithm alg = parseAlgorithm(jsonObject); if (alg.equals(Algorithm.NONE)) { return PlainHeader.parse(jsonObject, parsedBase64URL); } else if (alg instanceof JWSAlgorithm) { return JWSHeader.parse(jsonObject, parsedBase64URL); } else if (alg instanceof JWEAlgorithm) { return JWEHeader.parse(jsonObject, parsedBase64URL); } else { throw new AssertionError("Unexpected algorithm type: " + alg); } }
@Override public String apply(Algorithm alg) { if (alg == null) { return null; } else { return alg.getName(); } } };
if (alg.equals(Algorithm.NONE)) { return PlainObject.parse(s); } else if (alg instanceof JWSAlgorithm) {
private static <T extends Algorithm> T findAlgorithmFamily(final Set<Algorithm> family, final String alg) { return (T) family.stream().filter(l -> l.getName().equalsIgnoreCase(alg)).findFirst().get(); }
private void setRequestObjectValues(String requestObjectString, RequestObject requestObjectInstance) throws RequestObjectException { try { JOSEObject jwt = JOSEObject.parse(requestObjectString); if (jwt.getHeader().getAlgorithm() == null || jwt.getHeader().getAlgorithm().equals(JWSAlgorithm.NONE)) { requestObjectInstance.setPlainJWT(PlainJWT.parse(requestObjectString)); } else { requestObjectInstance.setSignedJWT(SignedJWT.parse(requestObjectString)); } } catch (ParseException e) { String errorMessage = "No Valid JWT is found for the Request Object."; if (log.isDebugEnabled()) { log.debug(errorMessage + "Received Request Object: " + requestObjectString, e); } throw new RequestObjectException(OAuth2ErrorCodes.INVALID_REQUEST, errorMessage); } }
/** * Creates a new JWS header builder. * * @param alg The JWS algorithm ({@code alg}) parameter. Must * not be "none" or {@code null}. */ public Builder(final JWSAlgorithm alg) { if (alg.getName().equals(Algorithm.NONE.getName())) { throw new IllegalArgumentException("The JWS algorithm \"alg\" cannot be \"none\""); } this.alg = alg; }
if (!clientAlg.equals(tokenAlg)) { throw new AuthenticationServiceException("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg); if (tokenAlg != null && !tokenAlg.equals(Algorithm.NONE)) { throw new AuthenticationServiceException("Unsigned token received, expected signature with " + tokenAlg); if (tokenAlg.equals(JWSAlgorithm.HS256) || tokenAlg.equals(JWSAlgorithm.HS384) || tokenAlg.equals(JWSAlgorithm.HS512)) {
private static <T extends Algorithm> T findAlgorithmFamily(final Set<Algorithm> family, final String alg, final Class<T> clazz) { val result = family .stream() .filter(l -> l.getName().equalsIgnoreCase(alg)) .findFirst() .get(); if (!clazz.isAssignableFrom(result.getClass())) { throw new ClassCastException("Result [" + result + " is of type " + result.getClass() + " when we were expecting " + clazz); } return (T) result; }
if (!clientAlg.equals(tokenAlg)) { throw new AuthenticationServiceException("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg); if (tokenAlg != null && !tokenAlg.equals(Algorithm.NONE)) { throw new AuthenticationServiceException("Unsigned token received, expected signature with " + tokenAlg); if (tokenAlg.equals(JWSAlgorithm.HS256) || tokenAlg.equals(JWSAlgorithm.HS384) || tokenAlg.equals(JWSAlgorithm.HS512)) {
public JWTTokenGenerator(boolean includeClaims, boolean enableSigning) { this.includeClaims = includeClaims; this.enableSigning = enableSigning; signatureAlgorithm = new JWSAlgorithm(JWSAlgorithm.NONE.getName()); }