io.vertx.mutiny.ext.auth.oauth2.OAuth2RBAC Maven / Gradle / Ivy
package io.vertx.mutiny.ext.auth.oauth2;
import java.util.Map;
import java.util.stream.Collectors;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import java.util.function.Consumer;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Publisher;
import io.smallrye.mutiny.vertx.TypeArg;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Future;
/**
* Functional interface that allows users to implement custom RBAC verifiers for OAuth2/OpenId Connect.
*
* Users are to implement the isAuthorized
method to verify authorities. For provides that do not
* export the permissions/roles in the token, this interface allows you to communicate with 3rd party services
* such as graph APIs to collect the required data.
*
* The contract is that once an authority is checked for a given user, it's value is cached during the execution
* of the request. If a user is stored to a persistent storage, or the token is introspected, the cache is cleared
* and a new call will be handled to the implementation.
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.ext.auth.oauth2.OAuth2RBAC original} non Mutiny-ified interface using Vert.x codegen.
*/
@io.smallrye.mutiny.vertx.MutinyGen(io.vertx.ext.auth.oauth2.OAuth2RBAC.class)
public class OAuth2RBAC {
public static final io.smallrye.mutiny.vertx.TypeArg __TYPE_ARG = new io.smallrye.mutiny.vertx.TypeArg<>( obj -> new OAuth2RBAC((io.vertx.ext.auth.oauth2.OAuth2RBAC) obj),
OAuth2RBAC::getDelegate
);
private final io.vertx.ext.auth.oauth2.OAuth2RBAC delegate;
public OAuth2RBAC(io.vertx.ext.auth.oauth2.OAuth2RBAC delegate) {
this.delegate = delegate;
}
public OAuth2RBAC(Object delegate) {
this.delegate = (io.vertx.ext.auth.oauth2.OAuth2RBAC)delegate;
}
/**
* Empty constructor used by CDI, do not use this constructor directly.
**/
OAuth2RBAC() {
this.delegate = null;
}
public io.vertx.ext.auth.oauth2.OAuth2RBAC getDelegate() {
return delegate;
}
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OAuth2RBAC that = (OAuth2RBAC) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
/**
* This method should verify if the user has the given authority and return either a boolean value or an error.
*
* Note that false and errors are not the same. A user might not have a given authority but that doesn't mean that
* there was an error during the call.
*
* Unlike the bare Vert.x variant, this method returns a {@link io.smallrye.mutiny.Uni Uni}.
* Don't forget to subscribe on it to trigger the operation.
* @param user the given user to assert on
* @param authority the authority to lookup
* @return the {@link io.smallrye.mutiny.Uni uni} firing the result of the operation when completed, or a failure if the operation failed.
* @deprecated */
@Deprecated
public io.smallrye.mutiny.Uni isAuthorized(io.vertx.mutiny.ext.auth.oauth2.AccessToken user, String authority) {
return io.smallrye.mutiny.vertx.AsyncResultUni.toUni(handler -> {
delegate.isAuthorized(user.getDelegate(), authority, handler);
});
}
/**
* Blocking variant of {@link io.vertx.mutiny.ext.auth.oauth2.OAuth2RBAC#isAuthorized(io.vertx.mutiny.ext.auth.oauth2.AccessToken,String)}.
*
* This method waits for the completion of the underlying asynchronous operation.
* If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
* @param user the given user to assert on
* @param authority the authority to lookup
* @return the Boolean instance produced by the operation.
* @deprecated */
@Deprecated
public Boolean isAuthorizedAndAwait(io.vertx.mutiny.ext.auth.oauth2.AccessToken user, String authority) {
return (Boolean) isAuthorized(user, authority).await().indefinitely();
}
/**
* Variant of {@link io.vertx.mutiny.ext.auth.oauth2.OAuth2RBAC#isAuthorized(io.vertx.mutiny.ext.auth.oauth2.AccessToken,String)} that ignores the result of the operation.
*
* This method subscribes on the result of {@link io.vertx.mutiny.ext.auth.oauth2.OAuth2RBAC#isAuthorized(io.vertx.mutiny.ext.auth.oauth2.AccessToken,String)}, but discards the outcome (item or failure).
* This method is useful to trigger the asynchronous operation from {@link io.vertx.mutiny.ext.auth.oauth2.OAuth2RBAC#isAuthorized(io.vertx.mutiny.ext.auth.oauth2.AccessToken,String)} but you don't need to compose it with other operations.
* @param user the given user to assert on
* @param authority the authority to lookup
* @deprecated */
@Deprecated
public void isAuthorizedAndForget(io.vertx.mutiny.ext.auth.oauth2.AccessToken user, String authority) {
isAuthorized(user, authority).subscribe().with(io.smallrye.mutiny.vertx.UniHelper.NOOP);
}
public static OAuth2RBAC newInstance(io.vertx.ext.auth.oauth2.OAuth2RBAC arg) {
return arg != null ? new OAuth2RBAC(arg) : null;
}
}