You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2015/01/21 16:31:14 UTC
karaf git commit: KARAF-3459 Checking for null
Repository: karaf
Updated Branches:
refs/heads/master 8e5cb54e2 -> 56d733b9e
KARAF-3459 Checking for null
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/56d733b9
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/56d733b9
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/56d733b9
Branch: refs/heads/master
Commit: 56d733b9eaabb1ab9b940253296bfee360654133
Parents: 8e5cb54
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Wed Jan 21 16:31:05 2015 +0100
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Wed Jan 21 16:31:05 2015 +0100
----------------------------------------------------------------------
.../properties/PropertiesLoginModule.java | 14 ++++++-----
.../properties/PropertiesLoginModuleTest.java | 25 ++++++++++++++++----
2 files changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/56d733b9/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 e7e2317..f5a6f67 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
@@ -78,12 +78,14 @@ public class PropertiesLoginModule extends AbstractKarafLoginModule {
callbacks[0] = new NameCallback("Username: ");
callbacks[1] = new PasswordCallback("Password: ", false);
- try {
- callbackHandler.handle(callbacks);
- } catch (IOException ioe) {
- throw new LoginException(ioe.getMessage());
- } catch (UnsupportedCallbackException uce) {
- throw new LoginException(uce.getMessage() + " not available to obtain information from user");
+ if (callbackHandler != null) {
+ try {
+ callbackHandler.handle(callbacks);
+ } catch (IOException ioe) {
+ throw new LoginException(ioe.getMessage());
+ } catch (UnsupportedCallbackException uce) {
+ throw new LoginException(uce.getMessage() + " not available to obtain information from user");
+ }
}
// user callback get value
if (((NameCallback) callbacks[0]).getName() == null) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/56d733b9/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java
index d9eaf97..37f6965 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java
@@ -27,12 +27,11 @@ import javax.security.auth.callback.*;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;
-import junit.framework.Assert;
-
import org.apache.felix.utils.properties.Properties;
import org.apache.karaf.jaas.boot.principal.GroupPrincipal;
import org.apache.karaf.jaas.boot.principal.RolePrincipal;
import org.apache.karaf.jaas.boot.principal.UserPrincipal;
+import org.junit.Assert;
import org.junit.Test;
public class PropertiesLoginModuleTest {
@@ -266,7 +265,7 @@ public class PropertiesLoginModuleTest {
Subject subject = new Subject();
CallbackHandler handler = new NullHandler();
Map<String, String> options = new HashMap<String, String>();
- options.put("users", this.getClass().getClassLoader().getResource("org/apache/karaf/jaas/modules/properties/test.properties").getFile());
+ options.put(PropertiesLoginModule.USER_FILE, getTestUsersFile());
module.initialize(subject, handler, null, options);
try {
@@ -282,9 +281,27 @@ public class PropertiesLoginModuleTest {
Subject sub = new Subject();
CallbackHandler handler = new NamePasswordHandler("test", "test");
Map<String, String> options = new HashMap<String, String>();
- options.put("users", usersFilePath);
+ options.put(PropertiesLoginModule.USER_FILE, usersFilePath);
module.initialize(sub, handler, null, options);
module.login();
}
+
+ @Test
+ public void testNullCallbackHandler() {
+ PropertiesLoginModule module = new PropertiesLoginModule();
+ Subject subject = new Subject();
+ Map<String, String> options = new HashMap<String, String>();
+ options.put(PropertiesLoginModule.USER_FILE, getTestUsersFile());
+ module.initialize(subject, null, null, options );
+ try {
+ module.login();
+ Assert.fail("LoginException expected");
+ } catch (LoginException e) {
+ Assert.assertEquals("Username can not be null", e.getMessage());
+ }
+ }
+ private String getTestUsersFile() {
+ return this.getClass().getClassLoader().getResource("org/apache/karaf/jaas/modules/properties/test.properties").getFile();
+ }
}