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

com.nimbusds.openid.connect.provider.spi.reg.statement.SoftwareStatementVerifier Maven / Gradle / Ivy

There is a newer version: 2.3
Show newest version
package com.nimbusds.openid.connect.provider.spi.reg.statement;


import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.EnumSet;
import java.util.Properties;
import java.util.Set;

import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.JsonOrgMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import net.jcip.annotations.ThreadSafe;
import net.minidev.json.JSONObject;

import com.nimbusds.common.contenttype.ContentType;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.RemoteKeySourceException;
import com.nimbusds.jose.jwk.source.RemoteJWKSet;
import com.nimbusds.jose.proc.BadJOSEException;
import com.nimbusds.jose.proc.JWSVerificationKeySelector;
import com.nimbusds.jose.util.DefaultResourceRetriever;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import com.nimbusds.jwt.proc.DefaultJWTClaimsVerifier;
import com.nimbusds.jwt.proc.DefaultJWTProcessor;
import com.nimbusds.oauth2.sdk.OAuth2Error;
import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.oauth2.sdk.client.RegistrationError;
import com.nimbusds.oauth2.sdk.http.HTTPRequest;
import com.nimbusds.oauth2.sdk.http.HTTPResponse;
import com.nimbusds.oauth2.sdk.util.JSONObjectUtils;
import com.nimbusds.oauth2.sdk.util.StringUtils;
import com.nimbusds.openid.connect.provider.spi.InitContext;
import com.nimbusds.openid.connect.provider.spi.reg.InterceptorContext;
import com.nimbusds.openid.connect.provider.spi.reg.RegistrationInterceptor;
import com.nimbusds.openid.connect.provider.spi.reg.WrappedHTTPResponseException;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
import com.nimbusds.openid.connect.sdk.rp.statement.InvalidSoftwareStatementException;
import com.nimbusds.openid.connect.sdk.rp.statement.SoftwareStatementProcessor;


/**
 * Software statement verifier.
 */
@ThreadSafe
public class SoftwareStatementVerifier implements RegistrationInterceptor {
	
	
	private static final URL DUMMY_URL;
	
	static {
		try {
			DUMMY_URL = new URL("http:///");
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}
	
	
	/**
	 * The verifier configuration.
	 */
	private Configuration config;
	
	
	/**
	 * The configured software statements processor, {@code null} if
	 * not enabled.
	 */
	private SoftwareStatementProcessor statementProcessor;
	
	
	/**
	 * Optional processor for signed JWT requests, where the JWK set URL
	 * is statically configured, {@code null} if not enabled.
	 */
	private DefaultJWTProcessor requestJWTProcessorWithStaticJWKSetURL;
	
	
	/**
	 * Optional processor for signed JWT requests, where the JWK set URL is
	 * specified by a claim in the software statement, {@code null} if not
	 * enabled.
	 */
	private DefaultJWTProcessor requestJWTProcessorWithStatementReferencedJWKSetURL;
	
	
	/**
	 * Loads the configuration.
	 *
	 * @param initContext The initialisation context. Must not be
	 *                    {@code null}.
	 *
	 * @return The configuration.
	 *
	 * @throws IOException If loading failed.
	 */
	private static Configuration loadConfiguration(final InitContext initContext)
		throws IOException {
		
		var props = new Properties();
		
		var inputStream = initContext.getResourceAsStream(Configuration.FILE_PATH);
		
		if (inputStream != null) {
			props.load(inputStream);
		}
		
		return new Configuration(props);
	}
	
	
	@Override
	public void init(final InitContext initContext)
		throws Exception {
		
		config = loadConfiguration(initContext);
		
		config.log();
		
		if (! config.enable) {
			return;
		}
		
		com.jayway.jsonpath.Configuration.setDefaults(new com.jayway.jsonpath.Configuration.Defaults() {
			
			private final JsonProvider jsonProvider = new JsonOrgJsonProvider();
			private final MappingProvider mappingProvider = new JsonOrgMappingProvider();
			
			@Override
			public JsonProvider jsonProvider() {
				return jsonProvider;
			}
			
			@Override
			public MappingProvider mappingProvider() {
				return mappingProvider;
			}
			
			@Override
			public Set




© 2015 - 2025 Weber Informatics LLC | Privacy Policy