Search in sources :

Example 1 with EJBComponent

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

the class AuthorizationInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    final Component component = context.getPrivateData(Component.class);
    if (component instanceof EJBComponent == false) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, EJBComponent.class);
    }
    final Method invokedMethod = context.getMethod();
    final ComponentView componentView = context.getPrivateData(ComponentView.class);
    final 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 (!this.viewClassName.equals(viewClassOfInvokedMethod) || !this.viewMethod.equals(invokedMethod)) {
        throw EjbLogger.ROOT_LOGGER.failProcessInvocation(this.getClass().getName(), invokedMethod, viewClassOfInvokedMethod, viewMethod, viewClassName);
    }
    final EJBComponent ejbComponent = (EJBComponent) component;
    final ServerSecurityManager securityManager = ejbComponent.getSecurityManager();
    final MethodInterfaceType methodIntfType = this.getMethodInterfaceType(componentView.getPrivateData(MethodIntf.class));
    // set the JACC contextID before calling the security manager.
    final String previousContextID = setContextID(this.contextID);
    try {
        if (WildFlySecurityManager.isChecking()) {
            try {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                    @Override
                    public ProtectionDomain run() {
                        if (!securityManager.authorize(ejbComponent.getComponentName(), componentView.getProxyClass().getProtectionDomain().getCodeSource(), methodIntfType.name(), AuthorizationInterceptor.this.viewMethod, AuthorizationInterceptor.this.getMethodRolesAsPrincipals(), AuthorizationInterceptor.this.contextID)) {
                            throw EjbLogger.ROOT_LOGGER.invocationOfMethodNotAllowed(invokedMethod, ejbComponent.getComponentName());
                        }
                        return null;
                    }
                });
            } catch (PrivilegedActionException e) {
                throw e.getException();
            }
        } else {
            if (!securityManager.authorize(ejbComponent.getComponentName(), componentView.getProxyClass().getProtectionDomain().getCodeSource(), methodIntfType.name(), this.viewMethod, this.getMethodRolesAsPrincipals(), this.contextID)) {
                throw EjbLogger.ROOT_LOGGER.invocationOfMethodNotAllowed(invokedMethod, ejbComponent.getComponentName());
            }
        }
        // successful authorization, let the invocation proceed
        return context.proceed();
    } finally {
        // reset the previous JACC contextID.
        setContextID(previousContextID);
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) PrivilegedActionException(java.security.PrivilegedActionException) Method(java.lang.reflect.Method) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ComponentView(org.jboss.as.ee.component.ComponentView) ServerSecurityManager(org.jboss.as.core.security.ServerSecurityManager) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) MethodInterfaceType(org.jboss.metadata.ejb.spec.MethodInterfaceType)

Example 2 with EJBComponent

use of org.jboss.as.ejb3.component.EJBComponent 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 3 with EJBComponent

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

the class EjbBMTInterceptor method handleInvocation.

@Override
protected Object handleInvocation(final InterceptorContext invocation) throws Exception {
    final EJBComponent ejbComponent = getComponent();
    TransactionManager tm = ejbComponent.getTransactionManager();
    assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active";
    boolean exceptionThrown = false;
    try {
        return invocation.proceed();
    } catch (Throwable ex) {
        exceptionThrown = true;
        checkStatelessDone(ejbComponent, invocation, tm, ex);
        // we should never get here, as checkStatelessDone should re-throw
        throw (Exception) ex;
    } finally {
        try {
            if (!exceptionThrown)
                checkStatelessDone(ejbComponent, invocation, tm, null);
        } finally {
            tm.suspend();
        }
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Example 4 with EJBComponent

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

the class SecurityDomainInterceptorFactory method create.

@Override
protected Interceptor create(final Component component, final InterceptorFactoryContext context) {
    if (!(component instanceof EJBComponent)) {
        throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, EJBComponent.class);
    }
    final EJBComponent ejbComponent = (EJBComponent) component;
    final EJBSecurityMetaData securityMetaData = ejbComponent.getSecurityMetaData();
    String securityDomainName = securityMetaData.getSecurityDomainName();
    if (securityDomainName == null) {
        securityDomainName = DEFAULT_DOMAIN;
    }
    final SecurityDomain securityDomain = ejbComponent.getSecurityDomain();
    if (securityDomain == null) {
        throw EjbLogger.ROOT_LOGGER.invalidSecurityForDomainSet(ejbComponent.getComponentName());
    }
    if (ROOT_LOGGER.isTraceEnabled()) {
        ROOT_LOGGER.trace("Using security domain: " + securityDomainName + " for EJB " + ejbComponent.getComponentName());
    }
    return new SecurityDomainInterceptor(securityDomain);
}
Also used : EJBComponent(org.jboss.as.ejb3.component.EJBComponent) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain)

Example 5 with EJBComponent

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

the class LocalEjbReceiver method createSession.

protected SessionID createSession(final EJBReceiverSessionCreationContext receiverContext) throws Exception {
    final StatelessEJBLocator<?> statelessLocator = receiverContext.getClientInvocationContext().getLocator().asStateless();
    final EjbDeploymentInformation ejbInfo = findBean(statelessLocator);
    final EJBComponent component = ejbInfo.getEjbComponent();
    if (!(component instanceof StatefulSessionComponent)) {
        throw EjbLogger.ROOT_LOGGER.notStatefulSessionBean(statelessLocator.getAppName(), statelessLocator.getModuleName(), statelessLocator.getDistinctName(), statelessLocator.getBeanName());
    }
    component.waitForComponentStart();
    return ((StatefulSessionComponent) component).createSession();
}
Also used : EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) StatefulSessionComponent(org.jboss.as.ejb3.component.stateful.StatefulSessionComponent) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Aggregations

EJBComponent (org.jboss.as.ejb3.component.EJBComponent)24 Component (org.jboss.as.ee.component.Component)7 ComponentView (org.jboss.as.ee.component.ComponentView)6 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)5 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)5 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)5 Method (java.lang.reflect.Method)4 EjbDeploymentInformation (org.jboss.as.ejb3.deployment.EjbDeploymentInformation)4 PrivilegedActionException (java.security.PrivilegedActionException)3 IOException (java.io.IOException)2 InvalidClassException (java.io.InvalidClassException)2 RemoteException (java.rmi.RemoteException)2 PrivilegedAction (java.security.PrivilegedAction)2 ProtectionDomain (java.security.ProtectionDomain)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)2 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)2 TransactionAttributeType (javax.ejb.TransactionAttributeType)2