Skip to content

Commit

Permalink
Merge pull request #74 from team-verby/dev
Browse files Browse the repository at this point in the history
chore: ํ—ˆ์šฉ๋˜์ง€ ์•Š์€ ์š”์ฒญ ํ•„ํ„ฐ๋ง
  • Loading branch information
pushedrumex authored Nov 12, 2024
2 parents 9050002 + ce5a5e2 commit b159b36
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/java/com/verby/indp/global/filter/ResourceFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.verby.indp.global.filter;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class ResourceFilter implements Filter {

private static final List<String> ALLOWED_PATHS = Arrays.asList(
"/api/music",
"/api/stores",
"/api/main",
"/api/contacts"
);

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();

boolean isAllowed = ALLOWED_PATHS.stream().anyMatch(requestURI::startsWith);

if (isAllowed) {
chain.doFilter(request, response);
} else {
response.getWriter().write("Access Denied");
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");

((HttpServletResponse) response).setStatus(HttpServletResponse.SC_FORBIDDEN);
}
}
}

0 comments on commit b159b36

Please sign in to comment.