java.lang.Object
org.springframework.security.kerberos.test.MiniKdc

public class MiniKdc extends Object
Mini KDC based on Apache Directory Server that can be embedded in testcases or used from command line as a standalone KDC.

From within testcases:

MiniKdc sets one System property when started and un-set when stopped:

  • sun.security.krb5.debug: set to the debug value provided in the configuration
Because of this, multiple MiniKdc instances cannot be started in parallel. For example, running testcases in parallel that start a KDC each. To accomplish this a single MiniKdc should be used for all testcases running in parallel.

MiniKdc default configuration values are:

  • org.name=EXAMPLE (used to create the REALM)
  • org.domain=COM (used to create the REALM)
  • kdc.bind.address=localhost
  • kdc.port=0 (ephemeral port)
  • instance=DefaultKrbServer
  • max.ticket.lifetime=86400000 (1 day)
  • max.renewable.lifetime=604800000 (7 days)
  • transport=TCP
  • debug=false
The generated krb5.conf forces TCP connections.
  • Field Details

  • Constructor Details

    • MiniKdc

      public MiniKdc(Properties conf, File workDir) throws Exception
      Creates a MiniKdc.
      Parameters:
      conf - MiniKdc configuration.
      workDir - working directory, it should be the build directory. Under this directory an ApacheDS working directory will be created, this directory will be deleted when the MiniKdc stops.
      Throws:
      Exception - thrown if the MiniKdc could not be created.
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception
    • createConf

      public static Properties createConf()
      Convenience method that returns MiniKdc default configuration.

      The returned configuration is a copy, it can be customized before using it to create a MiniKdc.

      Returns:
      a MiniKdc default configuration.
    • setTransport

      public void setTransport(String transport)
    • getPort

      public int getPort()
      Returns the port of the MiniKdc.
      Returns:
      the port of the MiniKdc.
    • getHost

      public String getHost()
      Returns the host of the MiniKdc.
      Returns:
      the host of the MiniKdc.
    • getRealm

      public String getRealm()
      Returns the realm of the MiniKdc.
      Returns:
      the realm of the MiniKdc.
    • getKrb5conf

      public File getKrb5conf()
    • start

      public void start() throws Exception
      Starts the MiniKdc.
      Throws:
      Exception - thrown if the MiniKdc could not be started.
    • stop

      public void stop()
      Stops the MiniKdc
    • createPrincipal

      public void createPrincipal(String principal, String password) throws Exception
      Creates a principal in the KDC with the specified user and password.
      Parameters:
      principal - principal name, do not include the domain.
      password - password.
      Throws:
      Exception - thrown if the principal could not be created.
    • createPrincipal

      public void createPrincipal(File keytabFile, String... principals) throws Exception
      Creates multiple principals in the KDC and adds them to a keytab file.
      Parameters:
      keytabFile - keytab file to add the created principals.
      principals - principals to add to the KDC, do not include the domain.
      Throws:
      Exception - thrown if the principals or the keytab file could not be created.