use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class EjbJarParsingDeploymentUnitProcessor method parseJBossEjb3Xml.
private static EjbJarMetaData parseJBossEjb3Xml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
// Locate the descriptor
final VirtualFile descriptor = getDescriptor(deploymentRoot, JBOSS_EJB3_XML);
if (descriptor == null) {
//but there may have been an ejb-jar element in jboss-all.xml
return deploymentUnit.getAttachment(EjbJarJBossAllParser.ATTACHMENT_KEY);
}
// get the XMLStreamReader and parse the descriptor
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
InputStream stream = open(descriptor);
try {
XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
final JBossEjb3MetaDataParser parser = new JBossEjb3MetaDataParser(createJbossEjbJarParsers());
final EjbJarMetaData ejbJarMetaData = parser.parse(reader, dtdInfo, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
return ejbJarMetaData;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, JBOSS_EJB3_XML + ": " + descriptor.getPathName());
} finally {
try {
stream.close();
} catch (IOException ioe) {
EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
}
}
}
use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class EjbJarParsingDeploymentUnitProcessor method deploy.
/**
* Finds an ejb-jar.xml (at WEB-INF of a .war or META-INF of a .jar) parses the file and creates
* metadata out of it. The metadata is then attached to the deployment unit.
*
* @param deploymentPhase
* @throws DeploymentUnitProcessingException
*
*/
@Override
public void deploy(DeploymentPhaseContext deploymentPhase) throws DeploymentUnitProcessingException {
// get hold of the deployment unit.
final DeploymentUnit deploymentUnit = deploymentPhase.getDeploymentUnit();
// get the root of the deployment unit
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EjbJarMetaData ejbJarMetaData;
final EjbJarMetaData specMetaData = parseEjbJarXml(deploymentUnit);
final EjbJarMetaData jbossMetaData = parseJBossEjb3Xml(deploymentUnit);
if (specMetaData == null) {
if (jbossMetaData == null)
return;
ejbJarMetaData = jbossMetaData;
} else if (jbossMetaData == null) {
ejbJarMetaData = specMetaData;
} else {
ejbJarMetaData = jbossMetaData.createMerged(specMetaData);
}
// Mark it as an EJB deployment
EjbDeploymentMarker.mark(deploymentUnit);
if (!deploymentUnit.hasAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION)) {
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final EjbJarDescription ejbModuleDescription = new EjbJarDescription(moduleDescription, applicationClassesDescription, deploymentUnit.getName().endsWith(".war"));
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbModuleDescription);
}
// attach the EjbJarMetaData to the deployment unit
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA, ejbJarMetaData);
// if the jboss-ejb3.xml has a distinct-name configured then attach it to the deployment unit
if (jbossMetaData != null && jbossMetaData.getDistinctName() != null) {
deploymentUnit.putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, jbossMetaData.getDistinctName());
}
if (ejbJarMetaData.getModuleName() != null) {
eeModuleDescription.setModuleName(ejbJarMetaData.getModuleName());
}
if (ejbJarMetaData.isMetadataComplete()) {
MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
}
if (!ejbJarMetaData.isEJB3x()) {
//EJB spec 20.5.1, we do not process annotations for older deployments
MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
}
if (ejbJarMetaData.getEnterpriseBeans() != null) {
//check for entity beans
StringBuilder beans = new StringBuilder();
boolean error = false;
for (AbstractEnterpriseBeanMetaData bean : ejbJarMetaData.getEnterpriseBeans()) {
if (bean.getEjbType() == EjbType.ENTITY) {
if (!error) {
error = true;
} else {
beans.append(", ");
}
beans.append(bean.getEjbName());
}
}
if (error) {
throw EjbLogger.ROOT_LOGGER.entityBeansAreNotSupported(beans.toString());
}
}
}
use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class EjbIIOPDeploymentUnitProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
return;
}
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
// a bean-name -> IIOPMetaData map, reflecting the assembly descriptor IIOP configuration.
Map<String, IIOPMetaData> iiopMetaDataMap = new HashMap<String, IIOPMetaData>();
final EjbJarMetaData ejbMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbMetaData != null && ejbMetaData.getAssemblyDescriptor() != null) {
List<IIOPMetaData> iiopMetaDatas = ejbMetaData.getAssemblyDescriptor().getAny(IIOPMetaData.class);
if (iiopMetaDatas != null && iiopMetaDatas.size() > 0) {
for (IIOPMetaData metaData : iiopMetaDatas) {
iiopMetaDataMap.put(metaData.getEjbName(), metaData);
}
}
}
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (moduleDescription != null) {
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
if (componentDescription instanceof EJBComponentDescription) {
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
if (ejbComponentDescription.getEjbRemoteView() != null && ejbComponentDescription.getEjbHomeView() != null) {
// check if there is IIOP metadata for the bean - first using the bean name, then the wildcard "*" if needed.
IIOPMetaData iiopMetaData = iiopMetaDataMap.get(ejbComponentDescription.getEJBName());
if (iiopMetaData == null) {
iiopMetaData = iiopMetaDataMap.get(IIOPMetaData.WILDCARD_BEAN_NAME);
}
// has been enabled by default in the EJB3 subsystem.
if (iiopMetaData != null || settingsService.isEnabledByDefault()) {
processEjb(ejbComponentDescription, deploymentReflectionIndex, module, phaseContext.getServiceTarget(), iiopMetaData);
}
}
}
}
}
}
use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class AbstractDeploymentModelBuilder method propagateAttachments.
private void propagateAttachments(final DeploymentUnit unit, final ArchiveDeployment dep) {
dep.addAttachment(DeploymentUnit.class, unit);
unit.putAttachment(DEPLOYMENT_KEY, dep);
final JBossWebMetaData webMD = getJBossWebMetaData(unit);
dep.addAttachment(JBossWebMetaData.class, webMD);
final WebservicesMetaData webservicesMD = getOptionalAttachment(unit, WEBSERVICES_METADATA_KEY);
dep.addAttachment(WebservicesMetaData.class, webservicesMD);
JBossWebservicesMetaData jbossWebservicesMD = getOptionalAttachment(unit, JBOSS_WEBSERVICES_METADATA_KEY);
if (unit.getParent() != null) {
jbossWebservicesMD = JBossWebservicesMetaData.merge(getOptionalAttachment(unit.getParent(), JBOSS_WEBSERVICES_METADATA_KEY), jbossWebservicesMD);
}
dep.addAttachment(JBossWebservicesMetaData.class, jbossWebservicesMD);
final JAXWSDeployment jaxwsDeployment = getOptionalAttachment(unit, JAXWS_ENDPOINTS_KEY);
dep.addAttachment(JAXWSDeployment.class, jaxwsDeployment);
final EjbJarMetaData ejbJarMD = getOptionalAttachment(unit, EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
dep.addAttachment(EjbJarMetaData.class, ejbJarMD);
final RejectionRule rr = getOptionalAttachment(unit, REJECTION_RULE_KEY);
if (rr != null) {
dep.addAttachment(RejectionRule.class, rr);
}
}
use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class WSIntegrationProcessorJAXWS_EJB method getDeclaredSecurityRoles.
private static Set<String> getDeclaredSecurityRoles(final DeploymentUnit unit, final ClassInfo webServiceClassInfo) {
final Set<String> securityRoles = new HashSet<String>();
// process assembly-descriptor DD section
final EjbJarMetaData ejbJarMD = unit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMD != null && ejbJarMD.getAssemblyDescriptor() != null) {
final List<SecurityRoleMetaData> securityRoleMetaDatas = ejbJarMD.getAssemblyDescriptor().getAny(SecurityRoleMetaData.class);
if (securityRoleMetaDatas != null) {
for (final SecurityRoleMetaData securityRoleMetaData : securityRoleMetaDatas) {
securityRoles.add(securityRoleMetaData.getRoleName());
}
}
final SecurityRolesMetaData securityRolesMD = ejbJarMD.getAssemblyDescriptor().getSecurityRoles();
if (securityRolesMD != null && securityRolesMD.size() > 0) {
for (final SecurityRoleMetaData securityRoleMD : securityRolesMD) {
securityRoles.add(securityRoleMD.getRoleName());
}
}
}
// process @RolesAllowed annotation
if (webServiceClassInfo.annotations().containsKey(ROLES_ALLOWED_ANNOTATION)) {
final List<AnnotationInstance> allowedRoles = webServiceClassInfo.annotations().get(ROLES_ALLOWED_ANNOTATION);
for (final AnnotationInstance allowedRole : allowedRoles) {
if (allowedRole.target().equals(webServiceClassInfo)) {
for (final String roleName : allowedRole.value().asStringArray()) {
securityRoles.add(roleName);
}
}
}
}
// process @DeclareRoles annotation
if (webServiceClassInfo.annotations().containsKey(DECLARE_ROLES_ANNOTATION)) {
final List<AnnotationInstance> declareRoles = webServiceClassInfo.annotations().get(DECLARE_ROLES_ANNOTATION);
for (final AnnotationInstance declareRole : declareRoles) {
if (declareRole.target().equals(webServiceClassInfo)) {
for (final String roleName : declareRole.value().asStringArray()) {
securityRoles.add(roleName);
}
}
}
}
// process @PermitAll annotation
if (webServiceClassInfo.annotations().containsKey(PERMIT_ALL_ANNOTATION)) {
for (AnnotationInstance permitAll : webServiceClassInfo.annotations().get(PERMIT_ALL_ANNOTATION)) {
if (permitAll.target().equals(webServiceClassInfo)) {
securityRoles.add("*");
break;
}
}
}
//if there is no class level security annotation, it will delegate to ejb's security check
if (securityRoles.isEmpty()) {
securityRoles.add("*");
}
return Collections.unmodifiableSet(securityRoles);
}
Aggregations