[jboss-cvs] JBossAS SVN: r97815 - in projects/metadata/trunk/src: test/java/org/jboss/test/metadata/jbmeta152 and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 14 18:44:01 EST 2009


Author: ALRubinger
Date: 2009-12-14 18:44:01 -0500 (Mon, 14 Dec 2009)
New Revision: 97815

Added:
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/ClassLevelRolesAllowedServiceBean.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/unit/ClassLevelAndMethodLevelRolesAllowedTestCase.java
Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java
Log:
[JBMETA-207] Merge in changes from JBPAPP-3205 regression, considering both class- and method-level @RolesAllowed (and new tests)

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java	2009-12-14 23:40:56 UTC (rev 97814)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/annotation/creator/ejb/jboss/RolesAllowedProcessor.java	2009-12-14 23:44:01 UTC (rev 97815)
@@ -35,6 +35,7 @@
 import org.jboss.metadata.annotation.creator.ProcessorUtils;
 import org.jboss.metadata.annotation.finder.AnnotationFinder;
 import org.jboss.metadata.ejb.spec.MethodMetaData;
+import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
 import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
 import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
 import org.jboss.metadata.ejb.spec.MethodsMetaData;
@@ -79,18 +80,30 @@
          {
             for (MethodMetaData existingMethod : existingPerm.getMethods())
             {
-               // JBMETA-207; if class-level @RolesAllowed is overridden, avoid NPE
-               if (existingMethod == null || existingMethod.getMethodParams() == null)
+               /*
+                * JBMETA-207 Only allow overrides if this method signature has 
+                * not been overridden, and do so in a way that avoids all NPEs
+                */
+               // If we've got no predefined existing method, move along
+               if (existingMethod == null)
                {
                   return;
                }
-               
-               // If this method's already been added
-               if (existingMethod.getMethodName().equals(mmd.getMethodName())
-                     && existingMethod.getMethodParams().equals(mmd.getMethodParams()))
+               // If the preexisting method matches what we have described here,
+               // then check the rest of the signature
+               if (existingMethod.getMethodName().equals(mmd.getMethodName()))
                {
-                  // Do nothing
-                  return;
+                  // If this method's already been added (equal signatures), then don't add it again                  
+                  final MethodParametersMetaData existingParams = existingMethod.getMethodParams();
+                  if (existingParams == null && mmd.getMethodParams() == null)
+                  {
+                     return;
+                  }
+                  if (existingParams.equals(mmd.getMethodParams()))
+                  {
+                     return;
+
+                  }
                }
             }
          }

Copied: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/ClassLevelRolesAllowedServiceBean.java (from rev 97814, projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta152/ClassLevelRolesAllowedServiceBean.java)
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/ClassLevelRolesAllowedServiceBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/ClassLevelRolesAllowedServiceBean.java	2009-12-14 23:44:01 UTC (rev 97815)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.
+ *
+ * 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.jboss.test.metadata.jbmeta152;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Stateless;
+
+/**
+ * Test EJB to ensure that class-level @RolesAllowed
+ * are considered in conjunction with method-level 
+ * @RolesAllowed.  Identified by a regression introduced
+ * by JBMETA-207
+ * 
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at RolesAllowed(SecureService.ROLES_BEAN_BASE)
+// Base roles by default
+public class ClassLevelRolesAllowedServiceBean implements SecureService
+{
+   //-------------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /*
+    * This method should get base roles
+    */
+   public void anotherMethod()
+   {
+
+   }
+
+   /*
+    * This method should get EJB roles
+    * @see org.jboss.test.metadata.jbmeta152.SecureService#someMethod()
+    */
+   @RolesAllowed(SecureService.ROLES_EJB)
+   public void someMethod()
+   {
+      return;
+   }
+
+}

Copied: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/unit/ClassLevelAndMethodLevelRolesAllowedTestCase.java (from rev 97814, projects/metadata/branches/JBPAPP_5_0_0_JBPAPP-3205/src/test/java/org/jboss/test/metadata/jbmeta152/unit/ClassLevelAndMethodLevelRolesAllowedTestCase.java)
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/unit/ClassLevelAndMethodLevelRolesAllowedTestCase.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/jbmeta152/unit/ClassLevelAndMethodLevelRolesAllowedTestCase.java	2009-12-14 23:44:01 UTC (rev 97815)
@@ -0,0 +1,96 @@
+/*
+ * 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.jbmeta152.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.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionMetaData;
+import org.jboss.metadata.ejb.spec.MethodPermissionsMetaData;
+import org.jboss.test.metadata.jbmeta152.ClassLevelRolesAllowedServiceBean;
+
+/**
+ * Ensures that both the class-level and method-level
+ * @RolesAllowed annotation is taken into consideration.  Introduced by
+ * a regression while fixing JBMETA-207.
+ *  
+ * JBMETA-152
+ * JBNETA-207
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ClassLevelAndMethodLevelRolesAllowedTestCase extends TestCase
+{
+   // -------------------------------------------------------------------||
+   // Class Members -----------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(ClassLevelAndMethodLevelRolesAllowedTestCase.class);
+
+   // -------------------------------------------------------------------||
+   // Tests -------------------------------------------------------------||
+   // -------------------------------------------------------------------||
+
+   /**
+    * Ensures that both the class-level and method-level
+    * @RolesAllowed annotation is taken into consideration.  Introduced by
+    * a regression while fixing JBMETA-207.
+    */
+   public void testMethodLevelAndClassLevelRolesAllowedMerged() throws Throwable
+   {
+      /*
+       * Set up a JBoss Metadata Creator
+       */
+
+      // Define the implementation class
+      Class<?> implClass = ClassLevelRolesAllowedServiceBean.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
+      JBoss50MetaData md = creator.create(classes);
+
+      // Ensure we've got the right permissions
+      MethodPermissionsMetaData permissions = md.getAssemblyDescriptor().getMethodPermissions()
+            .getMethodPermissionsByEjbName(implClass.getSimpleName());
+      TestCase.assertEquals("Exactly two sets of " + MethodPermissionsMetaData.class.getSimpleName()
+            + " should be defined", 2, permissions.size());
+      MethodPermissionMetaData permission = permissions.get(0);
+      TestCase.assertNotNull(permission);
+   }
+
+}




More information about the jboss-cvs-commits mailing list