Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#35] 로그인한 유저 인증 기능 추가 #38

Merged
merged 11 commits into from
Oct 18, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.srltas.runtogether.adapter.in.web.filter;

import static com.srltas.runtogether.common.AuthConstants.*;
import static com.srltas.runtogether.common.SessionAttribute.*;

import java.io.IOException;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;

String authorizationHeader = request.getHeader("Authorization");
String authorizationHeader = request.getHeader(AUTHORIZATION);
String token = extractToken(authorizationHeader);

if (token != null) {
Srltas marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -43,8 +44,8 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
}

private String extractToken(String authorizationHeader) {
if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
return authorizationHeader.substring(7);
if (authorizationHeader != null && authorizationHeader.startsWith(BEARER_TOKEN_PREFIX)) {
return authorizationHeader.substring(BEARER_TOKEN_LENGTH);
}
return null;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/srltas/runtogether/common/AuthConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.srltas.runtogether.common;
Srltas marked this conversation as resolved.
Show resolved Hide resolved

import static lombok.AccessLevel.PRIVATE;

import lombok.NoArgsConstructor;

@NoArgsConstructor(access = PRIVATE)
public final class AuthConstants {
public static final String AUTHORIZATION = "Authorization";
public static final String BEARER_TOKEN_PREFIX = "Bearer ";
public static final int BEARER_TOKEN_LENGTH = 7;
}