Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using deprecated InterceptorBindingRegistrar#registerAdditionalBindings #19656

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package io.quarkus.security.deployment;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.List;

import javax.annotation.security.DenyAll;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;

import org.jboss.jandex.DotName;

import io.quarkus.arc.processor.InterceptorBindingRegistrar;
import io.quarkus.security.Authenticated;

Expand All @@ -19,18 +15,15 @@
*/
public class SecurityAnnotationsRegistrar implements InterceptorBindingRegistrar {

public static final Map<DotName, Set<String>> SECURITY_BINDINGS = new HashMap<>();

static {
// keep the contents the same as in io.quarkus.resteasy.deployment.SecurityTransformerUtils
SECURITY_BINDINGS.put(DotName.createSimple(RolesAllowed.class.getName()), Collections.singleton("value"));
SECURITY_BINDINGS.put(DotName.createSimple(Authenticated.class.getName()), Collections.emptySet());
SECURITY_BINDINGS.put(DotName.createSimple(DenyAll.class.getName()), Collections.emptySet());
SECURITY_BINDINGS.put(DotName.createSimple(PermitAll.class.getName()), Collections.emptySet());
}
static final List<InterceptorBinding> SECURITY_BINDINGS = List.of(
// keep the contents the same as in io.quarkus.resteasy.deployment.SecurityTransformerUtils
InterceptorBinding.of(RolesAllowed.class, Collections.singleton("value")),
InterceptorBinding.of(Authenticated.class),
InterceptorBinding.of(DenyAll.class),
InterceptorBinding.of(PermitAll.class));

@Override
public Map<DotName, Set<String>> registerAdditionalBindings() {
public List<InterceptorBinding> getAdditionalBindings() {
return SECURITY_BINDINGS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.security.DenyAll;
import javax.annotation.security.RolesAllowed;
Expand All @@ -12,13 +13,16 @@
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;

import io.quarkus.arc.processor.InterceptorBindingRegistrar;

/**
* @author Michal Szynkiewicz, [email protected]
*/
public class SecurityTransformerUtils {
public static final DotName DENY_ALL = DotName.createSimple(DenyAll.class.getName());
public static final DotName ROLES_ALLOWED = DotName.createSimple(RolesAllowed.class.getName());
private static final Set<DotName> SECURITY_ANNOTATIONS = SecurityAnnotationsRegistrar.SECURITY_BINDINGS.keySet();
private static final Set<DotName> SECURITY_ANNOTATIONS = SecurityAnnotationsRegistrar.SECURITY_BINDINGS.stream()
.map(InterceptorBindingRegistrar.InterceptorBinding::getName).collect(Collectors.toSet());

public static boolean hasStandardSecurityAnnotation(MethodInfo methodInfo) {
return hasStandardSecurityAnnotation(methodInfo.annotations());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package io.quarkus.spring.security.deployment;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.List;

import org.jboss.jandex.DotName;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;

import io.quarkus.arc.processor.InterceptorBindingRegistrar;

public class SpringSecurityAnnotationsRegistrar implements InterceptorBindingRegistrar {

public static final Map<DotName, Set<String>> SECURITY_BINDINGS = new HashMap<>();

static {
SECURITY_BINDINGS.put(DotName.createSimple(Secured.class.getName()), Collections.singleton("value"));
SECURITY_BINDINGS.put(DotName.createSimple(PreAuthorize.class.getName()), Collections.singleton("value"));
}
private static final List<InterceptorBinding> SECURITY_BINDINGS = List.of(
InterceptorBinding.of(Secured.class, Collections.singleton("value")),
InterceptorBinding.of(PreAuthorize.class, Collections.singleton("value")));

@Override
public Map<DotName, Set<String>> registerAdditionalBindings() {
public List<InterceptorBinding> getAdditionalBindings() {
return SECURITY_BINDINGS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private Interceptors() {
static InterceptorInfo createInterceptor(ClassInfo interceptorClass, BeanDeployment beanDeployment,
InjectionPointModifier transformer, AnnotationStore store) {
Set<AnnotationInstance> bindings = new HashSet<>();
Integer priority = 0;
int priority = 0;
boolean priorityDeclared = false;
for (AnnotationInstance annotation : store.getAnnotations(interceptorClass)) {
bindings.addAll(beanDeployment.extractInterceptorBindings(annotation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.function.Supplier;
import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import org.jboss.jandex.DotName;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -94,14 +90,11 @@ private void assertAfterCall(Class<? extends Pingable> beanClass, Supplier<Boole
static class MyBindingRegistrar implements InterceptorBindingRegistrar {

@Override
public Map<DotName, Set<String>> registerAdditionalBindings() {
Map<DotName, Set<String>> newBindings = new HashMap<>();
newBindings.put(DotName.createSimple(ToBeBinding.class.getName()), Collections.emptySet());
HashSet<String> value = new HashSet<>();
value.add("value");
newBindings.put(DotName.createSimple(ToBeBindingWithNonBindingField.class.getName()), value);
newBindings.put(DotName.createSimple(ToBeBindingWithBindingField.class.getName()), Collections.emptySet());
return newBindings;
public List<InterceptorBinding> getAdditionalBindings() {
return List.of(
InterceptorBinding.of(ToBeBinding.class),
InterceptorBinding.of(ToBeBindingWithNonBindingField.class, Collections.singleton("value")),
InterceptorBinding.of(ToBeBindingWithBindingField.class));
}
}

Expand Down