-
Notifications
You must be signed in to change notification settings - Fork 1
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
[🚌 Issue] dev api 로그인 요청 위치에 따라 redirect url 변환 #245
Changes from 21 commits
b99367c
4249f81
854f4a2
23aa5f9
1c7d46f
74b372b
54c8b81
ef9f69d
30b557b
89264c7
5425558
48e2709
a9135a1
63bb7e9
4c110bc
bb151c4
0a00a11
c94c5b5
e97bc4e
583201f
e307c2d
1073e18
39ce4cc
128357d
e27bb5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
package io.raemian.api.goal.controller.request | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class TimelinePageRequest( | ||
val cursor: LocalDateTime?, | ||
val size: Int, | ||
val page: Int = 0, | ||
val size: Int = 20, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.raemian.api.support.response | ||
|
||
data class OffsetPaginationResult<T>( | ||
val total: Long, | ||
val page: Int, | ||
val size: Int, | ||
val contents: List<T>, | ||
) { | ||
companion object { | ||
fun <T> of(page: Int, size: Int, total: Long, contents: List<T>): OffsetPaginationResult<T> { | ||
return OffsetPaginationResult(total, page, size, contents) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.raemian.api.support.security | ||
|
||
import io.raemian.api.auth.model.Token | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class LoginRedirector( | ||
val profilePlaceHolder: ProfileHolder, | ||
val redirectUrlHolder: RedirectUrlHolder, | ||
val loginRequestRefererStorage: LoginRequestRefererStorage, | ||
) { | ||
fun getUrl(state: String, token: Token): String { | ||
if (profilePlaceHolder.isLive()) { | ||
return "${redirectUrlHolder.live}?token=${token.accessToken}&refresh=${token.refreshToken}" | ||
} | ||
|
||
val referer = loginRequestRefererStorage.get(state) | ||
|
||
if (profilePlaceHolder.isDev() && referer.contains("dev-bandiboodi")) { | ||
return "${redirectUrlHolder.dev}?token=${token.accessToken}&refresh=${token.refreshToken}" | ||
} | ||
|
||
return "${redirectUrlHolder.local}?token=${token.accessToken}&refresh=${token.refreshToken}" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.raemian.api.support.security | ||
|
||
import com.github.benmanes.caffeine.cache.Caffeine | ||
import org.springframework.stereotype.Component | ||
import java.util.concurrent.TimeUnit | ||
|
||
@Component | ||
class LoginRequestRefererStorage { | ||
private val timedStorage = Caffeine.newBuilder() | ||
.expireAfterWrite(60L, TimeUnit.SECONDS) | ||
.build<String, String>() | ||
|
||
fun put(state: String, referer: String?) { | ||
if (referer.isNullOrBlank()) { | ||
return | ||
} else { | ||
timedStorage.put(state, referer) | ||
} | ||
} | ||
|
||
fun get(state: String): String { | ||
return timedStorage.getIfPresent(state) ?: "" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.raemian.api.support.security | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ProfileHolder( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @binary-ho 추가 제안 ㅆㄱㄴ |
||
@Value("\${spring.profiles.active:local}") | ||
private val profile: String, | ||
) { | ||
fun isLive(): Boolean { | ||
return ProfileType.fromString(profile) == ProfileType.LIVE | ||
} | ||
|
||
fun isDev(): Boolean { | ||
return ProfileType.fromString(profile) == ProfileType.DEV | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.raemian.api.support.security | ||
|
||
enum class ProfileType( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ManHyuk 추가 제안 ㅆㄱㄴ |
||
value: String, | ||
) { | ||
LIVE("live"), | ||
DEV("dev"), | ||
LOCAL("local"), ; | ||
companion object { | ||
fun fromString(value: String): ProfileType = | ||
when (value) { | ||
"live" -> LIVE | ||
"dev" -> DEV | ||
else -> LOCAL | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.raemian.api.support.security | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
@ConfigurationProperties(prefix = "redirect-url") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @binary-ho 추가 제안 ㅆㄱㄴ |
||
data class RedirectUrlHolder( | ||
val live: String, | ||
val dev: String, | ||
val local: String, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[[ 100% 취향 제안 ]]
저도 자바에 익숙해서 우석님이랑 항상 같은 방식으로 코드를 작성했는데요?
요즘 코틀린 코드들 다른데서 보면서 아래와 같은 코드도 조금 이뻐 보이이기 시작했는데 어떠신가요..
혹은.. 확장함수 활용해서 isNotNullOrBlank() 구현한 다음..
완전 취향이고 지금 얼리 리턴 방식도 너무 좋아요 저도 보통 그렇게 작성해왔던 것 같아요.
어떤지 한번 얘기해보고 싶어서 올려봐요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 얼리 리턴을 위한 조건문은 명시적으로 작성하는 편이 잘 읽힌다고 생각하는 편이였는데요.
진호님이 제시해주신 첫번째 코드 (if문 Expression으로 사용)를 보니 한번 사용해보고 싶다는 생각이 들었습니다 ㅎㅎ
첫번째 방식으로 수정 한번 해보겠습니다!
제안 감사합니다 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@binary-ho
제안 감사합니다 👍
추가 제안 ㅆㄱㄴ