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;
}
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);
}
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);
}
};
}
}
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();
}
}
};
}
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();
}
};
}
Aggregations