You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2023/12/04 16:27:14 UTC

(streampipes) branch 2269-support-basic-auth-for-prometheus-monitoring-endpoint updated: Use constants for auth

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch 2269-support-basic-auth-for-prometheus-monitoring-endpoint
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/2269-support-basic-auth-for-prometheus-monitoring-endpoint by this push:
     new 77d996e39 Use constants for auth
77d996e39 is described below

commit 77d996e39359ab0d17b925d827dd1ddf4212acba
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Mon Dec 4 17:26:49 2023 +0100

    Use constants for auth
---
 .../org/apache/streampipes/commons/constants/HttpConstants.java    | 1 +
 .../streampipes/service/core/filter/TokenAuthenticationFilter.java | 7 ++++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/HttpConstants.java b/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/HttpConstants.java
index 63dece4bb..9866f10e8 100644
--- a/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/HttpConstants.java
+++ b/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/HttpConstants.java
@@ -26,5 +26,6 @@ public class HttpConstants {
   public static final String APPLICATION_JSON_TYPE = "application/json";
   public static final String X_API_USER = "X-API-USER";
   public static final String X_API_KEY = "X-API-KEY";
+  public static final String BASIC = "Basic ";
 
 }
diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/filter/TokenAuthenticationFilter.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/filter/TokenAuthenticationFilter.java
index 47f9dd018..85c73fb47 100644
--- a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/filter/TokenAuthenticationFilter.java
+++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/filter/TokenAuthenticationFilter.java
@@ -35,6 +35,7 @@ import org.apache.streampipes.user.management.util.TokenUtil;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpHeaders;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
@@ -89,10 +90,10 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
           }
         }
       } else {
-        var authorizationHeader = request.getHeader("Authorization");
-        if (authorizationHeader != null && authorizationHeader.startsWith("Basic ")) {
+        var authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
+        if (authorizationHeader != null && authorizationHeader.startsWith(HttpConstants.BASIC)) {
           if (supportedBasicAuthPaths.contains(request.getServletPath())) {
-            String base64Credentials = authorizationHeader.substring("Basic ".length()).trim();
+            String base64Credentials = authorizationHeader.substring(HttpConstants.BASIC.length()).trim();
             String credentials = new String(Base64.getDecoder().decode(base64Credentials));
 
             String[] splitCredentials = credentials.split(":");