[jboss-cvs] JBossAS SVN: r97423 - in projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src: test/java/org/jboss/test/metadata and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 3 13:05:28 EST 2009


Author: ALRubinger
Date: 2009-12-03 13:05:27 -0500 (Thu, 03 Dec 2009)
New Revision: 97423

Added:
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowed.java
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBean.java
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBeanBase.java
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/unit/
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/unit/ClassLevelRolesAllowedInheritedNoNpeTestCase.java
Modified:
   projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java
Log:
[JBPAPP-3205] Test Cases and Fixes for NPE when @RolesAllowed is overridden at the class level

Modified: projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java
===================================================================
--- projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java	2009-12-03 17:44:03 UTC (rev 97422)
+++ projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java	2009-12-03 18:05:27 UTC (rev 97423)
@@ -79,6 +79,12 @@
          {
             for (MethodMetaData existingMethod : existingPerm.getMethods())
             {
+               // JBMETA-207; if class-level @RolesAllowed is overridden, avoid NPE
+               if (existingMethod == null || existingMethod.getMethodParams() == null)
+               {
+                  return;
+               }
+               
                // If this method's already been added
                if (existingMethod.getMethodName().equals(mmd.getMethodName())
                      && existingMethod.getMethodParams().equals(mmd.getMethodParams()))

Added: projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowed.java
===================================================================
--- projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowed.java	                        (rev 0)
+++ projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowed.java	2009-12-03 18:05:27 UTC (rev 97423)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.jbmeta207;
+
+/**
+ * SecureService
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface InheritedRolesAllowed
+{
+   //------------------------------------------------------------------------------||
+   // Constants -------------------------------------------------------------------||
+   //------------------------------------------------------------------------------||
+
+   String ROLES_EJB = "EJBRole";
+
+   String ROLES_BEAN_BASE = "BaseRole";
+
+   //------------------------------------------------------------------------------||
+   // Contracts -------------------------------------------------------------------||
+   //------------------------------------------------------------------------------||
+
+   /**
+    * Dummy method, must be named "someMethod" for test to work
+    */
+   void someMethod();
+}

Added: projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBean.java
===================================================================
--- projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBean.java	                        (rev 0)
+++ projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBean.java	2009-12-03 18:05:27 UTC (rev 97423)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.jbmeta207;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * SecureServiceBean
+ * 
+ * A Test EJB which should override the
+ * roles allowed at the class level in an attempt 
+ * to expose the NPE defined by JBMETA-207
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(InheritedRolesAllowed.class)
+ at RolesAllowed(InheritedRolesAllowed.ROLES_EJB)
+public class InheritedRolesAllowedBean extends InheritedRolesAllowedBeanBase implements InheritedRolesAllowed
+{
+
+   @Override
+   public void someMethod()
+   {
+      return;
+   }
+
+}

Added: projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBeanBase.java
===================================================================
--- projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBeanBase.java	                        (rev 0)
+++ projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/InheritedRolesAllowedBeanBase.java	2009-12-03 18:05:27 UTC (rev 97423)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.jbmeta207;
+
+import javax.annotation.security.RolesAllowed;
+
+/**
+ * SecureServiceBeanBase
+ * 
+ * A base upon which the EJB will build, declaring 
+ * an allowed role at the class level in an attempt to 
+ * force an NPE as described by JBMETA-207
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at RolesAllowed(InheritedRolesAllowed.ROLES_BEAN_BASE)
+public class InheritedRolesAllowedBeanBase implements InheritedRolesAllowed
+{
+   public void someMethod()
+   {
+      return;
+   }
+
+}

Added: projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/unit/ClassLevelRolesAllowedInheritedNoNpeTestCase.java
===================================================================
--- projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/unit/ClassLevelRolesAllowedInheritedNoNpeTestCase.java	                        (rev 0)
+++ projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta207/unit/ClassLevelRolesAllowedInheritedNoNpeTestCase.java	2009-12-03 18:05:27 UTC (rev 97423)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.metadata.jbmeta207.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.test.metadata.jbmeta207.InheritedRolesAllowedBean;
+
+/**
+ * Tests EJBs that have @RolesAllowed overridden at the class
+ * level in an inheritance hierarchy does not result in 
+ * {@link NullPointerException}
+ * 
+ * JBMETA-207
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ClassLevelRolesAllowedInheritedNoNpeTestCase extends TestCase
+{
+   // -------------------------------------------------------------------||
+   // Class Members -----------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(ClassLevelRolesAllowedInheritedNoNpeTestCase.class);
+
+   // -------------------------------------------------------------------||
+   // Tests -------------------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   /**
+    * Ensures that @RolesAllowed definitions at the class level, 
+    * when overridden do not throw NPEs 
+    */
+   public void testRolesAllowedOverriddenNotAdditive() throws Throwable
+   {
+      /*
+       * Set up a JBoss Metadata Creator
+       */
+
+      // Define the implementation class
+      Class<?> implClass = InheritedRolesAllowedBean.class;
+
+      // Make an annotation finder
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+
+      // Configure to scan the test EJB
+      Collection<Class<?>> classes = new ArrayList<Class<?>>();
+      classes.add(implClass);
+      JBoss50Creator creator = new JBoss50Creator(finder);
+
+      // Make the metadata
+      try
+      {
+         creator.create(classes);
+      }
+      catch (final NullPointerException npe)
+      {
+         TestCase.fail("Should not throw " + npe);
+      }
+
+   }
+
+}




More information about the jboss-cvs-commits mailing list