-
Notifications
You must be signed in to change notification settings - Fork 0
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 #55 from project-lyrics/SCRUM-189
device_id 검사 로직 추가
- Loading branch information
Showing
13 changed files
with
250 additions
and
97 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
36 changes: 36 additions & 0 deletions
36
.../com/projectlyrics/server/domain/auth/authentication/interceptor/DeviceIdInterceptor.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,36 @@ | ||
package com.projectlyrics.server.domain.auth.authentication.interceptor; | ||
|
||
import com.projectlyrics.server.domain.auth.exception.NotRegisteredDeviceException; | ||
import com.projectlyrics.server.domain.auth.repository.AuthRepository; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Profile({"dev", "local"}) | ||
@Component | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class DeviceIdInterceptor implements HandlerInterceptor { | ||
|
||
private final AuthRepository authRepository; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
if (included(request)) { | ||
authRepository.findByDeviceId(request.getHeader("Device-Id")) | ||
.orElseThrow(NotRegisteredDeviceException::new); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean included(HttpServletRequest request) { | ||
String requestURI = request.getRequestURI(); | ||
return !requestURI.matches("/api/v1/auth/sign-in") && | ||
!requestURI.matches("/api/v1/auth/sign-up"); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
...ain/java/com/projectlyrics/server/domain/auth/exception/NotRegisteredDeviceException.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,11 @@ | ||
package com.projectlyrics.server.domain.auth.exception; | ||
|
||
import com.projectlyrics.server.domain.common.message.ErrorCode; | ||
import com.projectlyrics.server.global.exception.FeelinException; | ||
|
||
public class NotRegisteredDeviceException extends FeelinException { | ||
|
||
public NotRegisteredDeviceException() { | ||
super(ErrorCode.NOT_REGISTERED_DEVICE); | ||
} | ||
} |
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.