use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.
the class JandexUtil method getRepeatableAnnotation.
/**
* Many OAI annotations can either be found singly or as a wrapped array. This method will
* look for both and return a list of all found. Both the single and wrapper annotation names
* must be provided.
* @param method
* @param singleAnnotationName
* @param repeatableAnnotationName
*/
public static List<AnnotationInstance> getRepeatableAnnotation(MethodInfo method, DotName singleAnnotationName, DotName repeatableAnnotationName) {
List<AnnotationInstance> annotations = new ArrayList<>(method.annotations());
CollectionUtils.filter(annotations, new Predicate() {
@Override
public boolean evaluate(Object object) {
AnnotationInstance annotation = (AnnotationInstance) object;
return annotation.name().equals(singleAnnotationName);
}
});
if (repeatableAnnotationName != null && method.hasAnnotation(repeatableAnnotationName)) {
AnnotationInstance annotation = method.annotation(repeatableAnnotationName);
AnnotationValue annotationValue = annotation.value();
if (annotationValue != null) {
AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
annotations.addAll(Arrays.asList(nestedArray));
}
}
return annotations;
}
use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.
the class JandexUtil method getRepeatableAnnotation.
/**
* Many OAI annotations can either be found singly or as a wrapped array. This method will
* look for both and return a list of all found. Both the single and wrapper annotation names
* must be provided.
* @param clazz
* @param singleAnnotationName
* @param repeatableAnnotationName
*/
public static List<AnnotationInstance> getRepeatableAnnotation(ClassInfo clazz, DotName singleAnnotationName, DotName repeatableAnnotationName) {
List<AnnotationInstance> annotations = new ArrayList<>();
AnnotationInstance single = JandexUtil.getClassAnnotation(clazz, singleAnnotationName);
AnnotationInstance repeatable = JandexUtil.getClassAnnotation(clazz, repeatableAnnotationName);
if (single != null) {
annotations.add(single);
}
if (repeatable != null) {
AnnotationValue annotationValue = repeatable.value();
if (annotationValue != null) {
AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
annotations.addAll(Arrays.asList(nestedArray));
}
}
return annotations;
}
use of org.jboss.jandex.AnnotationValue in project wildfly-swarm by wildfly-swarm.
the class MPJWTAuthExtensionArchivePreparer method process.
@Override
public void process() throws Exception {
WARArchive war = archive.as(WARArchive.class);
// Check for LoginConfig annotation
Collection<AnnotationInstance> lcAnnotations = index.getAnnotations(LOGIN_CONFIG);
for (AnnotationInstance lc : lcAnnotations) {
AnnotationValue authMethod = lc.value("authMethod");
AnnotationValue realmName = lc.value("realmName");
String realm = realmName != null ? realmName.asString() : "";
// Set the web.xml login-config auth-method and jboss-web.xml security domain
if (authMethod != null) {
WebXmlAsset webXml = war.findWebXmlAsset();
webXml.setLoginConfig(authMethod.asString(), realm);
}
if (realm.length() > 0) {
JBossWebAsset jBossWeb = war.findJbossWebAsset();
jBossWeb.setSecurityDomain(realm);
}
}
// Get the @ApplicationPath setting
WebXmlAsset webXml = war.findWebXmlAsset();
String appPath = "/";
Collection<AnnotationInstance> appPaths = index.getAnnotations(APP_PATH);
if (!appPaths.isEmpty()) {
appPath = appPaths.iterator().next().value().asString();
}
// Process the @RolesAllowed, @PermitAll and @DenyAll annotations
Collection<AnnotationInstance> rolesAnnotations = index.getAnnotations(ROLES_ALLOWED);
for (AnnotationInstance annotation : rolesAnnotations) {
if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
// Process the root resource
String[] roles = annotation.value().asStringArray();
ClassInfo classInfo = annotation.target().asClass();
if (!scannedClasses.contains(classInfo.name())) {
generateSecurityConstraints(webXml, classInfo, roles, appPath);
}
} else if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) {
// Process the containing root resource if it has not been already
MethodInfo methodInfo = annotation.target().asMethod();
ClassInfo classInfo = methodInfo.declaringClass();
if (!scannedClasses.contains(classInfo.name())) {
String[] roles = {};
generateSecurityConstraints(webXml, classInfo, roles, appPath);
}
}
}
// Handle the verification configuration on the fraction
if (fraction.getTokenIssuer().isPresent()) {
log.debugf("Issuer: %s", fraction.getTokenIssuer().get());
war.addAsManifestResource(new StringAsset(fraction.getTokenIssuer().get()), "MP-JWT-ISSUER");
}
if (fraction.getPublicKey() != null) {
log.debugf("PublicKey: %s", fraction.getPublicKey());
war.addAsManifestResource(new StringAsset(fraction.getPublicKey()), "MP-JWT-SIGNER");
}
if (log.isTraceEnabled()) {
log.trace("war: " + war.toString(true));
}
}
use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class MessageDrivenComponentDescriptionFactory method getMessageListenerInterface.
private String getMessageListenerInterface(final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface");
if (value != null)
return value.asClass().name().toString();
final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target();
final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass));
// check super class(es) of the bean
DotName superClassDotName = beanClass.superName();
while (interfaces.isEmpty() && superClassDotName != null && !superClassDotName.toString().equals(Object.class.getName())) {
ClassInfo superClass = compositeIndex.getClassByName(superClassDotName);
if (superClass == null) {
final DeploymentUnit parent = deploymentUnit.getParent();
if (parent != null) {
final CompositeIndex parentIndex = parent.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (parentIndex != null) {
superClass = parentIndex.getClassByName(superClassDotName);
}
}
}
if (superClass == null) {
break;
}
interfaces.addAll(getPotentialViewInterfaces(superClass));
// move to next super class
superClassDotName = superClass.superName();
}
if (interfaces.size() != 1)
throw EjbLogger.ROOT_LOGGER.mdbDoesNotImplementNorSpecifyMessageListener(beanClass);
return interfaces.iterator().next().toString();
}
use of org.jboss.jandex.AnnotationValue in project wildfly by wildfly.
the class SessionBeanComponentDescriptionFactory method processSessionBeans.
private void processSessionBeans(final DeploymentUnit deploymentUnit, final List<AnnotationInstance> sessionBeanAnnotations, final SessionBeanComponentDescription.SessionBeanType annotatedSessionBeanType) {
final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
// process these session bean annotations and create component descriptions out of it
for (final AnnotationInstance sessionBeanAnnotation : sessionBeanAnnotations) {
final AnnotationTarget target = sessionBeanAnnotation.target();
if (!(target instanceof ClassInfo)) {
// Let's just WARN and move on. No need to throw an error
EjbLogger.DEPLOYMENT_LOGGER.warn(EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(sessionBeanAnnotation.name().toString(), target).getMessage());
continue;
}
final ClassInfo sessionBeanClassInfo = (ClassInfo) target;
// skip if it's not a valid class for session bean
if (!assertSessionBeanClassValidity(sessionBeanClassInfo)) {
continue;
}
final String ejbName = sessionBeanClassInfo.name().local();
final AnnotationValue nameValue = sessionBeanAnnotation.value("name");
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
final SessionBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, SessionBeanMetaData.class);
final SessionBeanComponentDescription.SessionBeanType sessionBeanType;
final String beanClassName;
if (beanMetaData != null) {
beanClassName = override(sessionBeanClassInfo.name().toString(), beanMetaData.getEjbClass());
sessionBeanType = override(annotatedSessionBeanType, descriptionOf(((SessionBeanMetaData) beanMetaData).getSessionType()));
} else {
beanClassName = sessionBeanClassInfo.name().toString();
sessionBeanType = annotatedSessionBeanType;
}
final SessionBeanComponentDescription sessionBeanDescription;
switch(sessionBeanType) {
case STATELESS:
sessionBeanDescription = new StatelessComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData, defaultSlsbPoolAvailable);
break;
case STATEFUL:
sessionBeanDescription = new StatefulComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
// If passivation is disabled for the SFSB, either via annotation or via DD, then setup the component
// description appropriately
final boolean passivationCapableAnnotationValue = sessionBeanAnnotation.value("passivationCapable") == null ? true : sessionBeanAnnotation.value("passivationCapable").asBoolean();
final Boolean passivationCapableDeploymentDescriptorValue;
if ((beanMetaData instanceof SessionBean32MetaData)) {
passivationCapableDeploymentDescriptorValue = ((SessionBean32MetaData) beanMetaData).isPassivationCapable();
} else {
passivationCapableDeploymentDescriptorValue = null;
}
final boolean passivationApplicable = override(passivationCapableDeploymentDescriptorValue, passivationCapableAnnotationValue);
((StatefulComponentDescription) sessionBeanDescription).setPassivationApplicable(passivationApplicable);
break;
case SINGLETON:
if (sessionBeanClassInfo.interfaceNames().contains(SESSION_BEAN_INTERFACE)) {
EjbLogger.ROOT_LOGGER.singletonCantImplementSessionBean(beanClassName);
}
sessionBeanDescription = new SingletonComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, beanMetaData);
break;
default:
throw EjbLogger.ROOT_LOGGER.unknownSessionBeanType(sessionBeanType.name());
}
addComponent(deploymentUnit, sessionBeanDescription);
final AnnotationValue mappedNameValue = sessionBeanAnnotation.value("mappedName");
if (mappedNameValue != null && !mappedNameValue.asString().isEmpty()) {
EjbLogger.ROOT_LOGGER.mappedNameNotSupported(mappedNameValue != null ? mappedNameValue.asString() : "", ejbName);
}
}
EjbDeploymentMarker.mark(deploymentUnit);
}
Aggregations