-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
425 additions
and
219 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
45 changes: 45 additions & 0 deletions
45
...booking/src/main/java/com/pgms/apibooking/common/interceptor/BookingTokenInterceptor.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,45 @@ | ||
package com.pgms.apibooking.common.interceptor; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import com.pgms.apibooking.common.exception.BookingException; | ||
import com.pgms.apibooking.common.jwt.BookingJwtPayload; | ||
import com.pgms.apibooking.common.jwt.BookingJwtProvider; | ||
import com.pgms.coredomain.domain.common.BookingErrorCode; | ||
|
||
import io.jsonwebtoken.JwtException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BookingTokenInterceptor implements HandlerInterceptor { | ||
|
||
private final BookingJwtProvider bookingJwtProvider; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws | ||
Exception { | ||
String token = parseToken(request); | ||
try { | ||
BookingJwtPayload authentication = bookingJwtProvider.validateAndParsePayload(token); | ||
request.setAttribute("tokenSessionId", authentication.sessionId()); | ||
} catch (JwtException | BookingException e) { | ||
log.warn(e.getMessage(), e); | ||
throw new BookingException(BookingErrorCode.INVALID_BOOKING_TOKEN); | ||
} | ||
return true; | ||
} | ||
|
||
private String parseToken(HttpServletRequest request) { | ||
String headerAuth = request.getHeader("Booking-Authorization"); | ||
if (headerAuth != null && headerAuth.startsWith("Bearer ")) { | ||
return headerAuth.substring(7); | ||
} | ||
throw new BookingException(BookingErrorCode.BOOKING_TOKEN_NOT_EXIST); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...curity/jwt/booking/BookingJwtPayload.java → ...booking/common/jwt/BookingJwtPayload.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
2 changes: 1 addition & 1 deletion
2
...urity/jwt/booking/BookingJwtProvider.java → ...ooking/common/jwt/BookingJwtProvider.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
6 changes: 3 additions & 3 deletions
6
...ity/security/config/BookingJwtConfig.java → ...s/apibooking/config/BookingJwtConfig.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
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
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
Oops, something went wrong.