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