StardogAuthenticationException when running up a new embedded server after shutting down a previous one


We have some tests that use the embedded server and with Stardog 5.0 we are getting this exception: Authentication failed for account 'admin'

	at com.complexible.stardog.StardogKernel.login(
	at com.complexible.stardog.api.EmbeddedDriver.lambda$login$21(
	at com.complexible.stardog.api.EmbeddedDriver.login(
	at com.complexible.stardog.api.EmbeddedDriver.connectAdmin(
	at com.complexible.stardog.api.admin.AdminConnectionConfiguration.connect(
	at no.difi.einnsyn.stardog.EmbeddedStardogDatabase.createDatabase(
	at no.difi.einnsyn.stardog.AbstractStardogServiceTest.beforeClass(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.RunBefores.evaluate(
	at org.junit.internal.runners.statements.RunAfters.evaluate(
	at org.junit.rules.ExternalResource$1.evaluate(
	at org.junit.rules.RunRules.evaluate(
	at org.junit.runners.Suite.runChild(
	at org.junit.runners.Suite.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
	at com.intellij.rt.execution.junit.JUnitStarter.main(
Caused by: org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=false].  Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(
	at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(
	at org.apache.shiro.mgt.DefaultSecurityManager.login(
	at com.complexible.stardog.StardogKernel.login(
	... 34 more
Caused by: java.lang.IllegalStateException: IndexConnection must be open.
	at com.complexible.stardog.index.IndexConnectionImpl.assertOpen(
	at com.complexible.stardog.index.IndexConnectionImpl.getReader(
	at com.complexible.stardog.index.impl.DelegatingIndexConnection.getReader(
	at com.complexible.stardog.index.impl.DelegatingIndexConnection.getReader(
	at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(
	... 38 more

Here is our code for running up the embedded server:

    protected static EmbeddedStardogDatabase stardogDatabase;
    protected static Stardog server;

    protected static final String LICENSE_KEY = "stardog-license-key.bin";

    public static TemporaryFolder systemFolder;

    public static void beforeClass() throws Exception {
        systemFolder = new TemporaryFolder();

        FileUtils.copyFile(new File(LICENSE_KEY), new File(systemFolder.getRoot(), LICENSE_KEY));

        server = Stardog.builder()

        stardogDatabase = new EmbeddedStardogDatabase();




    public static void tearDown() throws Exception {

        if(stardogDatabase != null){
            stardogDatabase = null;

        if (server != null) {
            server = null;

Each test passes if run on its own, but once you have two tests in two different classes and run these together, @BeforeClass for the second class will fail.

Is there a solution for this? This is the only bug stopping us from switching to 5.0 beta for our development since it breaks our unit tests.

I think I might have stumbled upon something here:

Looks like calling shutdown on Stardog server will shutdown something internally (seems to be the Kernel) so that calling server = Stardog.builder().home(systemFolder.getRoot()).create(); will not unshutdown Stardog. Looks like there is some injector code running that provides a shared Kernel object, and there is no way of getting a new one even after shutdown().

There’s not really an embedded server anymore; note what you’re creating is Stardog itself, not a server.

The embedded mode assumes there’s just a single embedded stardog+server at use per JVM whereas before an entire new stardog+server stack was being created.

We’ll look at ways we can relax that restriction. In the meantime, you can simply create one Stardog and use it for all of the tests, or you can spin up HTTP servers and use HTTP.

Thanks for the reply Michael.

What I’ve ended up with is just never calling shutdown(). This seems to work fine since I’m deleting the home directory anyway.

I have the same problem. If there are two test classes I get the same exception.

It seems stardog do not free the resources when calling Shutdown().

Then when calling the code below a second time, the test crashes.

STARDOG = Stardog.builder().home(homedir).create();

	try (AdminConnection aConn = AdminConnectionConfiguration.toEmbeddedServer()
			.credentials("admin", "admin")
			.connect()) {
		if (aConn.list().contains(DB)) {


Any resolution for this?

If I’m understanding your code snippet correctly, you’re creating a new Stardog object each time. As I said in my earlier response, you cannot do that. Embedded mode operates under the assumption that there is a single instance of Stardog for the duration of the JVM.