diff --git a/CHANGELOG.md b/CHANGELOG.md index d17760d..cd76d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Proteus Changelog. ## Unreleased ### No issue +**Fix Double conversion and add BigDecimal support.** + + +[d425ee1da2fa5a7](https://github.com/noboomu/proteus/commit/d425ee1da2fa5a7) Joshua Bauer *2020-02-25 00:54:22* + **Cleanup poms and improve redirect.** diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java index 8366f49..fc8d581 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java @@ -8,7 +8,6 @@ import io.sinistral.proteus.server.predicates.ServerPredicates; import io.sinistral.proteus.wrappers.JsonViewWrapper; import io.undertow.io.IoCallback; -import io.undertow.server.DefaultResponseListener; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.Cookie; @@ -695,6 +694,7 @@ public static ServerResponse response(Class clazz) return new ServerResponse(); } + public static ServerResponse response(ByteBuffer body) { return new ServerResponse().body(body); diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java index 44e7ab1..a228ebd 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java @@ -787,7 +787,6 @@ else if (m.getReturnType().getTypeName().contains("java.util.concurrent.Completi Annotation securityRequirementAnnotation = Arrays.stream(annotations).filter(a -> a.getClass().getName().contains("SecurityRequirement")).findFirst().orElse(null); - if (securityRequirementAnnotation != null) { if (securityRequirementAnnotation != null) { @@ -803,8 +802,6 @@ else if (m.getReturnType().getTypeName().contains("java.util.concurrent.Completi log.warn("No name field on security requirement"); } - } - } } diff --git a/proteus-openapi/src/main/java/io/sinistral/proteus/openapi/wrappers/HeaderApiKeyWrapper.java b/proteus-openapi/src/main/java/io/sinistral/proteus/openapi/wrappers/HeaderApiKeyWrapper.java new file mode 100644 index 0000000..637e1e6 --- /dev/null +++ b/proteus-openapi/src/main/java/io/sinistral/proteus/openapi/wrappers/HeaderApiKeyWrapper.java @@ -0,0 +1,68 @@ +package io.sinistral.proteus.openapi.wrappers; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.name.Named; +import io.sinistral.proteus.server.exceptions.ServerException; +import io.undertow.server.HandlerWrapper; +import io.undertow.server.HttpHandler; +import io.undertow.util.AttachmentKey; +import io.undertow.util.HttpString; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.core.Response; +import java.util.Optional; + +@Singleton +public class HeaderApiKeyWrapper implements HandlerWrapper +{ + private static final Logger logger = LoggerFactory.getLogger(HeaderApiKeyWrapper.class.getName()); + + public static final AttachmentKey THROWABLE = AttachmentKey.create(Throwable.class); + + @Inject + @Named("openapi.securitySchemes.ApiKeyAuth.name") + protected static String AUTH_KEY_NAME; + + @Inject(optional = true) + @Named("security.apiKey") + protected static String API_KEY; + + private final HttpString API_KEY_HEADER; + + public HeaderApiKeyWrapper() + { + API_KEY_HEADER = new HttpString(AUTH_KEY_NAME); + } + + @Override + public HttpHandler wrap(HttpHandler handler) + { + return exchange -> { + + if(API_KEY == null) + { + handler.handleRequest(exchange); + return; + } + + Optional keyValue = Optional.ofNullable(exchange.getRequestHeaders().getFirst(API_KEY_HEADER)); + + if(!keyValue.isPresent() || !keyValue.get().equals(API_KEY)) + { + + logger.error("Missing security credentials"); + exchange.putAttachment(THROWABLE, new ServerException("Unauthorized access", Response.Status.UNAUTHORIZED)); + throw new ServerException("Unauthorized access", Response.Status.UNAUTHORIZED); + + } + + handler.handleRequest(exchange); + + + + }; + } + +} diff --git a/proteus-openapi/src/main/resources/io/sinistral/proteus/openapi/index.html b/proteus-openapi/src/main/resources/io/sinistral/proteus/openapi/index.html index 72deea1..fa30cbf 100644 --- a/proteus-openapi/src/main/resources/io/sinistral/proteus/openapi/index.html +++ b/proteus-openapi/src/main/resources/io/sinistral/proteus/openapi/index.html @@ -6,7 +6,7 @@ {{ title }} - +