Class BasicCredential

java.lang.Object
se.swedenconnect.security.credential.AbstractPkiCredential
se.swedenconnect.security.credential.BasicCredential
All Implemented Interfaces:
PkiCredential

public class BasicCredential extends AbstractPkiCredential
A basic implementation of the PkiCredential interface.
Author:
Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
  • Constructor Details

    • BasicCredential

      public BasicCredential(@Nonnull KeyPair keyPair) throws IllegalArgumentException
      Constructor accepting a KeyPair.
      Parameters:
      keyPair - the key pair
      Throws:
      IllegalArgumentException - if key pair is not valid
    • BasicCredential

      public BasicCredential(@Nonnull PublicKey publicKey, @Nonnull PrivateKey privateKey) throws IllegalArgumentException
      Constructor setting the public and private keys.
      Parameters:
      publicKey - the public key
      privateKey - the private key
      Throws:
      IllegalArgumentException - if the public and private key does not make up a valid key pair
    • BasicCredential

      public BasicCredential(@Nonnull X509Certificate certificate, @Nonnull PrivateKey privateKey) throws IllegalArgumentException
      Constructor setting the certificate and private key.
      Parameters:
      certificate - the certificate
      privateKey - the private key
      Throws:
      IllegalArgumentException - if the public key from the certificate and private key does not make up a valid key pair
    • BasicCredential

      public BasicCredential(@Nonnull List<X509Certificate> certificates, @Nonnull PrivateKey privateKey)
      Constructor assigning a certificate chain and private key.
      Parameters:
      certificates - the certificate chain where the entity certificate is placed first
      privateKey - the private key
  • Method Details

    • getPrivateKey

      @Nonnull public PrivateKey getPrivateKey()
      Gets the private key.
      Returns:
      the private key
    • getCertificateChain

      @Nonnull public List<X509Certificate> getCertificateChain()
      Gets a certificate chain for the credential, where the first element is the entity certificate (PkiCredential.getCertificate()). If no certificate is configured for the credential an empty list is returned.
      Returns:
      a list of certificates, or an empty list
    • getStandalonePublicKey

      @Nullable protected PublicKey getStandalonePublicKey()
      Description copied from class: AbstractPkiCredential
      If a credential without a certificate is created, this method must be overridden and return the installed PublicKey.
      Overrides:
      getStandalonePublicKey in class AbstractPkiCredential
      Returns:
      the standalone public key, or null if a certificate is present
    • getDefaultName

      @Nonnull protected String getDefaultName()
      Gets the certificate serial number, and if no certificate is available a UUID is used.
      Specified by:
      getDefaultName in class AbstractPkiCredential
      Returns:
      the credential name