[jboss-cvs] JBossAS SVN: r65859 - in projects/metadata/trunk/src: main/java/org/jboss/metadata/ejb/jboss and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 4 18:05:39 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-10-04 18:05:38 -0400 (Thu, 04 Oct 2007)
New Revision: 65859

Added:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/SecurityRoleNames.java
Removed:
   projects/metadata/trunk/src/main/java/org/jboss/security/AnybodyPrincipal.java
   projects/metadata/trunk/src/main/java/org/jboss/security/NobodyPrincipal.java
   projects/metadata/trunk/src/main/java/org/jboss/security/SimplePrincipal.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/BeanMetaData.java
   projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar21UnitTestCase.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/javaee/AbstractJavaEEEverythingTest.java
Log:
Drop the prinipcal implementations and use Set<String> for the method permissions

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/BeanMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/BeanMetaData.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/BeanMetaData.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -446,10 +446,10 @@
     * @param methodName the method name
     * @param params the parameters
     * @param iface the interface
-    * @return The Set<Principal> for the application domain roles that
+    * @return The Set<String> for the application domain roles that
     *         caller principal's are to be validated against.
     */
-   public Set<Principal> getMethodPermissions(String methodName, Class[] params, InvocationType iface)
+   public Set<String> getMethodPermissions(String methodName, Class[] params, InvocationType iface)
    {
       return getDelegate().getMethodPermissions(methodName, params, invocationTypeToMethodInterfaceType(iface));
    }

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/JBossEnterpriseBeanMetaData.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -22,7 +22,6 @@
 package org.jboss.metadata.ejb.jboss;
 
 import java.lang.reflect.Method;
-import java.security.Principal;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -60,9 +59,6 @@
 import org.jboss.metadata.javaee.support.AbstractMappedMetaData;
 import org.jboss.metadata.javaee.support.NamedMetaDataWithDescriptionGroupWithOverride;
 import org.jboss.metadata.javaee.support.NonNullLinkedHashSet;
-import org.jboss.security.AnybodyPrincipal;
-import org.jboss.security.NobodyPrincipal;
-import org.jboss.security.SimplePrincipal;
 import org.jboss.xb.annotations.JBossXmlConstants;
 import org.jboss.xb.annotations.JBossXmlModelGroup;
 
@@ -906,11 +902,11 @@
     * @param methodName the method name
     * @param params the parameters
     * @param interfaceType the interface type
-    * @return The Set<Principal> for the application domain roles that caller principal's are to be validated against.
+    * @return The Set<String> for the application domain roles that caller principal's are to be validated against.
     */
-   public Set<Principal> getMethodPermissions(String methodName, Class[] params, MethodInterfaceType interfaceType)
+   public Set<String> getMethodPermissions(String methodName, Class[] params, MethodInterfaceType interfaceType)
    {
-      Set<Principal> result = null;
+      Set<String> result = null;
 
       EnterpriseBeanMetaData ejb = getOverridenMetaDataWithCheck();
       JBossMetaData jbossMetaData = getJBossMetaDataWithCheck();
@@ -925,8 +921,8 @@
          // We don't return null to differentiate between an explicit
          // assignment of no access and no assignment information.
          if (result == null)
-            result = new HashSet<Principal>();
-         result.add(NobodyPrincipal.NOBODY_PRINCIPAL);
+            result = new HashSet<String>();
+         result.add(SecurityRoleNames.NOBODY_PRINCIPAL);
          return result;
       }
 
@@ -940,7 +936,7 @@
             {
                if (result != null)
                   result.clear();
-               result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
+               result.add(SecurityRoleNames.ANYBODY_PRINCIPAL);
                break;
             }
             else if (permission.matches(methodName, params, interfaceType))
@@ -949,7 +945,7 @@
                if (roles != null)
                {
                   if (result == null)
-                     result = new HashSet<Principal>();
+                     result = new HashSet<String>();
                   for (String roleName : roles)
                   {
                      // Get any extra principal names assigned to the role
@@ -958,11 +954,11 @@
                      {
                         for (String principal : principals)
                         {
-                           result.add(new SimplePrincipal(principal));
+                           result.add(principal);
                         }
                      }
                      // Also add the role name itself
-                     result.add(new SimplePrincipal(roleName));
+                     result.add(roleName);
                   }
                }
             }
@@ -971,8 +967,8 @@
 
       if (jbossMetaData.isExcludeMissingMethods() == false && result == null)
       {
-            result = new HashSet<Principal>();
-            result.add(AnybodyPrincipal.ANYBODY_PRINCIPAL);
+            result = new HashSet<String>();
+            result.add(SecurityRoleNames.ANYBODY_PRINCIPAL);
       }
 
       if (result == null)

