From 3a0e43337ce8ab8b43571b9acf877900b2670034 Mon Sep 17 00:00:00 2001
From: Ben Alex
-{ * {@link JaasAuthenticationCallbackHandler}s are passed to the + * {{@link JaasAuthenticationCallbackHandler}s are passed to the * JaasAuthenticationProvider through the {@link * #setCallbackHandlers(net.sf.acegisecurity.providers.jaas.JaasAuthenticationCallbackHandler[]) - * callbackHandlers} property. -} *
+ * callbackHandlers} property. }
+ *
* <property name="callbackHandlers">
* <list>
* <bean class="net.sf.acegisecurity.providers.jaas.TestCallbackHandler"/>
@@ -255,7 +255,7 @@ public class JaasAuthenticationProvider implements AuthenticationProvider,
+ getClass());
}
- if (loginContextName == null) {
+ if ((loginContextName == null) || "".equals(loginContextName)) {
throw new ApplicationContextException(
"loginContextName must be set on " + getClass());
}
diff --git a/core/src/test/java/org/acegisecurity/providers/jaas/JaasAuthenticationProviderTests.java b/core/src/test/java/org/acegisecurity/providers/jaas/JaasAuthenticationProviderTests.java
index 6265a693d2..bb30055643 100644
--- a/core/src/test/java/org/acegisecurity/providers/jaas/JaasAuthenticationProviderTests.java
+++ b/core/src/test/java/org/acegisecurity/providers/jaas/JaasAuthenticationProviderTests.java
@@ -21,9 +21,11 @@ import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.AuthenticationException;
import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
+import net.sf.acegisecurity.providers.TestingAuthenticationToken;
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Arrays;
@@ -71,6 +73,46 @@ public class JaasAuthenticationProviderTests extends TestCase {
assertNull("Success event was fired", eventCheck.successEvent);
}
+ public void testDetectsMissingLoginConfig() throws Exception {
+ JaasAuthenticationProvider myJaasProvider = new JaasAuthenticationProvider();
+ myJaasProvider.setApplicationContext(context);
+ myJaasProvider.setAuthorityGranters(jaasProvider.getAuthorityGranters());
+ myJaasProvider.setCallbackHandlers(jaasProvider.getCallbackHandlers());
+ myJaasProvider.setLoginContextName(jaasProvider.getLoginContextName());
+
+ try {
+ myJaasProvider.afterPropertiesSet();
+ fail("Should have thrown ApplicationContextException");
+ } catch (ApplicationContextException expected) {
+ assertTrue(expected.getMessage().startsWith("loginConfig must be set on"));
+ }
+ }
+
+ public void testDetectsMissingLoginContextName() throws Exception {
+ JaasAuthenticationProvider myJaasProvider = new JaasAuthenticationProvider();
+ myJaasProvider.setApplicationContext(context);
+ myJaasProvider.setAuthorityGranters(jaasProvider.getAuthorityGranters());
+ myJaasProvider.setCallbackHandlers(jaasProvider.getCallbackHandlers());
+ myJaasProvider.setLoginConfig(jaasProvider.getLoginConfig());
+ myJaasProvider.setLoginContextName(null);
+
+ try {
+ myJaasProvider.afterPropertiesSet();
+ fail("Should have thrown ApplicationContextException");
+ } catch (ApplicationContextException expected) {
+ assertTrue(expected.getMessage().startsWith("loginContextName must be set on"));
+ }
+
+ myJaasProvider.setLoginContextName("");
+
+ try {
+ myJaasProvider.afterPropertiesSet();
+ fail("Should have thrown ApplicationContextException");
+ } catch (ApplicationContextException expected) {
+ assertTrue(expected.getMessage().startsWith("loginContextName must be set on"));
+ }
+ }
+
public void testFull() throws Exception {
GrantedAuthorityImpl role1 = new GrantedAuthorityImpl("ROLE_1");
GrantedAuthorityImpl role2 = new GrantedAuthorityImpl("ROLE_2");
@@ -123,6 +165,12 @@ public class JaasAuthenticationProviderTests extends TestCase {
assertNull("Failure event was fired", eventCheck.failedEvent);
}
+ public void testUnsupportedAuthenticationObjectReturnsNull() {
+ assertNull(jaasProvider.authenticate(
+ new TestingAuthenticationToken("foo", "bar",
+ new GrantedAuthority[] {})));
+ }
+
protected void setUp() throws Exception {
String resName = "/" + getClass().getName().replace('.', '/') + ".xml";
context = new ClassPathXmlApplicationContext(resName);