Search in sources :

Example 11 with Component

use of org.jboss.as.ee.component.Component 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 12 with Component

use of org.jboss.as.ee.component.Component in project wildfly by wildfly.

the class StatefulRemoveInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);
    //if a session bean is participating in a transaction, it
    //is an error for a client to invoke the remove method
    //on the session object's home or component interface.
    final ComponentView view = context.getPrivateData(ComponentView.class);
    if (view != null) {
        Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
        if (viewType != null) {
            //this means it is an EJB 2.x view
            //which is not allowed to remove while enrolled in a TX
            final StatefulTransactionMarker marker = context.getPrivateData(StatefulTransactionMarker.class);
            if (marker != null && !marker.isFirstInvocation()) {
                throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
            }
        }
    }
    // just log a WARN and throw back the original exception
    if (component instanceof StatefulSessionComponent == false) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
    }
    final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
    Object invocationResult = null;
    try {
        // proceed
        invocationResult = context.proceed();
    } catch (Exception e) {
        // then just throw back the exception and don't remove the session instance.
        if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
            throw e;
        }
        // otherwise, just remove it and throw back the original exception
        final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
        final SessionID sessionId = statefulComponentInstance.getId();
        statefulComponent.removeSession(sessionId);
        throw e;
    }
    final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
    final SessionID sessionId = statefulComponentInstance.getId();
    // just remove the session because of a call to @Remove method
    statefulComponent.removeSession(sessionId);
    // return the invocation result
    return invocationResult;
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Ejb2xViewType(org.jboss.as.ejb3.component.Ejb2xViewType) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) SessionID(org.jboss.ejb.client.SessionID)

Example 13 with Component

use of org.jboss.as.ee.component.Component in project wildfly by wildfly.

the class NonFunctionalTimerService method assertInvocationAllowed.

private void assertInvocationAllowed() {
    AllowedMethodsInformation.checkAllowed(MethodType.TIMER_SERVICE_METHOD);
    final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
    if (currentInvocationContext == null) {
        return;
    }
    // If the method in current invocation context is null,
    // then it represents a lifecycle callback invocation
    Method invokedMethod = currentInvocationContext.getMethod();
    if (invokedMethod == null) {
        // it's a lifecycle callback
        Component component = currentInvocationContext.getPrivateData(Component.class);
        if (!(component instanceof SingletonComponent)) {
            throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimerServiceDoLifecycle();
        }
    }
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) SingletonComponent(org.jboss.as.ejb3.component.singleton.SingletonComponent) Method(java.lang.reflect.Method) SingletonComponent(org.jboss.as.ejb3.component.singleton.SingletonComponent) Component(org.jboss.as.ee.component.Component)

Example 14 with Component

use of org.jboss.as.ee.component.Component in project wildfly by wildfly.

the class AssociationImpl method receiveSessionOpenRequest.