Added: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/SecurityRoleNames.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/SecurityRoleNames.java	                        (rev 0)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/SecurityRoleNames.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metadata.ejb.jboss;
+
+/**
+ * Constants for the well known security role/principal names.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface SecurityRoleNames
+{
+   /** The principal name representing a principal that matches no one */
+   public static final String NOBODY_PRINCIPAL = "<NOBODY>";
+   /** The principal name representing a principal that matches anyone */
+   public static final String ANYBODY_PRINCIPAL = "<ANYBODY>";
+}


Property changes on: projects/metadata/trunk/src/main/java/org/jboss/metadata/ejb/jboss/SecurityRoleNames.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native

Deleted: projects/metadata/trunk/src/main/java/org/jboss/security/AnybodyPrincipal.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/security/AnybodyPrincipal.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/main/java/org/jboss/security/AnybodyPrincipal.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -1,82 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security;
-
-import java.security.Principal;
-
-/** An implementation of Principal and Comparable that represents any role.
-Any Principal or name of a Principal when compared to an AnybodyPrincipal
-using {@link #equals(Object) equals} or {@link #compareTo(Object) compareTo} 
-will always be found equals to the AnybodyPrincipal.
-
-Note that this class is not likely to operate correctly in a collection
-since the hashCode() and equals() methods are not correlated.
-
- at author Scott.Stark at jboss.org
- at version $Revision: 40149 $
-*/
-public class AnybodyPrincipal implements Comparable, Principal
-{
-    public static final String ANYBODY = "<ANYBODY>";
-    public static final AnybodyPrincipal ANYBODY_PRINCIPAL = new AnybodyPrincipal();
-
-    public int hashCode()
-    {
-        return ANYBODY.hashCode();
-    }
-
-    /**
-    @return "<ANYBODY>"
-    */
-    public String getName()
-    {
-        return ANYBODY;
-    }
-
-    public String toString()
-    {
-        return ANYBODY;
-    }
-    
-    /** This method always returns 0 to indicate equality for any argument.
-    This is only meaningful when comparing against other Principal objects
-     or names of Principals.
-
-    @return true to indicate equality for any argument.
-    */
-    public boolean equals(Object another)
-    {
-        return true;
-    }
-
-    /** This method always returns 0 to indicate equality for any argument.
-    This is only meaningful when comparing against other Principal objects
-     or names of Principals.
-
-    @return 0 to indicate equality for any argument.
-    */
-    public int compareTo(Object o)
-    {
-        return 0;
-    }
-
-}

Deleted: projects/metadata/trunk/src/main/java/org/jboss/security/NobodyPrincipal.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/security/NobodyPrincipal.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/main/java/org/jboss/security/NobodyPrincipal.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -1,82 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security;
-
-import java.security.Principal;
-
-/** An implementation of Principal and Comparable that represents no role.
-Any Principal or name of a Principal when compared to an NobodyPrincipal
-using {@link #equals(Object) equals} or {@link #compareTo(Object) compareTo} 
-will always be found not equal to the NobodyPrincipal.
-
-Note that this class is not likely to operate correctly in a collection
-since the hashCode() and equals() methods are not correlated.
-
- at author Scott.Stark at jboss.org
- at version $Revision: 40149 $
-*/
-public class NobodyPrincipal implements Comparable, Principal
-{
-    public static final String NOBODY = "<NOBODY>";
-    public static final NobodyPrincipal NOBODY_PRINCIPAL = new NobodyPrincipal();
-
-    public int hashCode()
-    {
-        return NOBODY.hashCode();
-    }
-
-    /**
-    @return "<NOBODY>"
-    */
-    public String getName()
-    {
-        return NOBODY;
-    }
-
-    public String toString()
-    {
-        return NOBODY;
-    }
-    
-    /** This method always returns 0 to indicate equality for any argument.
-    This is only meaningful when comparing against other Principal objects
-     or names of Principals.
-
-    @return false to indicate inequality for any argument.
-    */
-    public boolean equals(Object another)
-    {
-        return false;
-    }
-
-    /** This method always returns 1 to indicate inequality for any argument.
-    This is only meaningful when comparing against other Principal objects
-     or names of Principals.
-
-    @return 1 to indicate inequality for any argument.
-    */
-    public int compareTo(Object o)
-    {
-        return 1;
-    }
-
-}

