diff options
author | Vitaly Takmazov | 2023-01-10 16:54:33 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-10 16:54:33 +0300 |
commit | e4941d80aedecb2c4c641a916acbb077ea91fc4b (patch) | |
tree | 3936d42884098cfb3fc258bed5a4e89a524bb7b9 | |
parent | bfac316630eaf4dde3a8e80fce7426f5b130ae6d (diff) |
Start using HttpHeaders class instead of string constants
4 files changed, 9 insertions, 8 deletions
diff --git a/src/main/java/com/juick/service/ActivityPubService.java b/src/main/java/com/juick/service/ActivityPubService.java index 295910bd..9b93cab2 100644 --- a/src/main/java/com/juick/service/ActivityPubService.java +++ b/src/main/java/com/juick/service/ActivityPubService.java @@ -139,8 +139,8 @@ public class ActivityPubService extends BaseJdbcService implements SocialService String signatureString = signatureService.addSignature(from, host, "get", contextUri.getPath(), requestDate, ""); HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Date", requestDate); - requestHeaders.add("Host", host); + requestHeaders.add(HttpHeaders.DATE, requestDate); + requestHeaders.add(HttpHeaders.HOST, host); requestHeaders.add("Signature", signatureString); requestHeaders.setAccept(Collections.singletonList(MediaType.valueOf(Context.ACTIVITY_MEDIA_TYPE))); HttpEntity<Void> activityRequest = new HttpEntity<>(requestHeaders); @@ -173,9 +173,9 @@ public class ActivityPubService extends BaseJdbcService implements SocialService digestHeader); HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Content-Type", Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE); - requestHeaders.add("Date", requestDate); - requestHeaders.add("Host", host); + requestHeaders.add(HttpHeaders.CONTENT_TYPE, Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE); + requestHeaders.add(HttpHeaders.DATE, requestDate); + requestHeaders.add(HttpHeaders.HOST, host); requestHeaders.add("Digest", digestHeader); requestHeaders.add("Signature", signatureString); HttpEntity<String> request = new HttpEntity<>(payload, requestHeaders); diff --git a/src/main/java/com/juick/service/security/BearerTokenAuthenticationFilter.java b/src/main/java/com/juick/service/security/BearerTokenAuthenticationFilter.java index f4e73b12..e5fdd738 100644 --- a/src/main/java/com/juick/service/security/BearerTokenAuthenticationFilter.java +++ b/src/main/java/com/juick/service/security/BearerTokenAuthenticationFilter.java @@ -28,6 +28,7 @@ import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpHeaders; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -58,7 +59,7 @@ public class BearerTokenAuthenticationFilter extends BaseAuthenticationFilter { var headers = Collections.list(request.getHeaderNames()) .stream() .collect(Collectors.toMap(String::toLowerCase, request::getHeader)); - var authorizationHeaderValue = headers.get("authorization"); + var authorizationHeaderValue = headers.get(HttpHeaders.AUTHORIZATION.toLowerCase()); if (StringUtils.isNotEmpty(authorizationHeaderValue) && authorizationHeaderValue.startsWith("Bearer")) { String token = authorizationHeaderValue.substring(7); try { diff --git a/src/main/java/com/juick/service/security/HTTPSignatureAuthenticationFilter.java b/src/main/java/com/juick/service/security/HTTPSignatureAuthenticationFilter.java index a851ef36..55c87383 100644 --- a/src/main/java/com/juick/service/security/HTTPSignatureAuthenticationFilter.java +++ b/src/main/java/com/juick/service/security/HTTPSignatureAuthenticationFilter.java @@ -25,7 +25,6 @@ import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.apache.commons.lang3.StringUtils; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; diff --git a/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java b/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java index 06f5edf4..57a770fe 100644 --- a/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java +++ b/src/main/java/com/juick/service/security/HashParamAuthenticationFilter.java @@ -26,6 +26,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpHeaders; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.security.authentication.RememberMeAuthenticationToken; @@ -91,7 +92,7 @@ public class HashParamAuthenticationFilter extends BaseAuthenticationFilter { } private String hashFromAuthorizationHeader(HttpServletRequest request) { - String authorizationHeader = request.getHeader("Authorization"); + String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION); if (StringUtils.isNotEmpty(authorizationHeader)) { String[] parts = authorizationHeader.split(" "); if ((parts.length == 2) && parts[0].equals("Juick")) { |