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

no.ks.fiks.maskinporten.MaskinportenAutoConfigure Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package no.ks.fiks.maskinporten;

import no.ks.fiks.virksomhetsertifikat.VirksomhetSertifikater;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateEncodingException;

@Configuration
@EnableConfigurationProperties({MaskinportenProperties.class})
public class MaskinportenAutoConfigure {

    @Bean
    public Maskinportenklient getMaskinportenklient(MaskinportenProperties properties, VirksomhetSertifikater virksomhetSertifikater) throws UnrecoverableKeyException, CertificateEncodingException, NoSuchAlgorithmException, KeyStoreException {
        VirksomhetSertifikater.KsVirksomhetSertifikatStore authKeyStore = virksomhetSertifikater.requireAuthKeyStore();

        return new Maskinportenklient(authKeyStore.getKeyStore(), MaskinportenklientProperties.builder()
                .privateKeyPassword(authKeyStore.getPrivateKeyPassword())
                .privateKeyAlias(authKeyStore.getPrivateKeyAlias())
                .numberOfSecondsLeftBeforeExpire(properties.getNumberOfSecondsLeftBeforeExpire())
                .issuer(properties.getIssuer())
                .audience(properties.getAudience())
                .tokenEndpoint(properties.getTokenEndpoint())
                .build());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy