-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #654 from tukcomCD2024/fix/filter-B-#653
fix: 앱 요청 식별 필터 추가
- Loading branch information
Showing
10 changed files
with
138 additions
and
48 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
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
56 changes: 56 additions & 0 deletions
56
...java/site/timecapsulearchive/core/global/security/filter/DefaultAuthenticationFilter.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,56 @@ | ||
package site.timecapsulearchive.core.global.security.filter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
import site.timecapsulearchive.core.global.error.ErrorCode; | ||
import site.timecapsulearchive.core.global.error.ErrorResponse; | ||
import site.timecapsulearchive.core.global.security.property.DefaultKeyProperties; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class DefaultAuthenticationFilter extends OncePerRequestFilter { | ||
|
||
private final DefaultKeyProperties defaultKeyProperties; | ||
|
||
@Override | ||
@Order(1) | ||
protected void doFilterInternal( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
FilterChain filterChain | ||
) throws ServletException, IOException { | ||
String requestKey = request.getHeader("Default-Key"); | ||
|
||
if (requestKey == null || !requestKey.equals(defaultKeyProperties.defaultKey())) { | ||
log.warn("Invalid default key provided: {}", requestKey); | ||
|
||
final ErrorResponse errorResponse = ErrorResponse.fromErrorCode( | ||
ErrorCode.REQUEST_DEFAULT_KEY_ERROR | ||
); | ||
|
||
response.setStatus(ErrorCode.REQUEST_DEFAULT_KEY_ERROR.getStatus()); | ||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); | ||
|
||
response.getWriter().write( | ||
new ObjectMapper().writeValueAsString( | ||
errorResponse | ||
) | ||
); | ||
|
||
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
10 changes: 10 additions & 0 deletions
10
...main/java/site/timecapsulearchive/core/global/security/property/DefaultKeyProperties.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,10 @@ | ||
package site.timecapsulearchive.core.global.security.property; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "app") | ||
public record DefaultKeyProperties( | ||
String defaultKey | ||
) { | ||
|
||
} |
Submodule config
updated
from 10bd3b to 92430a
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 |
---|---|---|
@@ -1,34 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<!-- 콘솔 출력 설정 --> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<Pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n | ||
</Pattern> | ||
<Pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n</Pattern> | ||
</layout> | ||
</appender> | ||
<appender name="INFO_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>./logs/info.log</file> | ||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
<level>INFO</level> | ||
</filter> | ||
<encoder> | ||
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - %msg%n | ||
</pattern> | ||
</encoder> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<fileNamePattern>./logs/info.%d{yyyy-MM-dd}.%i.log.gz | ||
</fileNamePattern> | ||
<timeBasedFileNamingAndTriggeringPolicy | ||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> | ||
<maxFileSize>100MB</maxFileSize> | ||
</timeBasedFileNamingAndTriggeringPolicy> | ||
<maxHistory>180</maxHistory> | ||
</rollingPolicy> | ||
</appender> | ||
<root level="INFO"> | ||
<logger name="org.hibernate" level="error" additivity="false"> | ||
<appender-ref ref="INFO_LOG"/> | ||
</logger> | ||
<appender-ref ref="INFO_LOG"/> | ||
</root> | ||
</configuration> | ||
|
||
<!-- local 프로파일일 때 콘솔에만 로그 출력 --> | ||
<springProfile name="local"> | ||
<root level="INFO"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</springProfile> | ||
|
||
<!-- local 프로파일이 아닐 때 로그를 파일로 출력 --> | ||
<springProfile name="!local"> | ||
<appender name="INFO_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>./logs/info.log</file> | ||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> | ||
<level>INFO</level> | ||
</filter> | ||
<encoder> | ||
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - %msg%n</pattern> | ||
</encoder> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<fileNamePattern>./logs/info.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> | ||
<timeBasedFileNamingAndTriggeringPolicy | ||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> | ||
<maxFileSize>100MB</maxFileSize> | ||
</timeBasedFileNamingAndTriggeringPolicy> | ||
<maxHistory>180</maxHistory> | ||
</rollingPolicy> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="INFO_LOG" /> | ||
</root> | ||
</springProfile> | ||
</configuration> |
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
Submodule config
updated
from 9340cf to 9c68d3