-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding custom filter for Request Header validation before the request…
… is pre-processed by the controller
- Loading branch information
1 parent
cc83eab
commit 326c7e2
Showing
5 changed files
with
104 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/hyland/webhook/filter/HeaderValidatorFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.hyland.webhook.filter; | ||
|
||
import com.hyland.webhook.constants.WebHookConstants; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
@Log4j2 | ||
public class HeaderValidatorFilter extends OncePerRequestFilter { | ||
|
||
@Value("${zoom.verification.token}") | ||
private String verificationToken; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, | ||
FilterChain filterChain) throws ServletException, IOException { | ||
|
||
String path = request.getRequestURI(); | ||
log.info("#### path {} ##### ", path); | ||
if ("/api/webhook/fetch".equals(path)) { | ||
filterChain.doFilter(request, response); | ||
return; | ||
} | ||
String authToken = request.getHeader(WebHookConstants.AUTHORIZATION); | ||
log.info("#### validateToken {} ##### ", authToken); | ||
|
||
if (null != authToken && !authToken.equals(verificationToken)) { | ||
response.sendError(HttpStatus.FORBIDDEN.value(), "Invalid Verification Token"); | ||
log.debug("Invalid Verification Token"); | ||
return; | ||
} | ||
|
||
filterChain.doFilter(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN" monitorInterval="30"> | ||
<Properties> | ||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %C{1.} [%t] %m%n</Property> | ||
<property name="name" value="Zoom-Twistage-integration"/> | ||
<property name="log.name" value="${name}.log"/> | ||
<property name="log.base" value="/var/log/${name}"/> | ||
</Properties> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT" follow="true"> | ||
<PatternLayout pattern="${LOG_PATTERN}" /> | ||
</Console> | ||
|
||
<RollingFile name="appLog" | ||
fileName="${log.base}/${name}_application.log" | ||
filePattern="${log.base}/${name}-%d{yyyy-MM-dd}-%i.log"> | ||
<PatternLayout pattern="${LOG_PATTERN}" /> | ||
<Policies> | ||
<SizeBasedTriggeringPolicy size="19500KB" /> | ||
<maxFileSize>50MB</maxFileSize> | ||
<maxHistory>30</maxHistory> | ||
<totalSizeCap>3GB</totalSizeCap> | ||
</Policies> | ||
<encoder> | ||
<charset>UTF-8</charset> | ||
<pattern>%date [%thread] [%X{X-B3-TraceId:-}.%X{X-B3-ParentSpanId:-}] %-5p %class{0}:%L %M - %m%n</pattern> | ||
</encoder> | ||
<DefaultRolloverStrategy max="1" /> | ||
</RollingFile> | ||
|
||
</Appenders> | ||
<root level="INFO"> | ||
<appender-ref ref="FILE"/> | ||
<appender-ref ref="ERROR"/> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
<Loggers> | ||
|
||
<Logger name="com.hyland.webhook" additivity="false"> | ||
<AppenderRef ref="appLog" /> | ||
<AppenderRef ref="Console" /> | ||
</Logger> | ||
|
||
<Root level="debug"> | ||
<AppenderRef ref="Console" /> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
This file was deleted.
Oops, something went wrong.