class SAML2MongoMetadataGenerator extends BaseSAML2MetadataGenerator {
    private final MongoClient mongoClient;
    private final String entityId;

    private String metadataDatabase = "saml2";

    private String metadataCollection = "metadata";

    /** {@inheritDoc} */
    @Override
    public AbstractMetadataResolver createMetadataResolver() throws Exception {
        var documents = Objects.requireNonNull(getCollection().find(buildMetadataDocumentFilter(this.entityId)));
        var foundDoc = documents.first();
        if (foundDoc != null) {
            var metadata = foundDoc.getString("metadata");
            try (var is = new ByteArrayInputStream(metadata.getBytes(StandardCharsets.UTF_8))) {
                var document = Configuration.getParserPool().parse(is);
                var root = document.getDocumentElement();
                return new DOMMetadataResolver(root);
            }
        }
        throw new SAMLException("Unable to locate metadata document ");
    }

    /**
     * <p>buildMetadataDocumentFilter.</p>
     *
     * @param entityId a {@link String} object
     * @return a {@link Bson} object
     */
    protected Bson buildMetadataDocumentFilter(final String entityId) {
        return eq("entityId", entityId);
    }

    /** {@inheritDoc} */
    @Override
    public boolean storeMetadata(final String metadata, final boolean force) {<FILL_FUNCTION_BODY>}

    /**
     * <p>getCollection.</p>
     *
     * @return a {@link MongoCollection} object
     */
    protected MongoCollection<Document> getCollection() {
        val db = mongoClient.getDatabase(metadataDatabase);
        return Objects.requireNonNull(db.getCollection(metadataCollection));
    }
}

        if (CommonHelper.isBlank(metadata)) {
            logger.info("No metadata is provided");
            return false;
        }

        var metadataToUse = isSignMetadata() ? getMetadataSigner().sign(metadata) : metadata;
        CommonHelper.assertNotBlank("metadata", metadataToUse);

        var metadataEntityId = Configuration.deserializeSamlObject(metadataToUse)
            .map(EntityDescriptor.class::cast)
            .map(EntityDescriptor::getEntityID)
            .orElseThrow();
        if (!metadataEntityId.equals(this.entityId)) {
            throw new SAMLException("Entity id from metadata " + metadataEntityId
                + " does not match supplied entity id " + this.entityId);
        }

        var filter = buildMetadataDocumentFilter(metadataEntityId);
        var foundDoc = getCollection().find(filter).first();
        if (foundDoc == null) {
            val doc = new Document();
            doc.put("metadata", metadataToUse);
            doc.put("entityId", metadataEntityId);
            return getCollection().insertOne(doc).getInsertedId() != null;
        }
        foundDoc.put("metadata", metadataToUse);
        var updateResult = getCollection().updateOne(filter, new Document("$set", foundDoc));
        return updateResult.getMatchedCount() == 1;
    
<methods>public non-sealed void <init>() ,public org.opensaml.saml.saml2.metadata.EntityDescriptor buildEntityDescriptor() ,public org.opensaml.saml.metadata.resolver.MetadataResolver buildMetadataResolver() throws java.lang.Exception,public List<java.lang.String> getBlackListedSignatureSigningAlgorithms() ,public java.lang.String getMetadata(org.opensaml.saml.saml2.metadata.EntityDescriptor) throws java.lang.Exception,public List<java.lang.String> getSignatureAlgorithms() ,public List<java.lang.String> getSignatureReferenceDigestMethods() <variables>protected java.lang.String assertionConsumerServiceUrl,protected boolean authnRequestSigned,protected List<java.lang.String> blackListedSignatureSigningAlgorithms,protected final org.opensaml.core.xml.XMLObjectBuilderFactory builderFactory,private List<org.pac4j.saml.metadata.SAML2MetadataContactPerson> contactPersons,protected org.pac4j.saml.crypto.CredentialProvider credentialProvider,protected int defaultACSIndex,protected org.opensaml.xmlsec.SignatureSigningConfiguration defaultSignatureSigningConfiguration,protected java.lang.String entityId,protected final org.opensaml.xmlsec.algorithm.AlgorithmRegistry globalAlgorithmRegistry,protected final org.slf4j.Logger logger,protected final org.opensaml.core.xml.io.MarshallerFactory marshallerFactory,private org.pac4j.saml.metadata.SAML2MetadataSigner metadataSigner,private List<org.pac4j.saml.metadata.SAML2MetadataUIInfo> metadataUIInfos,protected java.lang.String nameIdPolicyFormat,protected java.lang.String requestInitiatorLocation,protected List<org.pac4j.saml.metadata.SAML2ServiceProviderRequestedAttribute> requestedAttributes,protected java.lang.String responseBindingType,protected boolean signMetadata,protected List<java.lang.String> signatureAlgorithms,protected List<java.lang.String> signatureReferenceDigestMethods,protected java.lang.String singleLogoutServiceUrl,private List<java.lang.String> supportedProtocols,protected boolean wantAssertionSigned