[Jboss-cvs] JBossAS SVN: r55508 - in trunk/ejb3/src: main/org/jboss/ejb3 main/org/jboss/ejb3/security test/org/jboss/ejb3/test/stateful test/org/jboss/ejb3/test/stateful/unit
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 10 19:50:40 EDT 2006
Author: bdecoste
Date: 2006-08-10 19:50:37 -0400 (Thu, 10 Aug 2006)
New Revision: 55508
Added:
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/RemoteTx.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java
trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTx.java
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTxBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
Log:
fixed handling of annotations on templated methods
Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -23,10 +23,12 @@
import org.jboss.annotation.ejb.PoolClass;
import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassAdvisor;
import org.jboss.aop.ClassContainer;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.annotation.AnnotationElement;
import org.jboss.aop.joinpoint.ConstructorInvocation;
+import org.jboss.aop.util.MethodHashing;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.ejb3.interceptor.InterceptorInfo;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
@@ -781,6 +783,56 @@
{
return (T) resolveAnnotation(field, annotationType);
}
+
+ public Object resolveAnnotation(Method m, Class annotation)
+ {
+ Object value = super.resolveAnnotation(m, annotation);
+ if (value == null && m.isBridge()) value = getBridgedAnnotation(m, annotation);
+ return value;
+ }
+
+ protected Object getBridgedAnnotation(Method bridgeMethod, Class annotation)
+ {
+ Method[] methods = bridgeMethod.getDeclaringClass().getMethods();
+ int i = 0;
+ boolean found = false;
+ Class[] bridgeParams = bridgeMethod.getParameterTypes();
+ while (i < methods.length && !found)
+ {
+ if (!methods[i].isBridge() && methods[i].getName().equals(bridgeMethod.getName()))
+ {
+ Class[] params = methods[i].getParameterTypes();
+ if (params.length == bridgeParams.length)
+ {
+ int j = 0;
+ boolean matches = true;
+ while (j < params.length && matches)
+ {
+ if (!bridgeParams[j].isAssignableFrom(params[j]))
+ matches = false;
+ ++j;
+ }
+
+ if (matches)
+ return resolveAnnotation(methods[i], annotation);
+ }
+ }
+ ++i;
+ }
+
+ return null;
+ }
+
+ public Object resolveAnnotation(Method m, Class[] annotationChoices)
+ {
+ Object value = null;
+ int i = 0;
+ while (value == null && i < annotationChoices.length){
+ value = resolveAnnotation(m, annotationChoices[i++]);
+ }
+
+ return value;
+ }
public String getIdentifier()
{
Modified: trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptor.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3.security;
+import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.security.DenyAll;
@@ -28,6 +29,9 @@
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJBAccessException;
import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.EJBContainer;
import org.jboss.logging.Logger;
import org.jboss.security.AnybodyPrincipal;
import org.jboss.security.AuthenticationManager;
@@ -47,25 +51,29 @@
{
private static final Logger log = Logger.getLogger(RoleBasedAuthorizationInterceptor.class);
- public RoleBasedAuthorizationInterceptor(AuthenticationManager manager, RealmMapping realmMapping)
+ private EJBContainer container;
+
+ public RoleBasedAuthorizationInterceptor(AuthenticationManager manager, RealmMapping realmMapping, Container container)
{
super(manager, realmMapping);
+ this.container = (EJBContainer)container;
}
protected Set getRoleSet(Invocation invocation)
{
- HashSet set = new HashSet();
+ Method method = ((MethodInvocation)invocation).getActualMethod();
Class[] classes = new Class[]{DenyAll.class, PermitAll.class, RolesAllowed.class};
- Object annotation = invocation.resolveAnnotation(classes);
+ Object annotation = container.resolveAnnotation(method, classes);
int classIndex = 0;
while (annotation == null && classIndex < 3)
{
- annotation = invocation.resolveClassAnnotation(classes[classIndex++]);
+ annotation = container.resolveAnnotation(classes[classIndex++]);
}
-
+
+ HashSet set = new HashSet();
if (annotation != null)
{
if (annotation instanceof DenyAll)
Modified: trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/main/org/jboss/ejb3/security/RoleBasedAuthorizationInterceptorFactory.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -41,9 +41,9 @@
public Object createPerClass(Advisor advisor)
{
Object domain = null;
+ Container container = (Container)advisor;
try
{
- Container container = (Container)advisor;
InitialContext ctx = container.getInitialContext();
org.jboss.annotation.security.SecurityDomain securityAnnotation = (org.jboss.annotation.security.SecurityDomain) advisor.resolveAnnotation(org.jboss.annotation.security.SecurityDomain.class);
domain = ctx.lookup("java:/jaas/" + securityAnnotation.value());
@@ -55,7 +55,7 @@
AuthenticationManager manager = (AuthenticationManager) domain;
RealmMapping mapping = (RealmMapping) domain;
if (manager == null) throw new RuntimeException("Unable to find Security Domain");
- return new RoleBasedAuthorizationInterceptor(manager, mapping);
+ return new RoleBasedAuthorizationInterceptor(manager, mapping, container);
}
public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/RemoteTx.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/RemoteTx.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/RemoteTx.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -0,0 +1,34 @@
+/*
+ * 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.ejb3.test.stateful;
+
+
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface RemoteTx<T>
+{
+ T testMandatoryTx(T t);
+}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTx.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTx.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTx.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -29,7 +29,7 @@
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
* @version $Revision$
*/
-public interface StatefulTx
+public interface StatefulTx extends RemoteTx<State>
{
boolean isGlobalTransacted() throws javax.transaction.SystemException;
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTxBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTxBean.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulTxBean.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -21,6 +21,8 @@
*/
package org.jboss.ejb3.test.stateful;
+import javax.annotation.security.DenyAll;
+import javax.annotation.security.RolesAllowed;
import javax.ejb.Remote;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
@@ -31,6 +33,7 @@
import org.jboss.annotation.JndiInject;
import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.security.SecurityDomain;
import org.jboss.logging.Logger;
/**
@@ -43,27 +46,38 @@
@Remote(StatefulTx.class)
@RemoteBinding(jndiBinding = "StatefulTx")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ at SecurityDomain("test")
+ at DenyAll
public class StatefulTxBean implements StatefulTx
{
private static final Logger log = Logger.getLogger(StatefulTxBean.class);
@JndiInject(jndiName="java:/TransactionManager") private TransactionManager tm;
+ @RolesAllowed("allowed")
public boolean isGlobalTransacted() throws javax.transaction.SystemException
{
return (tm.getTransaction() != null);
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
+ @RolesAllowed("allowed")
public boolean isLocalTransacted() throws javax.transaction.SystemException
{
return (tm.getTransaction() != null);
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
+ @RolesAllowed("allowed")
public void testTxRollback()
{
- log.info("!!! testTxRollback " + tm);
throw new RuntimeException("test rollback");
}
+
+ @TransactionAttribute(value = TransactionAttributeType.MANDATORY)
+ @RolesAllowed("allowed")
+ public State testMandatoryTx(State o)
+ {
+ return o;
+ }
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2006-08-10 22:17:51 UTC (rev 55507)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java 2006-08-10 23:50:37 UTC (rev 55508)
@@ -32,6 +32,7 @@
import org.jboss.ejb3.test.stateful.StatefulTx;
import org.jboss.ejb3.test.stateful.ProxyFactoryInterface;
import org.jboss.ejb3.test.stateful.RemoteBindingInterceptor;
+import org.jboss.ejb3.test.stateful.State;
import org.jboss.ejb3.test.stateful.StatefulHome;
import org.jboss.ejb3.test.stateful.ExtendedState;
import org.jboss.ejb3.test.stateful.Tester;
@@ -166,6 +167,24 @@
}
}
+ public void testTemplateInterfaceTx() throws Exception
+ {
+ SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
+ SecurityAssociation.setCredential("password".toCharArray());
+
+ StatefulTx stateful = (StatefulTx)getInitialContext().lookup("StatefulTx");
+ assertNotNull(stateful);
+
+ try
+ {
+ stateful.testMandatoryTx(new State("test"));
+ fail("should have caught exception");
+ }
+ catch (javax.ejb.EJBTransactionRequiredException e)
+ {
+ }
+ }
+
public void testLocalSFSB() throws Exception
{
SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
More information about the jboss-cvs-commits
mailing list