Skip to content
Snippets Groups Projects
Commit cc8b6468 authored by Addin Munawwar's avatar Addin Munawwar
Browse files

feat: handle api key from http header

parent 4cd44aec
Branches
Tags
No related merge requests found
FROM maven:3.6.3-amazoncorretto-8
FROM amazoncorretto:8u392
COPY . /usr/src/app
WORKDIR /usr/src/app
......@@ -6,4 +6,5 @@ RUN mvn clean package assembly:assembly
EXPOSE 8080
ENTRYPOINT [ "java", "-cp", "target/soap_service-1.0-jar-with-dependencies.jar", "com.soap.Main" ]
# CMD java -cp target/soap_service-1.0-jar-with-dependencies.jar com.soap.Main
\ No newline at end of file
# CMD java -cp target/soap_service-1.0-jar-with-dependencies.jar com.soap.Main
version: '3.3'
services:
soap_service:
build:
context: .
dockerfile: Dockerfile
container_name: soap_service
env_file:
- .env
ports:
- '${APP_PORT:-8080}:${APP_PORT:-8080}'
volumes:
- .:/var/www/html
links:
- db
depends_on:
- db
# soap_service:
# build:
# context: .
# dockerfile: Dockerfile
# container_name: soap_service
# env_file:
# - .env
# ports:
# - '8080:8080'
# volumes:
# - .:/var/www/html
# links:
# - db
# depends_on:
# - db
db:
image: mysql:latest
container_name: soap_db
......
package com.soap.middlewares;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
......@@ -47,8 +48,18 @@ public class ApiKeyHandler implements SOAPHandler<SOAPMessageContext>{
String receivedApiKey = extractApiKeyFromHeader(context);
if (receivedApiKey == null) {
SOAPFaultException soapFaultException = generateSoapFaultException("API key is missing");
throw soapFaultException;
// Try to get api key from HTTP header
Map<String, Object> httpHeaders = (Map<String, Object>) context.get(MessageContext.HTTP_REQUEST_HEADERS);
LinkedList<String> apiKeys = (LinkedList<String>) httpHeaders.get("ApiKey");
if (apiKeys != null && apiKeys.size() > 0) {
receivedApiKey = apiKeys.get(0);
}
System.out.println("receivedApiKey: " + receivedApiKey);
if (receivedApiKey == null) {
SOAPFaultException soapFaultException = generateSoapFaultException("API key is missing");
throw soapFaultException;
}
}
if (!isValidApiKey(receivedApiKey)) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment