Skip to content

Commit

Permalink
[hotfix] fix: request에 setAttribute로 슬랙 정보 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
elive7 committed Dec 17, 2024
1 parent edf8389 commit 71e372b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/org/recordy/server/slack/domain/Slack.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public class Slack {
ApprovalStatus approvalStatus;

public Slack(HttpServletRequest request) {
JSONObject json = getJsonFrom(request);
String payload = (String) request.getAttribute("slackPayload");
if (payload == null) {
throw new SlackException(ErrorMessage.SLACK_INTERACTION_FAILED);
}

JSONObject json = new JSONObject(payload);

JSONObject action = json.getJSONArray("actions").getJSONObject(0);
JSONObject value = new JSONObject(action.getString("value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SlackInterceptor implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// ContentCachingRequestWrapper로 감싸기
// SecurityContextHolderAwareRequestWrapper가 아닌 경우에만 ContentCachingRequestWrapper로 감쌈
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);

String method = request.getMethod();
Expand All @@ -35,6 +35,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
String payload = getRequestBody(requestWrapper);

System.out.println("payload = " + payload);
request.setAttribute("slackPayload", payload);

if (!method.equalsIgnoreCase("POST") || !isValidRequest(payload, signature, timestamp)) {
throw new SlackException(ErrorMessage.SLACK_INVALID_REQUEST);
Expand Down Expand Up @@ -82,3 +83,4 @@ private boolean isValidRequest(String payload, String signature, String timestam
}
}


0 comments on commit 71e372b

Please sign in to comment.