geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r232906 - in /geronimo/trunk/modules/security/src: java/org/apache/geronimo/security/ java/org/apache/geronimo/security/realm/providers/ test/org/apache/geronimo/security/
Date Mon, 15 Aug 2005 23:18:09 GMT
Author: djencks
Date: Mon Aug 15 16:18:03 2005
New Revision: 232906

URL: http://svn.apache.org/viewcvs?rev=232906&view=rev
Log:
GERONIMO-668. Introduce GeronimoCallerPrincipal interface, have GeronimoUserprincipal implement
it, and return it preferentially from the Subject for getCallerPrincipal.

Added:
    geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoCallerPrincipal.java
    geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/ContextManagerTest.java
Modified:
    geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/ContextManager.java
    geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoUserPrincipal.java

Modified: geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/ContextManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/ContextManager.java?rev=232906&r1=232905&r2=232906&view=diff
==============================================================================
--- geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/ContextManager.java
(original)
+++ geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/ContextManager.java
Mon Aug 15 16:18:03 2005
@@ -35,6 +35,8 @@
 import javax.security.auth.Subject;
 import javax.security.jacc.EJBRoleRefPermission;
 
+import org.apache.geronimo.security.realm.providers.GeronimoCallerPrincipal;
+
 
 /**
  * @version $Rev$ $Date$
@@ -208,14 +210,16 @@
         Context context = new Context();
         context.subject = subject;
         context.context = acc;
-        if (!subject.getPrincipals(PrimaryRealmPrincipal.class).isEmpty()) {
-            context.principal = (PrimaryRealmPrincipal) subject.getPrincipals(PrimaryRealmPrincipal.class).iterator().next();
-        } else if (!subject.getPrincipals(RealmPrincipal.class).isEmpty()) {
-            context.principal = (RealmPrincipal) subject.getPrincipals(RealmPrincipal.class).iterator().next();
-        } else if (!subject.getPrincipals().isEmpty()) {
-            context.principal = (Principal) subject.getPrincipals().iterator().next();
+        Set principals = subject.getPrincipals(GeronimoCallerPrincipal.class);
+        if (!principals.isEmpty()) {
+            context.principal = (Principal) principals.iterator().next();
+        } else if (!(principals = subject.getPrincipals(PrimaryRealmPrincipal.class)).isEmpty())
{
+            context.principal = (PrimaryRealmPrincipal) principals.iterator().next();
+        } else if (!(principals = subject.getPrincipals(RealmPrincipal.class)).isEmpty())
{
+            context.principal = (RealmPrincipal) principals.iterator().next();
+        } else if (!(principals = subject.getPrincipals()).isEmpty()) {
+            context.principal = (Principal) principals.iterator().next();
         }
-        //there are several RealmPrincipals.  Why pick the first out of a map?
         Long id = new Long(nextSubjectId++);
         context.id = new SubjectId(id, hash(id));
 

Added: geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoCallerPrincipal.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoCallerPrincipal.java?rev=232906&view=auto
==============================================================================
--- geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoCallerPrincipal.java
(added)
+++ geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoCallerPrincipal.java
Mon Aug 15 16:18:03 2005
@@ -0,0 +1,25 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.security.realm.providers;
+
+/**
+ * This is a marker interface used to indicate that a particular principal should be returned
from getCallerPrincipal().
+ *
+ * @version $Rev:  $ $Date:  $
+ */
+public interface GeronimoCallerPrincipal {
+}

Modified: geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoUserPrincipal.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoUserPrincipal.java?rev=232906&r1=232905&r2=232906&view=diff
==============================================================================
--- geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoUserPrincipal.java
(original)
+++ geronimo/trunk/modules/security/src/java/org/apache/geronimo/security/realm/providers/GeronimoUserPrincipal.java
Mon Aug 15 16:18:03 2005
@@ -26,7 +26,7 @@
  *
  * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
  */
-public class GeronimoUserPrincipal implements Principal, Serializable {
+public class GeronimoUserPrincipal implements Principal, Serializable, GeronimoCallerPrincipal
{
     private final String name;
 
     public GeronimoUserPrincipal(String name) {

Added: geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/ContextManagerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/ContextManagerTest.java?rev=232906&view=auto
==============================================================================
--- geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/ContextManagerTest.java
(added)
+++ geronimo/trunk/modules/security/src/test/org/apache/geronimo/security/ContextManagerTest.java
Mon Aug 15 16:18:03 2005
@@ -0,0 +1,47 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.security;
+
+import java.util.Set;
+import java.security.Principal;
+import javax.security.auth.Subject;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal;
+import org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class ContextManagerTest extends TestCase {
+
+    public void testGetCallerPrincipal() throws Exception {
+        Subject subject = new Subject();
+        GeronimoUserPrincipal userPrincipal = new GeronimoUserPrincipal("foo");
+        RealmPrincipal realmPrincipal = new RealmPrincipal("domain", userPrincipal);
+        PrimaryRealmPrincipal primaryRealmPrincipal = new PrimaryRealmPrincipal("domain",
userPrincipal);
+        GeronimoGroupPrincipal groupPrincipal = new GeronimoGroupPrincipal("bar");
+        Set principals = subject.getPrincipals();
+        principals.add(userPrincipal);
+        principals.add(realmPrincipal);
+        principals.add(primaryRealmPrincipal);
+        principals.add(groupPrincipal);
+        ContextManager.registerSubject(subject);
+        Principal principal = ContextManager.getCurrentPrincipal(subject);
+        assertSame("Expected GeronimoCallerPrincipal", userPrincipal, principal);
+    }
+}



Mime
View raw message