io.quarkus.resteasy.reactive.server.runtime.exceptionmappers.SecurityExceptionMapperUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-rest Show documentation
Show all versions of quarkus-rest Show documentation
A Jakarta REST implementation utilizing build time processing and Vert.x. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on it.
The newest version!
package io.quarkus.resteasy.reactive.server.runtime.exceptionmappers;
import static org.jboss.resteasy.reactive.server.exceptionmappers.AsyncExceptionMappingUtil.DEFAULT_UNAUTHORIZED_RESPONSE;
import java.util.function.Function;
import jakarta.ws.rs.core.Response;
import io.quarkus.vertx.http.runtime.security.ChallengeData;
import io.quarkus.vertx.http.runtime.security.HttpAuthenticator;
import io.smallrye.mutiny.Uni;
import io.vertx.ext.web.RoutingContext;
final class SecurityExceptionMapperUtil {
private SecurityExceptionMapperUtil() {
}
static Uni handleWithAuthenticator(RoutingContext routingContext) {
HttpAuthenticator authenticator = routingContext.get(HttpAuthenticator.class.getName());
if (authenticator != null) {
Uni challenge = authenticator.getChallenge(routingContext);
return challenge.map(new Function() {
@Override
public Response apply(ChallengeData challengeData) {
if (challengeData == null) {
return DEFAULT_UNAUTHORIZED_RESPONSE;
}
Response.ResponseBuilder status = Response.status(challengeData.status);
if (challengeData.headerName != null) {
status.header(challengeData.headerName.toString(), challengeData.headerContent);
}
return status.build();
}
}).onFailure().recoverWithItem(DEFAULT_UNAUTHORIZED_RESPONSE);
} else {
return Uni.createFrom().item(DEFAULT_UNAUTHORIZED_RESPONSE);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy