All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.security.deployment.AdditionalRolesAllowedTransformer Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package io.quarkus.security.deployment;

import static io.quarkus.security.deployment.SecurityProcessor.createMethodDescription;
import static io.quarkus.security.deployment.SecurityTransformerUtils.ROLES_ALLOWED;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;

import io.quarkus.arc.processor.AnnotationsTransformer;
import io.quarkus.security.spi.runtime.MethodDescription;

public class AdditionalRolesAllowedTransformer implements AnnotationsTransformer {

    private final Set methods;
    private final AnnotationValue[] rolesAllowed;

    public AdditionalRolesAllowedTransformer(Collection methods, List rolesAllowed) {
        this.methods = new HashSet<>(methods);
        this.rolesAllowed = rolesAllowed.stream().map(s -> AnnotationValue.createStringValue("", s))
                .toArray(AnnotationValue[]::new);
    }

    @Override
    public boolean appliesTo(AnnotationTarget.Kind kind) {
        return kind == AnnotationTarget.Kind.METHOD;
    }

    @Override
    public void transform(TransformationContext context) {
        MethodDescription method = createMethodDescription(context.getTarget().asMethod());
        if (methods.contains(method)) {
            context.transform().add(ROLES_ALLOWED, AnnotationValue.createArrayValue("value", rolesAllowed)).done();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy