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);
}
use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class EjbJarParsingDeploymentUnitProcessor method parseEjbJarXml.
private static EjbJarMetaData parseEjbJarXml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR);
//this is a bit tri
// Locate the descriptor
final VirtualFile descriptor;
if (alternateDescriptor != null) {
descriptor = alternateDescriptor;
} else {
descriptor = getDescriptor(deploymentRoot.getRoot(), EJB_JAR_XML);
}
if (descriptor == null) {
// no descriptor found, nothing to do!
return null;
}
// get the XMLStreamReader and parse the descriptor
MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
InputStream stream = open(descriptor);
try {
XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
EjbJarMetaData ejbJarMetaData = EjbJarMetaDataParser.parse(reader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
return ejbJarMetaData;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.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 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 AbstractPoolMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, T description) throws DeploymentUnitProcessingException {
final String ejbName = description.getEJBName();
final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (metaData == null) {
return;
}
final AssemblyDescriptorMetaData assemblyDescriptor = metaData.getAssemblyDescriptor();
if (assemblyDescriptor == null) {
return;
}
// get the pool metadata
final List<EJBBoundPoolMetaData> pools = assemblyDescriptor.getAny(EJBBoundPoolMetaData.class);
String poolName = null;
if (pools != null) {
for (final EJBBoundPoolMetaData poolMetaData : pools) {
// for the specific bean (i.e. via an ejb-name match)
if ("*".equals(poolMetaData.getEjbName()) && poolName == null) {
poolName = poolMetaData.getPoolName();
} else if (ejbName.equals(poolMetaData.getEjbName())) {
poolName = poolMetaData.getPoolName();
}
}
}
if (poolName != null) {
this.setPoolName(description, poolName);
}
}
use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.
the class ApplicationExceptionMergingProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
return;
}
final List<DeploymentUnit> accessibleSubDeployments = deploymentUnit.getAttachment(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ApplicationExceptions applicationExceptions = new ApplicationExceptions();
for (DeploymentUnit unit : accessibleSubDeployments) {
//we want to get the details for classes from all sub deployments we have access to
final ApplicationExceptionDescriptions exceptionDescriptions = unit.getAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS);
if (exceptionDescriptions != null) {
for (Map.Entry<String, org.jboss.as.ejb3.tx.ApplicationExceptionDetails> exception : exceptionDescriptions.getApplicationExceptions().entrySet()) {
try {
final Class<?> index = ClassLoadingUtils.loadClass(exception.getKey(), module);
applicationExceptions.addApplicationException(index, exception.getValue());
} catch (ClassNotFoundException e) {
ROOT_LOGGER.debug("Could not load application exception class", e);
}
}
}
}
//now add the exceptions from the assembly descriptor
EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
if (ejbJarMetaData != null) {
// process assembly-descriptor stuff
AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetaData.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
// process application-exception(s)
ApplicationExceptionsMetaData ddAppExceptions = assemblyDescriptor.getApplicationExceptions();
if (ddAppExceptions != null && !ddAppExceptions.isEmpty()) {
for (ApplicationExceptionMetaData applicationException : ddAppExceptions) {
String exceptionClassName = applicationException.getExceptionClass();
try {
final Class<?> index = ClassLoadingUtils.loadClass(exceptionClassName, module);
boolean rollback = applicationException.isRollback();
// by default inherited is true
boolean inherited = applicationException.isInherited() == null ? true : applicationException.isInherited();
// add the application exception to the ejb jar description
applicationExceptions.addApplicationException(index, new ApplicationExceptionDetails(exceptionClassName, inherited, rollback));
} catch (ClassNotFoundException e) {
throw EjbLogger.ROOT_LOGGER.failToLoadAppExceptionClassInEjbJarXml(exceptionClassName, e);
}
}
}
}
}
deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DETAILS, applicationExceptions);
}
Aggregations