diff --git a/api-rest/pom.xml b/api-rest/pom.xml index d2903be9..5124b94f 100644 --- a/api-rest/pom.xml +++ b/api-rest/pom.xml @@ -30,6 +30,14 @@ + + + com.github + auth + 1.0.0-RC1 + + + com.github rest-common diff --git a/api-rest/src/main/resources/application-db.yml b/api-rest/src/main/resources/application-db.yml index 2794d1b0..2e89305d 100644 --- a/api-rest/src/main/resources/application-db.yml +++ b/api-rest/src/main/resources/application-db.yml @@ -8,7 +8,7 @@ app: schemas: connectionProperties: ssl: false - envProperties: + envProperties: # Not used yet enableDatetimeFormatting: ${ENABLE_DATETIME_FORMATTING:false} timeFormat: ${TIME_FORMAT:HH:mm:ss} dateFormat: ${DATE_FORMAT:yyyy-MM-dd} diff --git a/api-rest/src/main/resources/application-local.yml b/api-rest/src/main/resources/application-local.yml index 4c1e0f80..d03df425 100644 --- a/api-rest/src/main/resources/application-local.yml +++ b/api-rest/src/main/resources/application-local.yml @@ -7,7 +7,7 @@ app: password: homi2022 connectionProperties: ssl: false - envProperties: + envProperties: # Not used yet enableDatetimeFormatting: true timeFormat: 'HH:mm:ss' dateFormat: 'dd-MM-yyyy' diff --git a/api-rest/src/main/resources/application-mongo.yml b/api-rest/src/main/resources/application-mongo.yml index 47dae6f5..cdaa4bd2 100644 --- a/api-rest/src/main/resources/application-mongo.yml +++ b/api-rest/src/main/resources/application-mongo.yml @@ -7,7 +7,7 @@ app: password: homi2022 connectionProperties: ssl: false - envProperties: + envProperties: # Not used yet enableDatetimeFormatting: true timeFormat: 'HH:mm:ss' dateFormat: 'dd-MM-yyyy' diff --git a/api-rest/src/main/resources/application-pg15.yml b/api-rest/src/main/resources/application-pg15.yml new file mode 100644 index 00000000..3bd99c5d --- /dev/null +++ b/api-rest/src/main/resources/application-pg15.yml @@ -0,0 +1,7 @@ +app: + databases: + - name: ${DB_NAME:pgdb} + type: POSTGRESQL + url: jdbc:postgresql://localhost:5432/postgres + username: postgres + password: diff --git a/api-rest/src/main/resources/application-pg16.yml b/api-rest/src/main/resources/application-pg16.yml new file mode 100644 index 00000000..3bd99c5d --- /dev/null +++ b/api-rest/src/main/resources/application-pg16.yml @@ -0,0 +1,7 @@ +app: + databases: + - name: ${DB_NAME:pgdb} + type: POSTGRESQL + url: jdbc:postgresql://localhost:5432/postgres + username: postgres + password: diff --git a/api-rest/src/main/resources/application.yml b/api-rest/src/main/resources/application.yml index 28c395f5..f9da6c49 100644 --- a/api-rest/src/main/resources/application.yml +++ b/api-rest/src/main/resources/application.yml @@ -23,6 +23,14 @@ spring: db2rest: + dateTime: + enableDataTimeFormatting: ${ENABLE_DATETIME_FORMATTING:false} + timeFormat: ${TIME_FORMAT:HH:mm:ss} + dateFormat: ${DATE_FORMAT:yyyy-MM-dd} + dateTimeFormat: ${DATE_TIME_FORMAT:yyyy-MM-dd HH:mm:ss} + + defaultFetchLimit: ${DEFAULT_FETCH_LIMIT:100} + auth: type: ${AUTH_TYPE:none} @@ -45,6 +53,6 @@ logging: com.homihq.db2rest: rest: INFO jdbc.service: INFO - org.springframework.web : INFO + org.springframework.web : DEBUG org.springframework.beans : INFO - org.springframework.jdbc: trace + org.springframework.jdbc: INFO diff --git a/auth/src/main/java/com/homihq/db2rest/auth/AuthConfiguration.java b/auth/src/main/java/com/homihq/db2rest/auth/AuthConfiguration.java new file mode 100644 index 00000000..cef1d9f7 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/AuthConfiguration.java @@ -0,0 +1,31 @@ +package com.homihq.db2rest.auth; + + +import com.auth0.jwt.JWT; +import com.auth0.jwt.JWTVerifier; +import com.homihq.db2rest.auth.jwt.JwtAuthProvider; +import com.homihq.db2rest.auth.jwt.JwtProperties; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +@RequiredArgsConstructor +@ConditionalOnProperty(prefix = "db2rest.auth", name="type" , havingValue = "jwt") +public class AuthConfiguration { + + private final JwtProperties jwtProperties; + + @Bean + public JwtAuthProvider jwtAuthProvider() { + JWTVerifier jwtVerifier = + JWT.require(jwtProperties.getAlgo()) + .withIssuer(jwtProperties.getIssuers()) + .build(); + + return new JwtAuthProvider(jwtVerifier); + } + +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthFilter.java b/auth/src/main/java/com/homihq/db2rest/auth/AuthFilter.java similarity index 61% rename from auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthFilter.java rename to auth/src/main/java/com/homihq/db2rest/auth/AuthFilter.java index f33dd761..7dab8768 100644 --- a/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthFilter.java +++ b/auth/src/main/java/com/homihq/db2rest/auth/AuthFilter.java @@ -1,7 +1,7 @@ -package com.homihq.db2rest.auth.jwt; +package com.homihq.db2rest.auth; import com.fasterxml.jackson.databind.ObjectMapper; -import com.homihq.db2rest.auth.jwt.service.JwtAuthService; +import com.homihq.db2rest.auth.common.AuthProvider; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -11,49 +11,61 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.http.MediaType; import org.springframework.web.filter.OncePerRequestFilter; - import java.io.IOException; import java.time.Instant; import java.util.LinkedHashMap; +import java.util.List; +import java.util.Optional; @RequiredArgsConstructor @Slf4j -public class JwtAuthFilter extends OncePerRequestFilter { +public class AuthFilter extends OncePerRequestFilter { - private final JwtAuthService jwtAuthService; + private final List authProviders; private final ObjectMapper objectMapper; - final String JWT_KEY_HEADER = "Authorization"; + String AUTH_HEADER = "Authorization"; @Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { - String jwtHeader = request.getHeader(JWT_KEY_HEADER); - if (StringUtils.isBlank(jwtHeader) || !jwtHeader.startsWith("Bearer ")) { - addMissingJwtTokenError(request, response); + + log.info("Handling Auth"); + + + String authHeaderValue = request.getHeader(AUTH_HEADER); + + if(StringUtils.isBlank(authHeaderValue)) { + addMissingAuthTokenError(request, response); return; } - String token = StringUtils.replace(jwtHeader, "Bearer ", "", 1); - if (!jwtAuthService.isValidToken(token)) { + Optional authProvider = authProviders.stream() + .filter(ap -> ap.canHandle(authHeaderValue)) + .findFirst(); + + if(authProvider.isEmpty()) { addAuthenticationError(request, response); return; } + else{ + authProvider.get().handle(authHeaderValue); + } filterChain.doFilter(request, response); - logger.info("Completed Jwt Auth Filter"); - } + logger.info("Completed Auth Filter"); + } - private void addAuthenticationError(HttpServletRequest request , HttpServletResponse response) throws IOException{ + private void addMissingAuthTokenError(HttpServletRequest request , HttpServletResponse response) throws IOException{ var body = new LinkedHashMap<>(); - body.put("type", "https://db2rest/unauthorized"); - body.put("title", "Unauthorized"); + body.put("type", "https://db2rest/jwt-token-not-found"); + body.put("title", "Auth token not provided in header"); body.put("status", HttpServletResponse.SC_UNAUTHORIZED); - body.put("detail", "Invalid JWT Token"); + body.put("detail", "Auth token not provided in header. Please add header " + AUTH_HEADER + " with valid Auth token."); body.put("instance", request.getRequestURI()); - body.put("errorCategory", "Unauthorized"); + body.put("errorCategory", "Invalid-Auth-Token"); body.put("timestamp", Instant.now()); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); @@ -62,15 +74,16 @@ private void addAuthenticationError(HttpServletRequest request , HttpServletResp objectMapper.writeValue(response.getWriter(), body); } - private void addMissingJwtTokenError(HttpServletRequest request , HttpServletResponse response) throws IOException{ + + private void addAuthenticationError(HttpServletRequest request , HttpServletResponse response) throws IOException{ var body = new LinkedHashMap<>(); - body.put("type", "https://db2rest/jwt-token-not-found"); - body.put("title", "JWT token not provided in header"); + body.put("type", "https://db2rest/unauthorized"); + body.put("title", "Unauthorized"); body.put("status", HttpServletResponse.SC_UNAUTHORIZED); - body.put("detail", "JWT token not provided in header. Please add header " + JWT_KEY_HEADER + " with valid JWT token."); + body.put("detail", "No Auth Handler found"); body.put("instance", request.getRequestURI()); - body.put("errorCategory", "Invalid-JWT-Token"); + body.put("errorCategory", "Auth-error"); body.put("timestamp", Instant.now()); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); diff --git a/auth/src/main/java/com/homihq/db2rest/auth/basic/BasicAuthProvider.java b/auth/src/main/java/com/homihq/db2rest/auth/basic/BasicAuthProvider.java new file mode 100644 index 00000000..7c4abb45 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/basic/BasicAuthProvider.java @@ -0,0 +1,39 @@ +package com.homihq.db2rest.auth.basic; + +import com.homihq.db2rest.auth.common.AuthDataProvider; +import com.homihq.db2rest.auth.common.AuthProvider; +import com.homihq.db2rest.auth.common.Subject; +import com.homihq.db2rest.auth.common.User; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import java.nio.charset.StandardCharsets; +import java.util.Base64; + + +@RequiredArgsConstructor +@Slf4j +public class BasicAuthProvider implements AuthProvider { + + private final AuthDataProvider authDataProvider; + @Override + public boolean canHandle(String authHeader) { + return StringUtils.isNotBlank(authHeader) && authHeader.startsWith("Basic "); + } + + @Override + public Subject handle(String authHeader) { + String base64Credentials = authHeader.substring("Basic ".length()); + byte[] decodedCredentials = Base64.getDecoder().decode(base64Credentials); + String credentials = new String(decodedCredentials, StandardCharsets.UTF_8); + + String[] parts = credentials.split(":"); + String username = parts[0]; + String password = parts[1]; + + User user = authDataProvider.validate(username, password); + + return new Subject(username, user.roles(), ""); + } + +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/ApiResource.java b/auth/src/main/java/com/homihq/db2rest/auth/common/ApiResource.java new file mode 100644 index 00000000..5ff24bd5 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/common/ApiResource.java @@ -0,0 +1,6 @@ +package com.homihq.db2rest.auth.common; + +import java.util.List; + +public record ApiResource(String path, String method, List roles) { +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/AuthContext.java b/auth/src/main/java/com/homihq/db2rest/auth/common/AuthContext.java deleted file mode 100644 index 9f10e59a..00000000 --- a/auth/src/main/java/com/homihq/db2rest/auth/common/AuthContext.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.homihq.db2rest.auth.common; - -public abstract class AuthContext { - private static final ThreadLocal currentAuthInfo = new ThreadLocal(); - - public static void setCurrentAuthInfo(AuthInfo authInfo) { - currentAuthInfo.set(authInfo); - } - - public static AuthInfo getCurrentAuthInfo() { - return currentAuthInfo.get(); - } - - public static void clear() { - currentAuthInfo.remove(); - } -} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/AuthDataProvider.java b/auth/src/main/java/com/homihq/db2rest/auth/common/AuthDataProvider.java new file mode 100644 index 00000000..af95e71c --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/common/AuthDataProvider.java @@ -0,0 +1,20 @@ +package com.homihq.db2rest.auth.common; + +import com.homihq.db2rest.auth.exception.AuthException; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; + +public interface AuthDataProvider { + + List getApiResources(); + List getUsers(); + + default User validate(String username, String password) { + return + getUsers().stream() + .filter(u -> StringUtils.equals(u.username(), username) + && StringUtils.equals(u.username(), password)).findFirst().orElseThrow(() -> + new AuthException("Invalid username or password.")); + } +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/AuthInfo.java b/auth/src/main/java/com/homihq/db2rest/auth/common/AuthInfo.java deleted file mode 100644 index 6eedff47..00000000 --- a/auth/src/main/java/com/homihq/db2rest/auth/common/AuthInfo.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.homihq.db2rest.auth.common; - -public record AuthInfo(String keyId,String[] permissions) {} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/AuthProvider.java b/auth/src/main/java/com/homihq/db2rest/auth/common/AuthProvider.java new file mode 100644 index 00000000..fc93ec24 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/common/AuthProvider.java @@ -0,0 +1,8 @@ +package com.homihq.db2rest.auth.common; + +public interface AuthProvider { + + boolean canHandle(String authHeader); + + Subject handle(String authHeader); +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/Subject.java b/auth/src/main/java/com/homihq/db2rest/auth/common/Subject.java new file mode 100644 index 00000000..131dbd43 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/common/Subject.java @@ -0,0 +1,5 @@ +package com.homihq.db2rest.auth.common; + +import java.util.List; + +public record Subject (String principal, List roles, String requestedUri) { } diff --git a/auth/src/main/java/com/homihq/db2rest/auth/common/User.java b/auth/src/main/java/com/homihq/db2rest/auth/common/User.java new file mode 100644 index 00000000..e292bd31 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/common/User.java @@ -0,0 +1,6 @@ +package com.homihq.db2rest.auth.common; + +import java.util.List; + +public record User(String username, String password, List roles) { +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/data/FileAuthDataProvider.java b/auth/src/main/java/com/homihq/db2rest/auth/data/FileAuthDataProvider.java new file mode 100644 index 00000000..51bd4e68 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/data/FileAuthDataProvider.java @@ -0,0 +1,21 @@ +package com.homihq.db2rest.auth.data; + +import com.homihq.db2rest.auth.common.ApiResource; +import com.homihq.db2rest.auth.common.AuthDataProvider; +import com.homihq.db2rest.auth.common.User; + +import java.util.List; + +public class FileAuthDataProvider implements AuthDataProvider { + + + @Override + public List getApiResources() { + return null; + } + + @Override + public List getUsers() { + return null; + } +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/exception/AuthException.java b/auth/src/main/java/com/homihq/db2rest/auth/exception/AuthException.java new file mode 100644 index 00000000..141b361f --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/exception/AuthException.java @@ -0,0 +1,9 @@ +package com.homihq.db2rest.auth.exception; + +import org.springframework.core.NestedRuntimeException; + +public class AuthException extends NestedRuntimeException { + public AuthException(String msg) { + super(msg); + } +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthConfiguration.java b/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthConfiguration.java deleted file mode 100644 index 04f5ee5d..00000000 --- a/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.homihq.db2rest.auth.jwt; - -import com.auth0.jwt.JWT; -import com.auth0.jwt.JWTVerifier; -import com.auth0.jwt.algorithms.Algorithm; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.homihq.db2rest.auth.jwt.service.JwtAuthService; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConditionalOnProperty(prefix = "db2rest.auth", name="type" , havingValue = "jwt") -public class JwtAuthConfiguration { - - @Value("${db2rest.jwt.secret}") - private String jwtSecretKey; - - @Bean - public JWTVerifier jwtVerifier() { - return JWT.require(Algorithm.HMAC512(jwtSecretKey)).build(); - } - - @Bean - public JwtAuthService jwtAuthService(JWTVerifier verifier) { - return new JwtAuthService(verifier); - } - @Bean - public JwtAuthFilter jwtAuthFilter(JWTVerifier verifier, ObjectMapper objectMapper) { - return new JwtAuthFilter(jwtAuthService(verifier), objectMapper); - } -} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthProvider.java b/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthProvider.java new file mode 100644 index 00000000..ecbaac42 --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtAuthProvider.java @@ -0,0 +1,38 @@ +package com.homihq.db2rest.auth.jwt; + +import com.auth0.jwt.JWTVerifier; +import com.auth0.jwt.exceptions.JWTVerificationException; +import com.auth0.jwt.interfaces.DecodedJWT; +import com.homihq.db2rest.auth.common.AuthProvider; +import com.homihq.db2rest.auth.common.Subject; +import com.homihq.db2rest.auth.exception.AuthException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; + +@Slf4j +@RequiredArgsConstructor +public class JwtAuthProvider implements AuthProvider { + + private final JWTVerifier jwtVerifier; + + @Override + public boolean canHandle(String authHeader) { + return StringUtils.isNotBlank(authHeader) && authHeader.startsWith("Bearer "); + } + + @Override + public Subject handle(String authHeader) { + String token = StringUtils.replace(authHeader, "Bearer ", "", 1); + try { + DecodedJWT decodedJWT = jwtVerifier.verify(token); + + return new Subject(decodedJWT.getSubject(), List.of(), ""); + } + catch (JWTVerificationException e) { + throw new AuthException("Error in JWT validation - " + e.getMessage()); + } + } +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtProperties.java b/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtProperties.java new file mode 100644 index 00000000..6bfbe6be --- /dev/null +++ b/auth/src/main/java/com/homihq/db2rest/auth/jwt/JwtProperties.java @@ -0,0 +1,39 @@ +package com.homihq.db2rest.auth.jwt; + +import com.auth0.jwt.algorithms.Algorithm; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.validation.annotation.Validated; + +@Configuration +@ConfigurationProperties(prefix = "db2rest.auth.jwt") +@Validated +@Slf4j +@Getter +@Setter +public class JwtProperties { //Currently support HMAC only + + String algorithm; + String secret; + + String [] issuers; + + public Algorithm getAlgo() { + switch (algorithm) { + case "HMAC256" -> { + return Algorithm.HMAC256(secret); + } + case "HMAC384" -> { + return Algorithm.HMAC384(secret); + } + case "HMAC512" -> { + return Algorithm.HMAC512(secret); + } + default -> throw new RuntimeException(algorithm + " is not supported."); + } + } + +} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/jwt/service/JwtAuthService.java b/auth/src/main/java/com/homihq/db2rest/auth/jwt/service/JwtAuthService.java deleted file mode 100644 index 560bc565..00000000 --- a/auth/src/main/java/com/homihq/db2rest/auth/jwt/service/JwtAuthService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.homihq.db2rest.auth.jwt.service; - -import com.auth0.jwt.JWTVerifier; -import com.auth0.jwt.exceptions.JWTVerificationException; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@RequiredArgsConstructor -@Slf4j -public class JwtAuthService { - - private final JWTVerifier jwtVerifier; - - public boolean isValidToken(String token) { - - try { - jwtVerifier.verify(token); - } catch (final JWTVerificationException verificationException) { - log.warn("token invalid: {}", verificationException.getMessage()); - return false; - } - - return true; - } -} diff --git a/auth/src/main/java/com/homihq/db2rest/auth/unkey/UnKeyAuthConfiguration.java b/auth/src/main/java/com/homihq/db2rest/auth/unkey/UnKeyAuthConfiguration.java index 642ff6a1..2decfde2 100644 --- a/auth/src/main/java/com/homihq/db2rest/auth/unkey/UnKeyAuthConfiguration.java +++ b/auth/src/main/java/com/homihq/db2rest/auth/unkey/UnKeyAuthConfiguration.java @@ -9,7 +9,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -@Configuration +//@Configuration @ConditionalOnProperty(prefix = "db2rest.auth", name="type" , havingValue = "unkey") @Slf4j public class UnKeyAuthConfiguration { diff --git a/auth/src/test/java/com/homihq/db2rest/auth/JwtAuthServiceTest.java b/auth/src/test/java/com/homihq/db2rest/auth/JwtAuthServiceTest.java deleted file mode 100644 index d71fb8fc..00000000 --- a/auth/src/test/java/com/homihq/db2rest/auth/JwtAuthServiceTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.homihq.db2rest.auth; - -import com.auth0.jwt.JWT; -import com.auth0.jwt.algorithms.Algorithm; -import com.homihq.db2rest.auth.jwt.service.JwtAuthService; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Value; - -import java.util.Date; - -@Disabled -public class JwtAuthServiceTest { - - - private JwtAuthService jwtAuthService; - - @Value("${db2rest.jwt.secret}") - private String jwtSecret; - - @Test - @DisplayName("Test jwt token verification") - public void testJwtTokenVerification() { - String token = JWT.create() - .withIssuer("db2rest-test") - .withIssuedAt(new Date()) - .withExpiresAt(new Date(System.currentTimeMillis() + 5000)) - .sign(Algorithm.HMAC512(jwtSecret)); - - assert jwtAuthService.isValidToken(token); - } -} diff --git a/auth/src/test/java/com/homihq/db2rest/auth/UnkeyDevServiceTest.java b/auth/src/test/java/com/homihq/db2rest/auth/UnkeyDevServiceTest.java deleted file mode 100644 index c6cf28e4..00000000 --- a/auth/src/test/java/com/homihq/db2rest/auth/UnkeyDevServiceTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.homihq.db2rest.auth; - - -import com.homihq.db2rest.auth.unkey.service.UnKeyAuthService; -import com.homihq.db2rest.auth.unkey.to.UnKeyVerifyResponse; -import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; - -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; - -@DisabledIfEnvironmentVariable(named = "testUnkeyDevKey", matches = "") -public class UnkeyDevServiceTest { - //TODO - mock - /* - @Autowired - private UnKeyAuthService unKeyAuthService; - - @Test - @DisplayName("Test api key verification") - public void testAPIKeyVerify() { - String apiKey = System.getenv("testUnkeyDevKey"); - UnKeyVerifyResponse response = unKeyAuthService.verifyApiKey(apiKey); - assert response.enabled && response.valid; - } - - */ - -} diff --git a/pg-dialect/pom.xml b/pg-dialect/pom.xml index d2980341..8b192517 100644 --- a/pg-dialect/pom.xml +++ b/pg-dialect/pom.xml @@ -38,7 +38,6 @@ - diff --git a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/DbOperationService.java b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/DbOperationService.java index 5e018431..6c266703 100644 --- a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/DbOperationService.java +++ b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/core/DbOperationService.java @@ -6,6 +6,7 @@ import com.homihq.db2rest.jdbc.config.model.DbTable; import com.homihq.db2rest.core.dto.CreateBulkResponse; import com.homihq.db2rest.core.dto.CreateResponse; +import com.homihq.db2rest.jdbc.dto.BindVariable; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import java.util.List; diff --git a/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/dto/BindVariable.java b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/dto/BindVariable.java new file mode 100644 index 00000000..03644481 --- /dev/null +++ b/rdbms-support/src/main/java/com/homihq/db2rest/jdbc/dto/BindVariable.java @@ -0,0 +1,5 @@ +package com.homihq.db2rest.jdbc.dto; + +public record BindVariable(String type, Object value) { + +}