@Override
@NotNull
public CancelHandle receiveSessionOpenRequest(@NotNull final SessionOpenRequest sessionOpenRequest) {
    final EJBIdentifier ejbIdentifier = sessionOpenRequest.getEJBIdentifier();
    final String appName = ejbIdentifier.getAppName();
    final String moduleName = ejbIdentifier.getModuleName();
    final String beanName = ejbIdentifier.getBeanName();
    final String distinctName = ejbIdentifier.getDistinctName();
    final EjbDeploymentInformation ejbDeploymentInformation = findEJB(appName, moduleName, distinctName, beanName);
    if (ejbDeploymentInformation == null) {
        sessionOpenRequest.writeNoSuchEJB();
        return CancelHandle.NULL;
    }
    final Component component = ejbDeploymentInformation.getEjbComponent();
    if (!(component instanceof StatefulSessionComponent)) {
        sessionOpenRequest.writeNotStateful();
        return CancelHandle.NULL;
    }
    final StatefulSessionComponent statefulSessionComponent = (StatefulSessionComponent) component;
    // generate the session id and write out the response, possibly on a separate thread
    final AtomicBoolean cancelled = new AtomicBoolean();
    Runnable runnable = () -> {
        if (cancelled.get()) {
            sessionOpenRequest.writeCancelResponse();
            return;
        }
        final SessionID sessionID;
        try {
            sessionID = statefulSessionComponent.createSessionRemote();
        } catch (Exception t) {
            EjbLogger.REMOTE_LOGGER.exceptionGeneratingSessionId(t, statefulSessionComponent.getComponentName(), ejbIdentifier);
            sessionOpenRequest.writeException(t);
            return;
        }
        sessionOpenRequest.convertToStateful(sessionID);
    };
    execute(sessionOpenRequest, runnable, false);
    return ignored -> cancelled.set(true);
}
Also used : DeploymentRepositoryListener(org.jboss.as.ejb3.deployment.DeploymentRepositoryListener) NotNull(org.wildfly.common.annotation.NotNull) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) ClusterTopologyListener(org.jboss.ejb.server.ClusterTopologyListener) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) Future(java.util.concurrent.Future) EJBComponentUnavailableException(org.jboss.as.ejb3.component.EJBComponentUnavailableException) Map(java.util.Map) Affinity(org.jboss.ejb.client.Affinity) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) InvocationRequest(org.jboss.ejb.server.InvocationRequest) Method(java.lang.reflect.Method) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) Registry(org.wildfly.clustering.registry.Registry) CancellationException(java.util.concurrent.CancellationException) StatefulEJBLocator(org.jboss.ejb.client.StatefulEJBLocator) Set(java.util.Set) InterceptorContext(org.jboss.invocation.InterceptorContext) Collectors(java.util.stream.Collectors) ClientMapping(org.jboss.as.network.ClientMapping) EJBException(javax.ejb.EJBException) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener) List(java.util.List) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) EJBLocator(org.jboss.ejb.client.EJBLocator) Request(org.jboss.ejb.server.Request) ComponentIsStoppedException(org.jboss.as.ee.component.ComponentIsStoppedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Connection(org.jboss.remoting3.Connection) HashMap(java.util.HashMap) EJBIdentifier(org.jboss.ejb.client.EJBIdentifier) ArrayList(java.util.ArrayList) StatelessSessionComponent(org.jboss.as.ejb3.component.stateless.StatelessSessionComponent) DeploymentRepository(org.jboss.as.ejb3.deployment.DeploymentRepository) SessionOpenRequest(org.jboss.ejb.server.SessionOpenRequest) CancellationFlag(org.jboss.as.ejb3.component.interceptors.CancellationFlag) Executor(java.util.concurrent.Executor) Association(org.jboss.ejb.server.Association) ComponentView(org.jboss.as.ee.component.ComponentView) IOException(java.io.IOException) InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) EJBMethodLocator(org.jboss.ejb.client.EJBMethodLocator) SessionID(org.jboss.ejb.client.SessionID) EjbLogger(org.jboss.as.ejb3.logging.EjbLogger) ListenerHandle(org.jboss.ejb.server.ListenerHandle) EJBClientInvocationContext(org.jboss.ejb.client.EJBClientInvocationContext) Component(org.jboss.as.ee.component.Component) CancelHandle(org.jboss.ejb.server.CancelHandle) Collections(java.util.Collections) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) StatelessSessionComponent(org.jboss.as.ejb3.component.stateless.StatelessSessionComponent) Component(org.jboss.as.ee.component.Component) EJBIdentifier(org.jboss.ejb.client.EJBIdentifier) SessionID(org.jboss.ejb.client.SessionID) EJBComponentUnavailableException(org.jboss.as.ejb3.component.EJBComponentUnavailableException) CancellationException(java.util.concurrent.CancellationException) EJBException(javax.ejb.EJBException) ComponentIsStoppedException(org.jboss.as.ee.component.ComponentIsStoppedException) IOException(java.io.IOException) NotNull(org.wildfly.common.annotation.NotNull)

Example 15 with Component

use of org.jboss.as.ee.component.Component in project wildfly by wildfly.

the class JaccInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    Component component = context.getPrivateData(Component.class);
    final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class);
    Assert.checkNotNullParam("securityDomain", securityDomain);
    final SecurityIdentity currentIdentity = securityDomain.getCurrentSecurityIdentity();
    if (component instanceof EJBComponent == false) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, EJBComponent.class);
    }
    Method invokedMethod = context.getMethod();
    ComponentView componentView = context.getPrivateData(ComponentView.class);
    String viewClassOfInvokedMethod = componentView.getViewClass().getName();
    // shouldn't really happen if the interceptor was setup correctly. But let's be safe and do a check
    if (!viewClassName.equals(viewClassOfInvokedMethod) || !viewMethod.equals(invokedMethod)) {
        throw EjbLogger.ROOT_LOGGER.failProcessInvocation(getClass().getName(), invokedMethod, viewClassOfInvokedMethod, viewMethod, viewClassName);
    }
    EJBComponent ejbComponent = (EJBComponent) component;
    if (WildFlySecurityManager.isChecking()) {
        try {
            AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
                hasPermission(ejbComponent, componentView, invokedMethod, currentIdentity);
                return null;
            });
        } catch (PrivilegedActionException e) {
            throw e.getException();
        }
    } else {
        hasPermission(ejbComponent, componentView, invokedMethod, currentIdentity);
    }
    // successful authorization, let the invocation proceed
    return context.proceed();
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) ComponentView(org.jboss.as.ee.component.ComponentView) PrivilegedActionException(java.security.PrivilegedActionException) 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) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Aggregations

Component (org.jboss.as.ee.component.Component)18 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)8 ComponentView (org.jboss.as.ee.component.ComponentView)7 Method (java.lang.reflect.Method)6 InterceptorContext (org.jboss.invocation.InterceptorContext)5 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)5 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)4 PrivilegedActionException (java.security.PrivilegedActionException)3 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)3 IOException (java.io.IOException)2 TransactionAttributeType (javax.ejb.TransactionAttributeType)2 ComponentClientInstance (org.jboss.as.ee.component.ComponentClientInstance)2 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)2 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)2 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)2 SessionBeanComponent (org.jboss.as.ejb3.component.session.SessionBeanComponent)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 SessionID (org.jboss.ejb.client.SessionID)2 Interceptor (org.jboss.invocation.Interceptor)2 ServiceName (org.jboss.msc.service.ServiceName)2