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

io.quarkiverse.zanzibar.runtime.ZanzibarRecorder Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package io.quarkiverse.zanzibar.runtime;

import java.time.Duration;
import java.util.Optional;
import java.util.function.Supplier;

import io.quarkiverse.zanzibar.RelationshipManager;
import io.quarkiverse.zanzibar.UserIdExtractor;
import io.quarkiverse.zanzibar.jaxrs.ZanzibarDynamicFeature;
import io.quarkiverse.zanzibar.jaxrs.ZanzibarReactiveAuthorizationFilter;
import io.quarkiverse.zanzibar.jaxrs.ZanzibarSynchronousAuthorizationFilter;
import io.quarkus.arc.Arc;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class ZanzibarRecorder {

    public RuntimeValue createSynchronousFilterFactory() {
        return new RuntimeValue<>(ZanzibarSynchronousAuthorizationFilter::new);
    }

    public RuntimeValue createReactiveFilterFactory() {
        return new RuntimeValue<>(ZanzibarReactiveAuthorizationFilter::new);
    }

    public Supplier createDynamicFeature(Optional unauthenticatedUserId, Duration duration,
            boolean denyUnannotated, RuntimeValue filterFactory) {
        return () -> {
            try (var relationshipManager = Arc.container().instance(RelationshipManager.class);
                    var zanzibarUserIdExtractor = Arc.container().instance(UserIdExtractor.class)) {

                return new ZanzibarDynamicFeature(relationshipManager.get(),
                        zanzibarUserIdExtractor.get(),
                        unauthenticatedUserId, duration, denyUnannotated, filterFactory.getValue());
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy