geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r643431 - in /geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security: ContextManager.java SubjectId.java
Date Tue, 01 Apr 2008 15:06:10 GMT
Author: dwoods
Date: Tue Apr  1 08:05:55 2008
New Revision: 643431

URL: http://svn.apache.org/viewvc?rev=643431&view=rev
Log:
GERONIMO-3913 - NPE in org.apache.geronimo.security.SubjectId.hashCode() caused by incorrect
JAVA_HOME or JRE_HOME.  Patch from Toby Cabot.

Modified:
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/ContextManager.java
    geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/SubjectId.java

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/ContextManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/ContextManager.java?rev=643431&r1=643430&r2=643431&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/ContextManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/ContextManager.java
Tue Apr  1 08:05:55 2008
@@ -24,6 +24,7 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
 import java.security.PrivilegedAction;
+import java.security.ProviderException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.IdentityHashMap;
@@ -260,8 +261,13 @@
             context.principal = principals.iterator().next();
         }
         Long id = nextSubjectId++;
-        context.id = new SubjectId(id, hash(id));
-
+        try {
+            context.id = new SubjectId(id, hash(id));
+        } catch (NoSuchAlgorithmException e) {
+            throw new ProviderException("No such algorithm: " + algorithm + ".  This can
be caused by a misconfigured java.ext.dirs, JAVA_HOME or JRE_HOME environment variable");
+        } catch (InvalidKeyException e) {
+            throw new ProviderException("Invalid key: " + key.toString());
+        }
         subjectIds.put(context.id, subject);
         subjectContexts.put(subject, context);
 
@@ -333,8 +339,10 @@
             mac.init(key);
         } catch (NoSuchAlgorithmException e) {
             assert false : "Should never have reached here";
+            throw new ProviderException("No such algorithm: " + algorithm + ".  This can
be caused by a misconfigured java.ext.dirs, JAVA_HOME or JRE_HOME environment variable.");
         } catch (InvalidKeyException e) {
             assert false : "Should never have reached here";
+            throw new ProviderException("Invalid key: " + key.toString());
         }
     }
 
@@ -354,7 +362,7 @@
         key = new SecretKeySpec(password.getBytes(), algorithm);
     }
 
-    private static byte[] hash(Long id) {
+    private static byte[] hash(Long id) throws NoSuchAlgorithmException, InvalidKeyException
{
         long n = id;
         byte[] bytes = new byte[8];
         for (int i = 7; i >= 0; i--) {
@@ -362,19 +370,11 @@
             n >>>= 8;
         }
 
-        try {
-            Mac mac = Mac.getInstance(algorithm);
-            mac.init(key);
-            mac.update(bytes);
+        Mac mac = Mac.getInstance(algorithm);
+        mac.init(key);
+        mac.update(bytes);
 
-            return mac.doFinal();
-        } catch (NoSuchAlgorithmException e) {
-            //shouldn't happen
-        } catch (InvalidKeyException e) {
-            //shouldn't happen
-        }
-        assert false : "Should never have reached here";
-        return null;
+        return mac.doFinal();
     }
 
     private static class Context {

Modified: geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/SubjectId.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/SubjectId.java?rev=643431&r1=643430&r2=643431&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/SubjectId.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/SubjectId.java
Tue Apr  1 08:05:55 2008
@@ -30,6 +30,9 @@
     private transient String name;
 
     public SubjectId(Long subjectId, byte[] hash) {
+        if (subjectId == null) throw new IllegalArgumentException("subjectId cannot be null");
+        if (hash == null) throw new IllegalArgumentException("hash cannot be null");
+
         this.subjectId = subjectId;
         this.hash = hash;
     }



Mime
View raw message