|
@@ -0,0 +1,30 @@
|
|
|
+package com.wechi.adweb.bridge.auth;
|
|
|
+
|
|
|
+import com.wechi.adweb.bridge.exception.UnauthorizedException;
|
|
|
+
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wfansh
|
|
|
+ */
|
|
|
+public class AuthInterceptor implements HandlerInterceptor {
|
|
|
+
|
|
|
+ // The token is static and weak to reduce computational overhead.
|
|
|
+ private static final String STATIC_BEARER_TOKEN = "Bearer lgoXX9APqgPLGMPECiNoxaPx";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean preHandle(
|
|
|
+ HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
|
+ throws Exception {
|
|
|
+ String authToken = request.getHeader(HttpHeaders.AUTHORIZATION);
|
|
|
+ if (!STATIC_BEARER_TOKEN.equals(authToken)) {
|
|
|
+ throw new UnauthorizedException("Invalid auth token : " + authToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|