Search in sources :

Example 16 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class BasicComponentInstance method prepareInterceptorContext.

protected InterceptorContext prepareInterceptorContext() {
    final InterceptorContext interceptorContext = new InterceptorContext();
    interceptorContext.putPrivateData(Component.class, component);
    interceptorContext.putPrivateData(ComponentInstance.class, this);
    interceptorContext.setContextData(new HashMap<String, Object>());
    return interceptorContext;
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext)

Example 17 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class AllowedMethodsInformation method checkAllowed.

/**
     * Checks that the current method
     */
public static void checkAllowed(final MethodType methodType) {
    final InterceptorContext context = CurrentInvocationContext.get();
    if (context == null) {
        return;
    }
    final Component component = context.getPrivateData(Component.class);
    if (!(component instanceof EJBComponent)) {
        return;
    }
    final InvocationType invocationType = context.getPrivateData(InvocationType.class);
    ((EJBComponent) component).getAllowedMethodsInformation().realCheckPermission(methodType, invocationType);
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Example 18 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class AsyncFutureInterceptorFactory method create.

@Override
public Interceptor create(final InterceptorFactoryContext context) {
    final SessionBeanComponent component = (SessionBeanComponent) context.getContextData().get(Component.class);
    if (component.isSecurityDomainKnown()) {
        return new Interceptor() {

            @Override
            public Object processInvocation(final InterceptorContext context) throws Exception {
                if (!context.isBlockingCaller()) {
                    return context.proceed();
                }
                final InterceptorContext asyncInterceptorContext = context.clone();
                asyncInterceptorContext.putPrivateData(InvocationType.class, InvocationType.ASYNC);
                final CancellationFlag flag = new CancellationFlag();
                final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class);
                final StartupCountdown.Frame frame = StartupCountdown.current();
                final SecurityIdentity currentIdentity = securityDomain == null ? null : securityDomain.getCurrentSecurityIdentity();
                final Connection remoteConnection = getConnection();
                Callable<Object> invocationTask = () -> {
                    setConnection(remoteConnection);
                    StartupCountdown.restore(frame);
                    try {
                        return asyncInterceptorContext.proceed();
                    } finally {
                        StartupCountdown.restore(null);
                        clearConnection();
                    }
                };
                final AsyncInvocationTask task = new AsyncInvocationTask(flag) {

                    @Override
                    protected Object runInvocation() throws Exception {
                        if (currentIdentity != null) {
                            return currentIdentity.runAs(invocationTask);
                        } else {
                            return invocationTask.call();
                        }
                    }
                };
                asyncInterceptorContext.putPrivateData(CancellationFlag.class, flag);
                asyncInterceptorContext.setBlockingCaller(false);
                return execute(component, task);
            }
        };
    } else {
        return new Interceptor() {

            @Override
            public Object processInvocation(final InterceptorContext context) throws Exception {
                if (!context.isBlockingCaller()) {
                    return context.proceed();
                }
                final InterceptorContext asyncInterceptorContext = context.clone();
                asyncInterceptorContext.putPrivateData(InvocationType.class, InvocationType.ASYNC);
                final CancellationFlag flag = new CancellationFlag();
                final SecurityContext securityContext;
                if (WildFlySecurityManager.isChecking()) {
                    securityContext = AccessController.doPrivileged(new PrivilegedAction<SecurityContext>() {

                        @Override
                        public SecurityContext run() {
                            return SecurityContextAssociation.getSecurityContext();
                        }
                    });
                } else {
                    securityContext = SecurityContextAssociation.getSecurityContext();
                }
                // clone the original security context so that changes to the original security context in a separate (caller/unrelated) thread doesn't affect
                // the security context associated with the async invocation thread
                final SecurityContext clonedSecurityContext;
                if (securityContext instanceof JBossSecurityContext) {
                    clonedSecurityContext = (SecurityContext) ((JBossSecurityContext) securityContext).clone();
                } else {
                    // we can't do anything if it isn't a JBossSecurityContext so just use the original one
                    clonedSecurityContext = securityContext;
                }
                final Connection remoteConnection = getConnection();
                final StartupCountdown.Frame frame = StartupCountdown.current();
                final AsyncInvocationTask task = new AsyncInvocationTask(flag) {

                    @Override
                    protected Object runInvocation() throws Exception {
                        setSecurityContextOnAssociation(clonedSecurityContext);
                        setConnection(remoteConnection);
                        StartupCountdown.restore(frame);
                        try {
                            return asyncInterceptorContext.proceed();
                        } finally {
                            StartupCountdown.restore(null);
                            try {
                                clearSecurityContextOnAssociation();
                            } finally {
                                clearConnection();
                            }
                        }
                    }
                };
                asyncInterceptorContext.putPrivateData(CancellationFlag.class, flag);
                asyncInterceptorContext.setBlockingCaller(false);
                return execute(component, task);
            }
        };
    }
}
Also used : Connection(org.jboss.remoting3.Connection) SecurityDomain(org.wildfly.security.auth.server.SecurityDomain) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) PrivilegedAction(java.security.PrivilegedAction) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) InterceptorContext(org.jboss.invocation.InterceptorContext) SecurityContext(org.jboss.security.SecurityContext) JBossSecurityContext(org.jboss.security.plugins.JBossSecurityContext) JBossSecurityContext(org.jboss.security.plugins.JBossSecurityContext) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) Component(org.jboss.as.ee.component.Component) Interceptor(org.jboss.invocation.Interceptor) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown)

