Skip to content

Commit

Permalink
Avoid using deprecated InterceptorBindingRegistrar#registerAdditional…
Browse files Browse the repository at this point in the history
…Bindings
  • Loading branch information
gastaldi committed Aug 25, 2021
1 parent 66be642 commit c5c27c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 40 deletions.
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 @@ -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(ToBeBindingWithBindingField.class, Collections.singleton("value")),
InterceptorBinding.of(ToBeBindingWithBindingField.class));
}
}

Expand Down

0 comments on commit c5c27c0

Please sign in to comment.