Repository: karaf Updated Branches: refs/heads/karaf-2.x e5453482f -> 1bd45b3c7
[KARAF-2910]add a testcase Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1bd45b3c Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1bd45b3c Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1bd45b3c Branch: refs/heads/karaf-2.x Commit: 1bd45b3c7d3474dcbc8a9a03a31e7335b53adda7 Parents: e545348 Author: Freeman Fang <[email protected]> Authored: Tue Apr 15 16:16:54 2014 +0800 Committer: Freeman Fang <[email protected]> Committed: Tue Apr 15 16:16:54 2014 +0800 ---------------------------------------------------------------------- .../java/org/apache/karaf/itests/JaasTest.java | 53 ++++++++++++++++++++ .../properties/PropertiesLoginModule.java | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/1bd45b3c/itests/src/test/java/org/apache/karaf/itests/JaasTest.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/apache/karaf/itests/JaasTest.java b/itests/src/test/java/org/apache/karaf/itests/JaasTest.java index b1fa7dd..d00bfe8 100644 --- a/itests/src/test/java/org/apache/karaf/itests/JaasTest.java +++ b/itests/src/test/java/org/apache/karaf/itests/JaasTest.java @@ -14,13 +14,28 @@ package org.apache.karaf.itests; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import java.io.IOException; +import javax.inject.Inject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.LoginContext; +import org.apache.felix.fileinstall.ArtifactInstaller; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerMethod; +import org.osgi.framework.BundleContext; + + @RunWith(PaxExam.class) @ExamReactorStrategy(PerMethod.class) public class JaasTest extends KarafTestSupport { @@ -33,4 +48,42 @@ public class JaasTest extends KarafTestSupport { assertTrue(listRealmsOutput.contains("PublickeyLoginModule")); } + @Ignore + //ignore it as this is too time consuming + public void testLoginNoLeak() throws Exception { + for (int i = 0; i<200000; i++) { + doLogin(); + } + } + + @Inject + protected BundleContext bundleContext; + + @Test // shows the leak afaics + public void testLoginSingleReg() throws Exception { + for (int i=0; i<10; i++) { + doLogin(); + } + assertEquals(3, bundleContext.getServiceReferences(ArtifactInstaller.class.getName(), null).length); + } + + private void doLogin() throws Exception { + final String userPassRealm = "karaf"; + LoginContext lc = new LoginContext(userPassRealm, new CallbackHandler() { + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + Callback callback = callbacks[i]; + if (callback instanceof PasswordCallback) { + PasswordCallback passwordCallback = (PasswordCallback)callback; + passwordCallback.setPassword(userPassRealm.toCharArray()); + } else if (callback instanceof NameCallback) { + NameCallback nameCallback = (NameCallback)callback; + nameCallback.setName(userPassRealm); + } + } + } + }); + lc.login(); + assertNotNull(lc.getSubject()); + } } http://git-wip-us.apache.org/repos/asf/karaf/blob/1bd45b3c/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java ---------------------------------------------------------------------- diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java index a31adeb..8afe51e 100644 --- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java +++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java @@ -62,7 +62,7 @@ public class PropertiesLoginModule extends AbstractKarafLoginModule { if (propertiesInstaller == null || !usersFile.equals(propertiesInstaller.getUsersFileName()) ) { - LOG.debug("Register PropertiesInstaller service"); + LOGGER.debug("Register PropertiesInstaller service"); propertiesInstaller = new PropertiesInstaller(this, usersFile); if (this.bundleContext != null) {
