@Override public Resource retrieveResource(final URL url) throws IOException { final Resource ret = super.retrieveResource(url); return new Resource(ret.getContent().replace("{tenantid}", "%7Btenantid%7D"), ret.getContentType()); } }
private JWKSet retrieveJwkSet(String endpointUrl) { Resource res; try { res = resourceRetriever.retrieveResource(new URL(endpointUrl)); } catch (IOException e) { throw new IllegalStateException("Couldn't retrieve remote jwk set from: " + endpointUrl, e); } try { JWKSet.parse(res.getContent()); return JWKSet.parse(res.getContent()); } catch (java.text.ParseException e) { throw new IllegalStateException(e); } } }
jsonObject = JSONObjectUtils.parse(res.getContent()); } catch (ParseException e) { throw new IllegalStateException("Couldn't parse remote metadata: " + e.getMessage(), e); JWKSet.parse(res.getContent()); jwkSource = new RemoteJWKSet<>(new URL(resourceServer.getEndpointUrl()), resourceRetriever); return jwkSource;
/** * Updates the cached JWK set from the configured URL. * * @return The updated JWK set. * * @throws RemoteKeySourceException If JWK retrieval failed. */ private JWKSet updateJWKSetFromURL() throws RemoteKeySourceException { Resource res; try { res = jwkSetRetriever.retrieveResource(jwkSetURL); } catch (IOException e) { throw new RemoteKeySourceException("Couldn't retrieve remote JWK set: " + e.getMessage(), e); } JWKSet jwkSet; try { jwkSet = JWKSet.parse(res.getContent()); } catch (java.text.ParseException e) { throw new RemoteKeySourceException("Couldn't parse remote JWK set: " + e.getMessage(), e); } jwkSetCache.put(jwkSet); return jwkSet; }
/** * Loads a JSON Web Key (JWK) set from the specified URL. * * @param url The JWK set URL. Must not be {@code null}. * @param connectTimeout The URL connection timeout, in milliseconds. * If zero no (infinite) timeout. * @param readTimeout The URL read timeout, in milliseconds. If zero * no (infinite) timeout. * @param sizeLimit The read size limit, in bytes. If zero no * limit. * * @return The JWK set. * * @throws IOException If the file couldn't be read. * @throws ParseException If the file couldn't be parsed to a valid * JSON Web Key (JWK) set. */ public static JWKSet load(final URL url, final int connectTimeout, final int readTimeout, final int sizeLimit) throws IOException, ParseException { RestrictedResourceRetriever resourceRetriever = new DefaultResourceRetriever( connectTimeout, readTimeout, sizeLimit); Resource resource = resourceRetriever.retrieveResource(url); return parse(resource.getContent()); }
@Override protected void internalInit() { // checks CommonHelper.assertNotBlank("clientId", getClientId()); if (!AUTHORIZATION_CODE_FLOWS.contains(responseType) && !IMPLICIT_FLOWS.contains(responseType) && !HYBRID_CODE_FLOWS.contains(responseType)) { throw new TechnicalException("Unsupported responseType: " + responseType); } // except for the implicit flow, the secret is mandatory if (!IMPLICIT_FLOWS.contains(responseType)) { CommonHelper.assertNotBlank("secret", getSecret()); } if (this.getDiscoveryURI() == null && this.getProviderMetadata() == null) { throw new TechnicalException("You must define either the discovery URL or directly the provider metadata"); } // default value if (getResourceRetriever() == null) { setResourceRetriever(new DefaultResourceRetriever(getConnectTimeout(),getReadTimeout())); } if (this.getProviderMetadata() == null) { CommonHelper.assertNotBlank("discoveryURI", getDiscoveryURI()); try { // Download OIDC metadata this.setProviderMetadata(OIDCProviderMetadata.parse(getResourceRetriever().retrieveResource( new URL(this.getDiscoveryURI())).getContent())); } catch (final IOException | ParseException e) { throw new TechnicalException(e); } } }