use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class MethodPermissionsMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentDescription) throws DeploymentUnitProcessingException {
//Add the configurator that calculates JACC permissions
//TODO: should this be elsewhere?
componentDescription.getConfigurators().add(new EjbJaccConfigurator());
//DO NOT USE componentConfiguration.getDescriptorData()
//It will return null if there is no <enterprise-beans/> declaration even if there is an assembly descriptor entry
EjbJarMetaData ejbJarMetadata = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetadata != null) {
final AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetadata.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
//handle wildcard exclude-list
final ExcludeListMetaData wildCardExcludeList = assemblyDescriptor.getExcludeListByEjbName("*");
if (wildCardExcludeList != null && wildCardExcludeList.getMethods() != null) {
handleExcludeMethods(componentDescription, wildCardExcludeList);
}
//handle ejb-specific exclude-list
final ExcludeListMetaData excludeList = assemblyDescriptor.getExcludeListByEjbName(componentDescription.getEJBName());
if (excludeList != null && excludeList.getMethods() != null) {
handleExcludeMethods(componentDescription, excludeList);
}
//handle wildcard method permissions
final MethodPermissionsMetaData wildCardMethodPermissions = assemblyDescriptor.getMethodPermissionsByEjbName("*");
if (wildCardMethodPermissions != null) {
handleMethodPermissions(componentDescription, wildCardMethodPermissions);
}
//handle ejb-specific method permissions
final MethodPermissionsMetaData methodPermissions = assemblyDescriptor.getMethodPermissionsByEjbName(componentDescription.getEJBName());
if (methodPermissions != null) {
handleMethodPermissions(componentDescription, methodPermissions);
}
}
}
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class MethodPermissionsMergingProcessor method handleMethodPermissions.
private void handleMethodPermissions(final EJBComponentDescription componentDescription, final MethodPermissionsMetaData methodPermissions) {
for (final MethodPermissionMetaData methodPermissionMetaData : methodPermissions) {
final MethodsMetaData methods = methodPermissionMetaData.getMethods();
for (final MethodMetaData method : methods) {
EJBMethodSecurityAttribute ejbMethodSecurityMetaData;
// EJB 3.1 FR 17.3.2.2 The unchecked element is used instead of a role name in the method-permission element to indicate that all roles are permitted.
if (methodPermissionMetaData.isNotChecked()) {
ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.permitAll();
} else {
ejbMethodSecurityMetaData = EJBMethodSecurityAttribute.rolesAllowed(methodPermissionMetaData.getRoles());
}
final String methodName = method.getMethodName();
final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
if (methodName.equals("*")) {
final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle1(methodIntf, null);
ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, null, ejbMethodSecurityMetaData);
} else {
final MethodParametersMetaData methodParams = method.getMethodParams();
// update the session bean description with the tx attribute info
if (methodParams == null) {
final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle2(methodIntf, methodName);
ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, ejbMethodSecurityMetaData, methodName);
} else {
final EJBMethodSecurityAttribute existingRoles = componentDescription.getDescriptorMethodPermissions().getAttributeStyle3(methodIntf, null, methodName, this.getMethodParams(methodParams));
ejbMethodSecurityMetaData = mergeExistingRoles(ejbMethodSecurityMetaData, existingRoles);
componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, ejbMethodSecurityMetaData, null, methodName, this.getMethodParams(methodParams));
}
}
}
}
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class RunAsMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
if (componentConfiguration.getDescriptorData() != null) {
final SecurityIdentityMetaData identity = componentConfiguration.getDescriptorData().getSecurityIdentity();
if (identity != null) {
final RunAsMetaData runAs = identity.getRunAs();
if (runAs != null) {
final String role = runAs.getRoleName();
if (role != null && !role.trim().isEmpty()) {
componentConfiguration.setRunAs(role.trim());
}
}
}
}
if (componentConfiguration.getRunAs() != null) {
String principal = null;
String globalRunAsPrincipal = null;
EjbJarMetaData jbossMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (jbossMetaData != null && jbossMetaData.getAssemblyDescriptor() != null) {
List<EJBBoundSecurityMetaData> securityMetaDatas = jbossMetaData.getAssemblyDescriptor().getAny(EJBBoundSecurityMetaData.class);
if (securityMetaDatas != null) {
for (EJBBoundSecurityMetaData securityMetaData : securityMetaDatas) {
if (securityMetaData.getEjbName().equals(componentConfiguration.getComponentName())) {
principal = securityMetaData.getRunAsPrincipal();
break;
}
// check global run-as principal
if (securityMetaData.getEjbName().equals("*")) {
globalRunAsPrincipal = securityMetaData.getRunAsPrincipal();
continue;
}
}
}
if (principal != null)
componentConfiguration.setRunAsPrincipal(principal);
else if (globalRunAsPrincipal != null)
componentConfiguration.setRunAsPrincipal(globalRunAsPrincipal);
else {
// we only set the run-as-principal to default, if it's not already set (via annotation) on the component
if (componentConfiguration.getRunAsPrincipal() == null) {
componentConfiguration.setRunAsPrincipal(DEFAULT_RUN_AS_PRINCIPAL);
}
}
}
}
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class StartupAwaitDeploymentUnitProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
if (component instanceof EJBComponentDescription) {
component.getConfigurators().add(new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
StartupCountdown countdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
for (ViewConfiguration view : configuration.getViews()) {
EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
if (INTFS.contains(ejbView.getMethodIntf())) {
ejbView.addViewInterceptor(new ImmediateInterceptorFactory(new StartupAwaitInterceptor(countdown)), InterceptorOrder.View.STARTUP_AWAIT_INTERCEPTOR);
}
}
}
});
}
}
}
use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.
the class DeploymentDescriptorInterceptorBindingsProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final DeploymentReflectionIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
if (metaData == null) {
return;
}
if (metaData.getAssemblyDescriptor() == null) {
return;
}
if (metaData.getAssemblyDescriptor().getInterceptorBindings() == null) {
return;
}
//default interceptors must be mentioned in the interceptors section
final Set<String> interceptorClasses = new HashSet<String>();
if (metaData.getInterceptors() != null) {
for (final InterceptorMetaData interceptor : metaData.getInterceptors()) {
interceptorClasses.add(interceptor.getInterceptorClass());
}
}
final Map<String, List<InterceptorBindingMetaData>> bindingsPerComponent = new HashMap<String, List<InterceptorBindingMetaData>>();
final List<InterceptorBindingMetaData> defaultInterceptorBindings = new ArrayList<InterceptorBindingMetaData>();
for (final InterceptorBindingMetaData binding : metaData.getAssemblyDescriptor().getInterceptorBindings()) {
if (binding.getEjbName().equals("*")) {
if (binding.getMethod() != null) {
throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotBindToMethod();
}
if (binding.getInterceptorOrder() != null) {
throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotSpecifyOrder();
}
defaultInterceptorBindings.add(binding);
} else if (ejbNameRegexService.isEjbNameRegexAllowed()) {
Pattern pattern = Pattern.compile(binding.getEjbName());
for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) {
if (componentDescription instanceof EJBComponentDescription) {
String ejbName = ((EJBComponentDescription) componentDescription).getEJBName();
if (pattern.matcher(ejbName).matches()) {
List<InterceptorBindingMetaData> bindings = bindingsPerComponent.get(ejbName);
if (bindings == null) {
bindingsPerComponent.put(ejbName, bindings = new ArrayList<InterceptorBindingMetaData>());
}
bindings.add(binding);
}
}
}
} else {
List<InterceptorBindingMetaData> bindings = bindingsPerComponent.get(binding.getEjbName());
if (bindings == null) {
bindingsPerComponent.put(binding.getEjbName(), bindings = new ArrayList<InterceptorBindingMetaData>());
}
bindings.add(binding);
}
}
final List<InterceptorDescription> defaultInterceptors = new ArrayList<InterceptorDescription>();
for (InterceptorBindingMetaData binding : defaultInterceptorBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String clazz : binding.getInterceptorClasses()) {
//we only want default interceptors referenced in the interceptors section
if (interceptorClasses.contains(clazz)) {
defaultInterceptors.add(new InterceptorDescription(clazz));
} else {
ROOT_LOGGER.defaultInterceptorClassNotListed(clazz);
}
}
}
}
//we iterate over all components, as we need to process default interceptors
for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) {
final Class<?> componentClass;
try {
componentClass = module.getClassLoader().loadClass(componentDescription.getComponentClassName());
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadComponentClass(e, componentDescription.getComponentClassName());
}
final List<InterceptorBindingMetaData> bindings = bindingsPerComponent.get(componentDescription.getComponentName());
final Map<Method, List<InterceptorBindingMetaData>> methodInterceptors = new HashMap<Method, List<InterceptorBindingMetaData>>();
final List<InterceptorBindingMetaData> classLevelBindings = new ArrayList<InterceptorBindingMetaData>();
//we only want to exclude default and class level interceptors if every binding
//has the exclude element.
boolean classLevelExcludeDefaultInterceptors = false;
Map<Method, Boolean> methodLevelExcludeDefaultInterceptors = new HashMap<Method, Boolean>();
Map<Method, Boolean> methodLevelExcludeClassInterceptors = new HashMap<Method, Boolean>();
//if an absolute order has been defined at any level
//absolute ordering takes precedence
boolean classLevelAbsoluteOrder = false;
final Map<Method, Boolean> methodLevelAbsoluteOrder = new HashMap<Method, Boolean>();
if (bindings != null) {
for (final InterceptorBindingMetaData binding : bindings) {
if (binding.getMethod() == null) {
classLevelBindings.add(binding);
//if even one binding does not say exclude default then we do not exclude
if (binding.isExcludeDefaultInterceptors()) {
classLevelExcludeDefaultInterceptors = true;
}
if (binding.isTotalOrdering()) {
if (classLevelAbsoluteOrder) {
throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(componentClass.toString());
} else {
classLevelAbsoluteOrder = true;
}
}
} else {
//method level bindings
//first find the right method
final NamedMethodMetaData methodData = binding.getMethod();
final ClassReflectionIndex classIndex = index.getClassIndex(componentClass);
Method resolvedMethod = null;
if (methodData.getMethodParams() == null) {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
if (methods.isEmpty()) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodInEjbJarXml(componentClass.getName(), methodData.getMethodName());
} else if (methods.size() > 1) {
throw EjbLogger.ROOT_LOGGER.multipleMethodReferencedInEjbJarXml(methodData.getMethodName(), componentClass.getName());
}
resolvedMethod = methods.iterator().next();
} else {
final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
for (final Method method : methods) {
boolean match = true;
for (int i = 0; i < method.getParameterTypes().length; ++i) {
if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
match = false;
break;
}
}
if (match) {
resolvedMethod = method;
break;
}
}
if (resolvedMethod == null) {
throw EjbLogger.ROOT_LOGGER.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
}
}
List<InterceptorBindingMetaData> list = methodInterceptors.get(resolvedMethod);
if (list == null) {
methodInterceptors.put(resolvedMethod, list = new ArrayList<InterceptorBindingMetaData>());
}
list.add(binding);
if (binding.isExcludeDefaultInterceptors()) {
methodLevelExcludeDefaultInterceptors.put(resolvedMethod, true);
}
if (binding.isExcludeClassInterceptors()) {
methodLevelExcludeClassInterceptors.put(resolvedMethod, true);
}
if (binding.isTotalOrdering()) {
if (methodLevelAbsoluteOrder.containsKey(resolvedMethod)) {
throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(resolvedMethod.toString());
} else {
methodLevelAbsoluteOrder.put(resolvedMethod, true);
}
}
}
}
}
//now we have all the bindings in a format we can use
//build the list of default interceptors
componentDescription.setDefaultInterceptors(defaultInterceptors);
if (classLevelExcludeDefaultInterceptors) {
componentDescription.setExcludeDefaultInterceptors(true);
}
final List<InterceptorDescription> classLevelInterceptors = new ArrayList<InterceptorDescription>();
if (classLevelAbsoluteOrder) {
//we have an absolute ordering for the class level interceptors
for (final InterceptorBindingMetaData binding : classLevelBindings) {
if (binding.isTotalOrdering()) {
for (final String interceptor : binding.getInterceptorOrder()) {
classLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
//we have merged the default interceptors into the class interceptors
componentDescription.setExcludeDefaultInterceptors(true);
} else {
//the order we want is default interceptors (this will be empty if they are excluded)
//the annotation interceptors
//then dd interceptors
classLevelInterceptors.addAll(componentDescription.getClassInterceptors());
for (InterceptorBindingMetaData binding : classLevelBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String interceptor : binding.getInterceptorClasses()) {
classLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
}
componentDescription.setClassInterceptors(classLevelInterceptors);
for (Map.Entry<Method, List<InterceptorBindingMetaData>> entry : methodInterceptors.entrySet()) {
final Method method = entry.getKey();
final List<InterceptorBindingMetaData> methodBindings = entry.getValue();
boolean totalOrder = methodLevelAbsoluteOrder.containsKey(method);
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
Boolean excludeDefaultInterceptors = methodLevelExcludeDefaultInterceptors.get(method);
excludeDefaultInterceptors = excludeDefaultInterceptors == null ? false : excludeDefaultInterceptors;
if (!excludeDefaultInterceptors) {
excludeDefaultInterceptors = componentDescription.isExcludeDefaultInterceptors() || componentDescription.isExcludeDefaultInterceptors(methodIdentifier);
}
Boolean excludeClassInterceptors = methodLevelExcludeClassInterceptors.get(method);
excludeClassInterceptors = excludeClassInterceptors == null ? false : excludeClassInterceptors;
if (!excludeClassInterceptors) {
excludeClassInterceptors = componentDescription.isExcludeClassInterceptors(methodIdentifier);
}
final List<InterceptorDescription> methodLevelInterceptors = new ArrayList<InterceptorDescription>();
if (totalOrder) {
//if there is a total order we just use it
for (final InterceptorBindingMetaData binding : methodBindings) {
if (binding.isTotalOrdering()) {
for (final String interceptor : binding.getInterceptorOrder()) {
methodLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
} else {
//class level interceptors also includes default interceptors
if (!excludeDefaultInterceptors) {
methodLevelInterceptors.addAll(defaultInterceptors);
}
if (!excludeClassInterceptors) {
for (InterceptorDescription interceptor : classLevelInterceptors) {
methodLevelInterceptors.add(interceptor);
}
}
List<InterceptorDescription> annotationMethodLevel = componentDescription.getMethodInterceptors().get(methodIdentifier);
if (annotationMethodLevel != null) {
methodLevelInterceptors.addAll(annotationMethodLevel);
}
//now add all the interceptors from the bindings
for (InterceptorBindingMetaData binding : methodBindings) {
if (binding.getInterceptorClasses() != null) {
for (final String interceptor : binding.getInterceptorClasses()) {
methodLevelInterceptors.add(new InterceptorDescription(interceptor));
}
}
}
}
//we have already taken component and default interceptors into account
componentDescription.excludeClassInterceptors(methodIdentifier);
componentDescription.excludeDefaultInterceptors(methodIdentifier);
componentDescription.setMethodInterceptors(methodIdentifier, methodLevelInterceptors);
}
}
}
Aggregations