Deleted: projects/metadata/trunk/src/main/java/org/jboss/security/SimplePrincipal.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/security/SimplePrincipal.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/main/java/org/jboss/security/SimplePrincipal.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -1,75 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security;
-
-import java.security.Principal;
-
-/**
- * A simple String based implementation of Principal. Typically a
- * SimplePrincipal is created given a userID which is used as the Principal
- * name.
- * @author <a href="on at ibis.odessa.ua">Oleg Nitz</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision: 40149 $
- */
-public class SimplePrincipal implements Principal, java.io.Serializable
-{
-   static final long serialVersionUID = 7701951188631723261L;
-   private String name;
-
-   public SimplePrincipal(String name)
-   {
-      this.name = name;
-   }
-
-   /**
-    * Compare this SimplePrincipal's name against another Principal
-    * @return true if name equals another.getName();
-    */
-   public boolean equals(Object another)
-   {
-      if (!(another instanceof Principal))
-         return false;
-      String anotherName = ((Principal) another).getName();
-      boolean equals = false;
-      if (name == null)
-         equals = anotherName == null;
-      else
-         equals = name.equals(anotherName);
-      return equals;
-   }
-
-   public int hashCode()
-   {
-      return (name == null ? 0 : name.hashCode());
-   }
-
-   public String toString()
-   {
-      return name;
-   }
-
-   public String getName()
-   {
-      return name;
-   }
-} 

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar21UnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar21UnitTestCase.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar21UnitTestCase.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -22,12 +22,21 @@
 package org.jboss.test.metadata.ejb;
 
 import java.math.BigDecimal;
+import java.security.Principal;
+import java.util.Set;
 
 import junit.framework.Test;
 
+import org.jboss.invocation.InvocationType;
 import org.jboss.metadata.ApplicationMetaData;
+import org.jboss.metadata.BeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData;
 import org.jboss.metadata.ejb.spec.EjbJar21MetaData;
 import org.jboss.metadata.ejb.spec.EjbJar2xMetaData;
+import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
 import org.jboss.test.metadata.javaee.AbstractJavaEEMetaDataTest;
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
 
@@ -75,4 +84,39 @@
       assertTrue(old.isEJB21());
       assertFalse(old.isEJB3x());
    }
+   public void testMethodPermissions()
+      throws Exception
+   {
+      EjbJar2xMetaData result = unmarshal();
+      JBossMetaData jbossMetaData = new JBossMetaData();
+      jbossMetaData.setOverridenMetaData(result);
+      ApplicationMetaData appData = new ApplicationMetaData(jbossMetaData);
+
+      // Validate the assembly descriptor permissions
+      AssemblyDescriptorMetaData admd = result.getAssemblyDescriptor();
+      MethodPermissionsMetaData allPerms = admd.getMethodPermissions();
+      assertEquals("ejb-jar has 4 method-permissions", 4, allPerms.size());
+
+      // Validate StatelessSession bean permission count
+      EnterpriseBeanMetaData ebmd = result.getEnterpriseBeans().get("StatelessSession");
+      MethodPermissionsMetaData beanPerms = ebmd.getMethodPermissions();
+      assertEquals("StatelessSession has 3 method-permissions", 3, beanPerms.size());
+
+      // Now validate the method matching logic
+      String echo = "Echo";
+      String echoLocal = "EchoLocal";
+      String internal = "InternalRole";
+
+      BeanMetaData ss = appData.getBeanByEjbName("StatelessSession");
+      Class[] sig = {};
+      Set<String> perms = ss.getMethodPermissions("create", sig, InvocationType.HOME);
+      getLog().debug("home create perms: "+perms);
+      assertTrue("Echo can invoke StatelessSessionHome.create", perms.contains(echo));
+      assertTrue("EchoLocal cannot invoke StatelessSessionHome.create", perms.contains(echoLocal) == false);
+
+      perms = ss.getMethodPermissions("create", sig, InvocationType.LOCALHOME);
+      getLog().debug("local home create perms: "+perms);
+      assertTrue("Echo can invoke StatelessSessionLocalHome.create", perms.contains(echo));
+      assertTrue("EchoLocal can invoke StatelessSessionLocalHome.create", perms.contains(echoLocal));
+   }
 }

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/javaee/AbstractJavaEEEverythingTest.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/javaee/AbstractJavaEEEverythingTest.java	2007-10-04 20:05:24 UTC (rev 65858)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/javaee/AbstractJavaEEEverythingTest.java	2007-10-04 22:05:38 UTC (rev 65859)
@@ -208,6 +208,12 @@
       assertEquals(prefix + "RoleName", securityRoleMetaData.getRoleName());
    }
 
+   /**
+    * 
+    * @param prefix
+    * @param size
+    * @param principals
+    */
    protected void assertPrincipals(String prefix, int size, Set<String> principals)
    {
       assertNotNull(principals);




More information about the jboss-cvs-commits mailing list