You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/10/08 15:35:38 UTC

svn commit: r1530270 - in /karaf/branches/karaf-2.x/jaas/modules/src: main/java/org/apache/karaf/jaas/modules/properties/ test/java/org/apache/karaf/jaas/modules/properties/ test/resources/ test/resources/org/ test/resources/org/apache/ test/resources/...

Author: jbonofre
Date: Tue Oct  8 13:35:37 2013
New Revision: 1530270

URL: http://svn.apache.org/r1530270
Log:
[KARAF-2497] Test if username and password are null in the PropertiesLoginModule and throw a LoginException

Added:
    karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NullHandler.java
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/properties/
    karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/properties/test.properties
Modified:
    karaf/branches/karaf-2.x/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
    karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NamePasswordHandler.java
    karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java

Modified: karaf/branches/karaf-2.x/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java?rev=1530270&r1=1530269&r2=1530270&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java (original)
+++ karaf/branches/karaf-2.x/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModule.java Tue Oct  8 13:35:37 2013
@@ -80,8 +80,14 @@ public class PropertiesLoginModule exten
             throw new LoginException(uce.getMessage() + " not available to obtain information from user");
         }
         // user callback get value
+        if (((NameCallback) callbacks[0]).getName() == null) {
+            throw new LoginException("Username can not be null");
+        }
         user = ((NameCallback) callbacks[0]).getName();
         // password callback get value
+        if (((PasswordCallback) callbacks[1]).getPassword() == null) {
+            throw new LoginException("Password can not be null");
+        }
         String password = new String(((PasswordCallback) callbacks[1]).getPassword());
 
         // user infos container read from the users properties file

Modified: karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NamePasswordHandler.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NamePasswordHandler.java?rev=1530270&r1=1530269&r2=1530270&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NamePasswordHandler.java (original)
+++ karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NamePasswordHandler.java Tue Oct  8 13:35:37 2013
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.karaf.jaas.modules.properties;
 
 import java.io.IOException;

Added: karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NullHandler.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NullHandler.java?rev=1530270&view=auto
==============================================================================
--- karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NullHandler.java (added)
+++ karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/NullHandler.java Tue Oct  8 13:35:37 2013
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jaas.modules.properties;
+
+import javax.security.auth.callback.*;
+import java.io.IOException;
+
+public class NullHandler implements CallbackHandler {
+
+    @Override
+    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+        for (Callback callback : callbacks) {
+            if (callback instanceof NameCallback) {
+                NameCallback nameCallback = (NameCallback) callback;
+                nameCallback.setName("test");
+            } else if (callback instanceof PasswordCallback) {
+                PasswordCallback passwordCallback = (PasswordCallback) callback;
+                passwordCallback.setPassword(null);
+            }
+        }
+    }
+
+}

Modified: karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java?rev=1530270&r1=1530269&r2=1530270&view=diff
==============================================================================
--- karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java (original)
+++ karaf/branches/karaf-2.x/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/properties/PropertiesLoginModuleTest.java Tue Oct  8 13:35:37 2013
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.karaf.jaas.modules.properties;
 
 import java.io.IOException;
@@ -14,6 +30,7 @@ import junit.framework.Assert;
 import org.junit.Test;
 
 public class PropertiesLoginModuleTest {
+
     @Test
     public void testNullUsersFile() {
         try {
@@ -33,6 +50,23 @@ public class PropertiesLoginModuleTest {
         }
     }
 
+    @Test
+    public void testNullPassword() throws Exception {
+        PropertiesLoginModule module = new PropertiesLoginModule();
+        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());
+        module.initialize(subject, handler, null, options);
+
+        try {
+            module.login();
+            Assert.fail("LoginException expected");
+        } catch (LoginException e) {
+            Assert.assertEquals("Password can not be null", e.getMessage());
+        }
+    }
+
     private void testWithUsersFile(String usersFilePath) throws LoginException {
         PropertiesLoginModule module = new PropertiesLoginModule();
         Subject sub = new Subject();
@@ -42,4 +76,5 @@ public class PropertiesLoginModuleTest {
         module.initialize(sub, handler, null, options);
         module.login();
     }
+
 }

Added: karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/properties/test.properties
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/properties/test.properties?rev=1530270&view=auto
==============================================================================
--- karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/properties/test.properties (added)
+++ karaf/branches/karaf-2.x/jaas/modules/src/test/resources/org/apache/karaf/jaas/modules/properties/test.properties Tue Oct  8 13:35:37 2013
@@ -0,0 +1 @@
+test=test,test
\ No newline at end of file