| 
					
				 | 
			
			
				@@ -15,28 +15,30 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package org.acegisecurity.annotation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.lang.reflect.Field; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.lang.reflect.Method; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Collection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import junit.framework.TestCase; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.acegisecurity.SecurityConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.logging.Log; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.logging.LogFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.metadata.Attributes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.lang.reflect.Field; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.lang.reflect.Method; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Collection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * Tests for {@link org.acegisecurity.annotation.SecurityAnnotationAttributes} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @author Mark St.Godard 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- * @version $Revision$ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @author Joe Scalise 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @version $Id$ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class SecurityAnnotationAttributesTests extends TestCase { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //~ Instance fields ================================================================================================ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private Attributes attributes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Log logger = LogFactory.getLog(SecurityAnnotationAttributesTests.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //~ Methods ======================================================================================================== 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -132,4 +134,59 @@ public class SecurityAnnotationAttributesTests extends TestCase { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             fail("Unsupported method should have thrown an exception!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } catch (UnsupportedOperationException expected) {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void testGenericsSuperclassDeclarationsAreIncludedWhenSubclassesOverride() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Method method = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            method = DepartmentServiceImpl.class.getMethod("someUserMethod3", new Class[]{Department.class}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (NoSuchMethodException unexpected) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            fail("Should be a superMethod called 'someUserMethod3' on class!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Collection attrs = this.attributes.getAttributes(method); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (logger.isDebugEnabled()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.debug("attrs: "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.debug(attrs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        assertNotNull(attrs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // expect 1 attribute 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        assertTrue("Did not find 1 attribute", attrs.size() == 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // should have 1 SecurityConfig 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Object obj : attrs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assertTrue(obj instanceof SecurityConfig); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SecurityConfig sc = (SecurityConfig) obj; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assertEquals("Found an incorrect role", "ROLE_ADMIN", sc.getAttribute()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Method superMethod = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            superMethod = DepartmentServiceImpl.class.getMethod("someUserMethod3", new Class[]{Entity.class}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (NoSuchMethodException unexpected) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            fail("Should be a superMethod called 'someUserMethod3' on class!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(superMethod); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Collection superAttrs = this.attributes.getAttributes(superMethod); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (logger.isDebugEnabled()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.debug("superAttrs: "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.debug(superAttrs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        assertNotNull(superAttrs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // TODO: Resolve bridge method bug as reported in SEC-274 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // expect 1 attribute 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        assertTrue("Did not find 1 attribute", superAttrs.size() == 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // should have 1 SecurityConfig 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Object obj : superAttrs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assertTrue(obj instanceof SecurityConfig); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SecurityConfig sc = (SecurityConfig) obj; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assertEquals("Found an incorrect role", "ROLE_ADMIN", sc.getAttribute()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }    
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |