You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/01/06 18:58:03 UTC

svn commit: r1055966 - in /activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security: FileGroupLoginModule.scala FileUserLoginModule.scala

Author: chirino
Date: Thu Jan  6 17:58:02 2011
New Revision: 1055966

URL: http://svn.apache.org/viewvc?rev=1055966&view=rev
Log:
Some minor cleanups.

Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileGroupLoginModule.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileUserLoginModule.scala

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileGroupLoginModule.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileGroupLoginModule.scala?rev=1055966&r1=1055965&r2=1055966&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileGroupLoginModule.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileGroupLoginModule.scala Thu Jan  6 17:58:02 2011
@@ -18,12 +18,9 @@ package org.apache.activemq.apollo.broke
  */
 import java.io.File
 import java.io.FileInputStream
-import java.io.IOException
 import java.security.Principal
-import java.util.Properties
 import javax.security.auth.Subject
 import javax.security.auth.callback.CallbackHandler
-import javax.security.auth.login.LoginException
 import javax.security.auth.spi.LoginModule
 
 import org.apache.activemq.jaas.GroupPrincipal
@@ -32,6 +29,7 @@ import java.{util => ju}
 import org.apache.activemq.apollo.util.{FileSupport, Log}
 import FileSupport._
 import java.util.regex.Pattern
+import java.util.{LinkedList, Properties}
 
 object FileGroupLoginModule extends Log {
   val LOGIN_CONFIG = "java.security.auth.login.config"
@@ -58,8 +56,7 @@ class FileGroupLoginModule extends Login
   private var subject: Subject = _
   private var file: File = _
 
-  private val groups = new Properties()
-  private val principals = new ju.HashSet[Principal]()
+  private val principals = new LinkedList[Principal]()
 
   def initialize(subject: Subject, callback_handler: CallbackHandler, shared_state: ju.Map[String, _], options: ju.Map[String, _]): Unit = {
     this.subject = subject
@@ -82,18 +79,22 @@ class FileGroupLoginModule extends Login
   }
 
   def login: Boolean = {
-    try {
-      groups.clear
+    false
+  }
+
+  def commit: Boolean = {
+
+    val groups = try {
       using( new FileInputStream(file) ) { in=>
+        val groups = new Properties()
         groups.load(in)
+        groups
       }
     } catch {
-      case ioe: IOException => throw new LoginException("Unable to load group properties file " + file)
+      case e: Throwable =>
+        warn(e, "Unable to load group properties file " + file)
+        return false;
     }
-    false
-  }
-
-  def commit: Boolean = {
 
     import collection.JavaConversions._
     val principles = subject.getPrincipals.filter(_.getClass.getName == match_kind).map(_.getName)
@@ -110,7 +111,6 @@ class FileGroupLoginModule extends Login
     }
 
     subject.getPrincipals().addAll(principals)
-
     debug("commit")
     return true
   }

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileUserLoginModule.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileUserLoginModule.scala?rev=1055966&r1=1055965&r2=1055966&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileUserLoginModule.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/security/FileUserLoginModule.scala Thu Jan  6 17:58:02 2011
@@ -57,8 +57,6 @@ class FileUserLoginModule extends LoginM
   private var callback_handler: CallbackHandler = _
 
   private var file: File = _
-  private val users = new Properties()
-  private var user: String = _
   private val principals = new ju.HashSet[Principal]()
 
   def initialize(subject: Subject, callback_handler: CallbackHandler, shared_state: ju.Map[String, _], options: ju.Map[String, _]): Unit = {
@@ -78,14 +76,16 @@ class FileUserLoginModule extends LoginM
   }
 
   def login: Boolean = {
+    val users = new Properties()
     try {
-      users.clear()
       using( new FileInputStream(file) ) { in=>
         users.load(in)
       }
       EncryptionSupport.decrypt(users)
     } catch {
-      case ioe: IOException => throw new LoginException("Unable to load user properties file " + file)
+      case e: Throwable =>
+        warn(e, "Unable to load user properties file: " + file)
+        return false
     }
 
     val callbacks = new Array[Callback](2)
@@ -100,7 +100,7 @@ class FileUserLoginModule extends LoginM
         throw new LoginException(uce.getMessage() + " not available to obtain information from user")
     }
 
-    user = callbacks(0).asInstanceOf[NameCallback].getName()
+    val user = callbacks(0).asInstanceOf[NameCallback].getName()
     var tmpPassword = callbacks(1).asInstanceOf[PasswordCallback].getPassword()
     if (tmpPassword == null) {
       tmpPassword = new Array[Char](0)
@@ -110,21 +110,20 @@ class FileUserLoginModule extends LoginM
     if (password == null || !password.equals(new String(tmpPassword))) {
       throw new FailedLoginException("Invalid user id or password")
     }
+
+    principals.add(new UserPrincipal(user))
     debug("login %s", user)
     true
   }
 
   def commit: Boolean = {
-    principals.add(new UserPrincipal(user))
     subject.getPrincipals().addAll(principals)
-
-    user = null
     debug("commit")
     return true
   }
 
   def abort: Boolean = {
-    user = null
+    principals.clear
     debug("abort")
     return true
   }
@@ -132,7 +131,6 @@ class FileUserLoginModule extends LoginM
   def logout: Boolean = {
     subject.getPrincipals().removeAll(principals)
     principals.clear
-    user = null
     debug("logout")
     return true
   }