Example 19 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class SessionBeanHomeInterceptorFactory method create.

@Override
public Interceptor create(final InterceptorFactoryContext context) {
    return new Interceptor() {

        @Override
        public Object processInvocation(final InterceptorContext context) throws Exception {
            final ComponentView view = viewToCreate.getValue();
            try {
                INIT_METHOD.set(method);
                INIT_PARAMETERS.set(context.getParameters());
                final ManagedReference instance = view.createInstance();
                return instance.getInstance();
            } finally {
                INIT_METHOD.remove();
                INIT_PARAMETERS.remove();
            }
        }
    };
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) InterceptorContext(org.jboss.invocation.InterceptorContext) ManagedReference(org.jboss.as.naming.ManagedReference) Interceptor(org.jboss.invocation.Interceptor)

Example 20 with InterceptorContext

use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.

the class AroundConstructInterceptorFactory method create.

@Override
public Interceptor create(final InterceptorFactoryContext context) {
    final Interceptor aroundConstruct = aroundConstrctChain.create(context);
    return new Interceptor() {

        @Override
        public Object processInvocation(final InterceptorContext context) throws Exception {
            aroundConstruct.processInvocation(context);
            context.setParameters(null);
            return context.proceed();
        }
    };
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) Interceptor(org.jboss.invocation.Interceptor)

Aggregations

InterceptorContext (org.jboss.invocation.InterceptorContext)29 Interceptor (org.jboss.invocation.Interceptor)8 Method (java.lang.reflect.Method)4 Component (org.jboss.as.ee.component.Component)4 ComponentView (org.jboss.as.ee.component.ComponentView)4 ManagedReference (org.jboss.as.naming.ManagedReference)4 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)3 SessionBeanComponent (org.jboss.as.ejb3.component.session.SessionBeanComponent)3 SecurityContext (org.jboss.security.SecurityContext)3 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)3 PrivilegedAction (java.security.PrivilegedAction)2 HashMap (java.util.HashMap)2 ComponentFactory (org.jboss.as.ee.component.ComponentFactory)2 StartupCountdown (org.jboss.as.ee.component.deployers.StartupCountdown)2 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)2 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)2 CancellationFlag (org.jboss.as.ejb3.component.interceptors.CancellationFlag)2 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)2 SkeletonStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy)2 ObjectStreamException (java.io.ObjectStreamException)1