class SAML2IdentityProviderMetadataResolver extends SpringResourceLoader<MetadataResolver> implements SAML2MetadataResolver {

    @Setter
    private Proxy proxy = Proxy.NO_PROXY;
    @Setter
    private HostnameVerifier hostnameVerifier;
    @Setter
    private SSLSocketFactory sslSocketFactory;

    private final SAML2Configuration configuration;

    /**
     * <p>Constructor for SAML2IdentityProviderMetadataResolver.</p>
     *
     * @param configuration a {@link SAML2Configuration} object
     */
    public SAML2IdentityProviderMetadataResolver(final SAML2Configuration configuration) {
        super(configuration.getIdentityProviderMetadataResource());
        if (configuration.getSslSocketFactory() != null) {
            setSslSocketFactory(configuration.getSslSocketFactory());
        }
        if (configuration.getHostnameVerifier() != null) {
            setHostnameVerifier(configuration.getHostnameVerifier());
        }
        this.configuration = configuration;
    }

    /** {@inheritDoc} */
    @Override
    public final MetadataResolver resolve() {
        return load();
    }

    /**
     * <p>internalLoad.</p>
     */
    protected void internalLoad() {
        this.loaded = initializeMetadataResolver();
    }

    /**
     * <p>initializeMetadataResolver.</p>
     *
     * @return a {@link DOMMetadataResolver} object
     */
    protected DOMMetadataResolver initializeMetadataResolver() {
        try (var in = SpringResourceHelper.getResourceInputStream(
            configuration.getIdentityProviderMetadataResource(),
            proxy,
            sslSocketFactory,
            hostnameVerifier,
            configuration.getIdentityProviderMetadataConnectTimeout(),
            configuration.getIdentityProviderMetadataReadTimeout()
        )) {
            var parsedInput = Configuration.getParserPool().parse(in);
            var metadataRoot = parsedInput.getDocumentElement();
            var resolver = new DOMMetadataResolver(metadataRoot);
            resolver.setIndexes(Collections.singleton(new RoleMetadataIndex()));
            resolver.setParserPool(Configuration.getParserPool());
            resolver.setFailFastInitialization(true);
            resolver.setRequireValidMetadata(true);
            resolver.setId(resolver.getClass().getCanonicalName());
            resolver.initialize();
            return resolver;
        } catch (final FileNotFoundException e) {
            throw new TechnicalException("Error loading idp metadata", e);
        } catch (final ComponentInitializationException e) {
            throw new TechnicalException("Error initializing idp metadata resolver", e);
        } catch (final XMLParserException e) {
            throw new TechnicalException("Error parsing idp metadata", e);
        } catch (final IOException e) {
            throw new TechnicalException("Error getting idp metadata resource", e);
        }
    }

    /**
     * If no idpEntityId declared, select first EntityDescriptor entityId as our IDP.
     *
     * @return entity id of the idp
     */
    protected String determineIdentityProviderEntityId() {
        var idpEntityId = configuration.getIdentityProviderEntityId();
        if (idpEntityId == null) {
            var it = ((IterableMetadataSource) loaded).iterator();
            if (it.hasNext()) {
                var entityDescriptor = it.next();
                idpEntityId = entityDescriptor.getEntityID();
            }
        }

        if (idpEntityId == null) {
            throw new SAMLException("No idp entityId found");
        }
        return idpEntityId;
    }

    /** {@inheritDoc} */
    @Override
    public String getEntityId() {
        val md = getEntityDescriptorElement();
        if (md instanceof EntitiesDescriptor) {
            return ((EntitiesDescriptor) md).getEntityDescriptors().get(0).getEntityID();
        }
        if (md instanceof EntityDescriptor) {
            return ((EntityDescriptor) md).getEntityID();
        }
        throw new SAMLException("No idp entityId found");
    }

    /** {@inheritDoc} */
    @Override
    public String getMetadata() {<FILL_FUNCTION_BODY>}

    /** {@inheritDoc} */
    @Override
    public final XMLObject getEntityDescriptorElement() {
        try {
            var idpEntityId = determineIdentityProviderEntityId();
            return resolve().resolveSingle(new CriteriaSet(new EntityIdCriterion(idpEntityId)));
        } catch (final ResolverException e) {
            throw new SAMLException("Error initializing idpMetadataProvider", e);
        }
    }
}

        if (getEntityDescriptorElement() != null) {
            return Configuration.serializeSamlObject(getEntityDescriptorElement()).toString();
        }
        throw new TechnicalException("Metadata cannot be retrieved because entity descriptor is null");
    
<methods>public non-sealed void <init>() ,public boolean hasChanged() ,public final org.opensaml.saml.metadata.resolver.MetadataResolver load() <variables>private static final long NO_LAST_MODIFIED,private final java.util.concurrent.atomic.AtomicBoolean byteArrayHasChanged,private long lastModified,protected org.opensaml.saml.metadata.resolver.MetadataResolver loaded,private final java.util.concurrent.locks.Lock lock,protected final non-sealed org.springframework.core.io.Resource resource