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

uk.gov.ida.saml.metadata.factories.MetadataTrustStoreProvider Maven / Gradle / Ivy

There is a newer version: 3.4.6-277
Show newest version
package uk.gov.ida.saml.metadata.factories;

import com.google.common.base.Throwables;
import uk.gov.ida.saml.metadata.KeyStoreLoader;
import uk.gov.ida.saml.metadata.exception.EmptyTrustStoreException;

import javax.inject.Provider;
import java.security.KeyStore;
import java.security.KeyStoreException;

public class MetadataTrustStoreProvider implements Provider {

    private KeyStoreLoader keyStoreLoader;
    private String uri;
    private String password;

    public MetadataTrustStoreProvider(KeyStoreLoader keyStoreLoader, String uri, String password) {
        this.keyStoreLoader = keyStoreLoader;
        this.uri = uri;
        this.password = password;
    }

    @Override
    public KeyStore get() {
        KeyStore trustStore = keyStoreLoader.load(uri, password);
        int trustStoreSize = 0;
        try {
            trustStoreSize = trustStore.size();
        } catch (KeyStoreException e) {
            Throwables.propagate(e);
        }
        if (trustStoreSize == 0) {
            throw new EmptyTrustStoreException();
        }
        return trustStore;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy