Search in sources :

Example 1 with MethodIntf

use of org.jboss.as.ejb3.component.MethodIntf in project wildfly by wildfly.

the class CMTTxInterceptor method processInvocation.

public Object processInvocation(InterceptorContext invocation) throws Exception {
    final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
    final ContextTransactionManager tm = ContextTransactionManager.getInstance();
    final int oldTimeout = tm.getTransactionTimeout();
    try {
        final MethodIntf methodIntf = MethodIntfHelper.of(invocation);
        final Method method = invocation.getMethod();
        final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, method);
        final int timeoutInSeconds = component.getTransactionTimeout(methodIntf, method);
        switch(attr) {
            case MANDATORY:
                return mandatory(invocation, component);
            case NEVER:
                return never(invocation, component);
            case NOT_SUPPORTED:
                return notSupported(invocation, component);
            case REQUIRED:
                final ComponentView view = invocation.getPrivateData(ComponentView.class);
                if (view != null && view.isAsynchronous(method)) {
                    // method are exactly the same as REQUIRES_NEW.
                    return requiresNew(invocation, component, timeoutInSeconds);
                }
                return required(invocation, component, timeoutInSeconds);
            case REQUIRES_NEW:
                return requiresNew(invocation, component, timeoutInSeconds);
            case SUPPORTS:
                return supports(invocation, component);
            default:
                throw EjbLogger.ROOT_LOGGER.unknownTxAttributeOnInvocation(attr, invocation);
        }
    } finally {
        // See also https://issues.jboss.org/browse/WFTC-44
        tm.setTransactionTimeout(oldTimeout == ContextTransactionManager.getGlobalDefaultTransactionTimeout() ? 0 : oldTimeout);
    }
}
Also used : ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) ComponentView(org.jboss.as.ee.component.ComponentView) Method(java.lang.reflect.Method) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) TransactionAttributeType(javax.ejb.TransactionAttributeType)

Example 2 with MethodIntf

use of org.jboss.as.ejb3.component.MethodIntf in project wildfly by wildfly.

the class TransactionAttributeMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentDescription) throws DeploymentUnitProcessingException {
    // CMT Tx attributes
    // DO NOT USE componentConfiguration.getDescriptorData()
    // It will return null if there is no <enterprise-beans/> declaration even if there is an assembly descriptor entry
    EjbJarMetaData ejbJarMetadata = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetadata != null) {
        boolean wildcardAttributeSet = false;
        boolean wildcardTimeoutSet = false;
        ContainerTransactionMetaData global = null;
        final AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetadata.getAssemblyDescriptor();
        if (assemblyDescriptor != null) {
            final ContainerTransactionsMetaData globalTransactions = assemblyDescriptor.getContainerTransactionsByEjbName("*");
            if (globalTransactions != null) {
                if (globalTransactions.size() > 1) {
                    throw EjbLogger.ROOT_LOGGER.mustOnlyBeSingleContainerTransactionElementWithWildcard();
                }
                global = globalTransactions.iterator().next();
                for (MethodMetaData method : global.getMethods()) {
                    if (!method.getMethodName().equals("*")) {
                        throw EjbLogger.ROOT_LOGGER.wildcardContainerTransactionElementsMustHaveWildcardMethodName();
                    }
                }
            }
            final ContainerTransactionsMetaData containerTransactions = assemblyDescriptor.getContainerTransactionsByEjbName(componentDescription.getEJBName());
            if (containerTransactions != null) {
                for (final ContainerTransactionMetaData containerTx : containerTransactions) {
                    final TransactionAttributeType txAttr = containerTx.getTransAttribute();
                    final Integer timeout = timeout(containerTx);
                    final MethodsMetaData methods = containerTx.getMethods();
                    for (final MethodMetaData method : methods) {
                        final String methodName = method.getMethodName();
                        final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
                        final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
                        if (methodName.equals("*")) {
                            if (txAttr != null) {
                                wildcardAttributeSet = true;
                                componentDescription.getTransactionAttributes().setAttribute(methodIntf, null, txAttr);
                            }
                            if (timeout != null) {
                                wildcardTimeoutSet = true;
                                componentDescription.getTransactionTimeouts().setAttribute(methodIntf, null, timeout);
                            }
                        } else {
                            final MethodParametersMetaData methodParams = method.getMethodParams();
                            // update the session bean description with the tx attribute info
                            if (methodParams == null) {
                                if (txAttr != null)
                                    componentDescription.getTransactionAttributes().setAttribute(methodIntf, txAttr, methodName);
                                if (timeout != null)
                                    componentDescription.getTransactionTimeouts().setAttribute(methodIntf, timeout, methodName);
                            } else {
                                if (txAttr != null)
                                    componentDescription.getTransactionAttributes().setAttribute(methodIntf, txAttr, null, methodName, this.getMethodParams(methodParams));
                                if (timeout != null)
                                    componentDescription.getTransactionTimeouts().setAttribute(methodIntf, timeout, null, methodName, this.getMethodParams(methodParams));
                            }
                        }
                    }
                }
            }
        }
        if (global != null) {
            if (!wildcardAttributeSet && global.getTransAttribute() != null) {
                for (MethodMetaData method : global.getMethods()) {
                    final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
                    final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
                    componentDescription.getTransactionAttributes().setAttribute(methodIntf, null, global.getTransAttribute());
                }
            }
            final Integer timeout = timeout(global);
            if (!wildcardTimeoutSet && timeout != null) {
                for (MethodMetaData method : global.getMethods()) {
                    final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
                    final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
                    componentDescription.getTransactionTimeouts().setAttribute(methodIntf, null, timeout);
                }
            }
        }
    }
}
Also used : EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) MethodMetaData(org.jboss.metadata.ejb.spec.MethodMetaData) MethodParametersMetaData(org.jboss.metadata.ejb.spec.MethodParametersMetaData) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ContainerTransactionMetaData(org.jboss.metadata.ejb.spec.ContainerTransactionMetaData) MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) ContainerTransactionsMetaData(org.jboss.metadata.ejb.spec.ContainerTransactionsMetaData) AssemblyDescriptorMetaData(org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData) MethodsMetaData(org.jboss.metadata.ejb.spec.MethodsMetaData) TransactionAttributeType(javax.ejb.TransactionAttributeType)

Example 3 with MethodIntf

use of org.jboss.as.ejb3.component.MethodIntf in project wildfly by wildfly.

the class EjbIIOPTransactionInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext invocation) throws Exception {
    // Do we have a foreign transaction context?
    Transaction tx = TxServerInterceptor.getCurrentTransaction();
    if (tx instanceof ForeignTransaction) {
        final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
        // for timer invocations there is no view, so the methodInf is attached directly
        // to the context. Otherwise we retrieve it from the invoked view
        MethodIntf methodIntf = invocation.getPrivateData(MethodIntf.class);
        if (methodIntf == null) {
            final ComponentView componentView = invocation.getPrivateData(ComponentView.class);
            if (componentView != null) {
                methodIntf = componentView.getPrivateData(MethodIntf.class);
            } else {
                methodIntf = MethodIntf.BEAN;
            }
        }
        final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod());
        if (attr != TransactionAttributeType.NOT_SUPPORTED && attr != TransactionAttributeType.REQUIRES_NEW) {
            throw EjbLogger.ROOT_LOGGER.transactionPropagationNotSupported();
        }
    }
    return invocation.proceed();
}
Also used : Transaction(javax.transaction.Transaction) ForeignTransaction(org.wildfly.iiop.openjdk.tm.ForeignTransaction) ComponentView(org.jboss.as.ee.component.ComponentView) ForeignTransaction(org.wildfly.iiop.openjdk.tm.ForeignTransaction) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) TransactionAttributeType(javax.ejb.TransactionAttributeType)

Example 4 with MethodIntf

use of org.jboss.as.ejb3.component.MethodIntf in project wildfly by wildfly.

the class MethodPermissionsMergingProcessor method handleExcludeMethods.

private void handleExcludeMethods(final EJBComponentDescription componentDescription, final ExcludeListMetaData excludeList) {
    for (final MethodMetaData method : excludeList.getMethods()) {
        final String methodName = method.getMethodName();
        final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
        final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
        if (methodName.equals("*")) {
            componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, null, EJBMethodSecurityAttribute.denyAll());
        } else {
            final MethodParametersMetaData methodParams = method.getMethodParams();
            // update the session bean description with the tx attribute info
            if (methodParams == null) {
                componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, EJBMethodSecurityAttribute.denyAll(), methodName);
            } else {
                componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, EJBMethodSecurityAttribute.denyAll(), null, methodName, this.getMethodParams(methodParams));
            }
        }
    }
}
Also used : MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) MethodMetaData(org.jboss.metadata.ejb.spec.MethodMetaData) MethodParametersMetaData(org.jboss.metadata.ejb.spec.MethodParametersMetaData) MethodIntf(org.jboss.as.ejb3.component.MethodIntf)

Example 5 with MethodIntf

use of org.jboss.as.ejb3.component.MethodIntf in project wildfly by wildfly.

the class MethodPermissionsMergingProcessor method handleMethodPermissions.

private void handleMethodPermissions(final EJBComponentDescription componentDescription, final MethodPermissionsMetaData methodPermissions) {
    for (final MethodPermissionMetaData methodPermissionMetaData : methodPermissions) {
        final MethodsMetaData methods = methodPermissionMetaData.getMethods();
        for (final MethodMetaData method : methods) {
            EJBMethodSecurityAttribute ejbMethodSecurityMetaData;
            // Enterprise Beans 3.1 FR 17.3.2.2 The unchecked element is used instead of a role name in the method-permission element to indicate that all roles are permitted.
            if (methodPermissionMetaData.isNotChecked()) {
                ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.permitAll();
            } else {
                ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.rolesAllowed(methodPermissionMetaData.getRoles());
            }
            final String methodName = method.getMethodName();
            final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
            final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
            if (methodName.equals("*")) {
                final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle1(methodIntf, null);
                ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
                componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, null, ejbMethodSecurityMetaData);
            } else {
                final MethodParametersMetaData methodParams = method.getMethodParams();
                // update the session bean description with the tx attribute info
                if (methodParams == null) {
                    final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle2(methodIntf, methodName);
                    ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
                    componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, ejbMethodSecurityMetaData, methodName);
                } else {
                    final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle3(methodIntf, null, methodName, this.getMethodParams(methodParams));
                    ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
                    componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, ejbMethodSecurityMetaData, null, methodName, this.getMethodParams(methodParams));
                }
            }
        }
    }
}
Also used : MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) EJBMethodSecurityAttribute(org.jboss.as.ejb3.security.EJBMethodSecurityAttribute) MethodsMetaData(org.jboss.metadata.ejb.spec.MethodsMetaData) MethodMetaData(org.jboss.metadata.ejb.spec.MethodMetaData) MethodParametersMetaData(org.jboss.metadata.ejb.spec.MethodParametersMetaData) MethodPermissionMetaData(org.jboss.metadata.ejb.spec.MethodPermissionMetaData) MethodIntf(org.jboss.as.ejb3.component.MethodIntf)

Aggregations

MethodIntf (org.jboss.as.ejb3.component.MethodIntf)7 TransactionAttributeType (javax.ejb.TransactionAttributeType)4 MessageDrivenComponentDescription (org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription)4 ComponentView (org.jboss.as.ee.component.ComponentView)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)3 MethodMetaData (org.jboss.metadata.ejb.spec.MethodMetaData)3 MethodParametersMetaData (org.jboss.metadata.ejb.spec.MethodParametersMetaData)3 HashSet (java.util.HashSet)2 Component (org.jboss.as.ee.component.Component)2 ViewDescription (org.jboss.as.ee.component.ViewDescription)2 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)2 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)2 MethodsMetaData (org.jboss.metadata.ejb.spec.MethodsMetaData)2 Module (org.jboss.modules.Module)2 ServiceName (org.jboss.msc.service.ServiceName)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Transaction (javax.transaction.Transaction)1