no.ks.fiks.maskinporten.MaskinportenAutoConfigure Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fiks-maskinporten-spring-boot-client Show documentation
Show all versions of fiks-maskinporten-spring-boot-client Show documentation
fiks-maskinporten-spring-boot-client
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());
}
}