@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (securityIdentity != null) { try { return securityIdentity.runAs((PrivilegedExceptionAction<Object>) (() -> { try { return super.invoke(proxy, method, args); } catch (Throwable e) { throw new WrapperException(e); } })); } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); throw cause instanceof WrapperException ? cause.getCause() : cause; } } else { return super.invoke(proxy, method, args); } }
@Override public <T> T createContextualProxy(T instance, Map<String, String> executionProperties, Class<T> intf) { if (instance == null) { throw new IllegalArgumentException(NULL_INSTANCE); } if (intf == null) { throw new IllegalArgumentException(NO_INTERFACES); } ContextProxyInvocationHandler handler = new ContextProxyInvocationHandler(this, instance, executionProperties); Object proxy = Proxy.newProxyInstance(instance.getClass().getClassLoader(), new Class[]{intf}, handler); return (T) proxy; }
protected ContextProxyInvocationHandler verifyHandler(Object contextObject) { InvocationHandler handler = Proxy.getInvocationHandler(contextObject); if (handler instanceof ContextProxyInvocationHandler) { ContextProxyInvocationHandler cpih = (ContextProxyInvocationHandler) handler; if (cpih.getContextService() != this) { throw new IllegalArgumentException(DIFFERENT_CONTEXTSERVICE); } return cpih; } throw new IllegalArgumentException(INVALID_PROXY); } }
@Override public Map<String, String> getExecutionProperties(Object contextObject) { ContextProxyInvocationHandler handler = verifyHandler(contextObject); return handler.getExecutionProperties(); }
txHandle = transactionSetupProvider.beforeProxyMethod(getTransactionExecutionProperty()); contextSetupProvider.reset(contextHandleForReset); if (transactionSetupProvider != null) { transactionSetupProvider.afterProxyMethod(txHandle, getTransactionExecutionProperty());
@Override public Object createContextualProxy(Object instance, Map<String, String> executionProperties, Class<?>... interfaces) { if (instance == null) { throw new IllegalArgumentException(NULL_INSTANCE); } if (interfaces == null || interfaces.length == 0) { throw new IllegalArgumentException(NO_INTERFACES); } Class instanceClass = instance.getClass(); for (Class thisInterface: interfaces) { if (! thisInterface.isAssignableFrom(instanceClass)) { throw new IllegalArgumentException(CLASS_DOES_NOT_IMPLEMENT_INTERFACES); } } ContextProxyInvocationHandler handler = new ContextProxyInvocationHandler(this, instance, executionProperties); Object proxy = Proxy.newProxyInstance(instance.getClass().getClassLoader(), interfaces, handler); return proxy; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (securityIdentity != null) { try { return securityIdentity.runAs((PrivilegedExceptionAction<Object>) (() -> { try { return super.invoke(proxy, method, args); } catch (Throwable e) { throw new WrapperException(e); } })); } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); throw cause instanceof WrapperException ? cause.getCause() : cause; } } else { return super.invoke(proxy, method, args); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (securityIdentity != null) { try { return securityIdentity.runAs((PrivilegedExceptionAction<Object>) (() -> { try { return super.invoke(proxy, method, args); } catch (Throwable e) { throw new WrapperException(e); } })); } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); throw cause instanceof WrapperException ? cause.getCause() : cause; } } else { return super.invoke(proxy, method, args); } }