Skip to content

Commit 37a25f6

Browse files
committed
fix/qg-253: WIP: GoogleAccount.refreshToken переведён на CharArray
Чтобы он не светился в логах через toString
1 parent b4b2740 commit 37a25f6

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

app/src/main/kotlin/pro/qyoga/app/therapist/oauth2/GoogleCallbackController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GoogleOAuthController(
4747
val picture = response["picture"] as? String?
4848

4949
googleCalendarsService.addGoogleAccount(
50-
GoogleAccount(therapistId, email, authorizedClient.refreshToken!!.tokenValue)
50+
GoogleAccount(therapistId, email, authorizedClient.refreshToken!!.tokenValue.toCharArray())
5151
)
5252

5353
// Греем кэш, чтобы улучшить UX пользователя при возврате на страницу расписания

app/src/main/kotlin/pro/qyoga/core/calendar/google/GoogleAccount.kt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,37 @@ typealias GoogleAccountRef = AggregateReference<GoogleAccount, UUID>
1515
data class GoogleAccount(
1616
val ownerRef: TherapistRef,
1717
val email: String,
18-
val refreshToken: String,
18+
val refreshToken: CharArray,
1919

2020
@Id override val id: UUID = UUIDv7.randomUUID()
21-
) : Identifiable<UUID>
21+
) : Identifiable<UUID> {
22+
23+
constructor(
24+
ownerRef: TherapistRef,
25+
email: String,
26+
refreshToken: String
27+
) : this(ownerRef, email, refreshToken.toCharArray())
28+
29+
override fun equals(other: Any?): Boolean {
30+
if (this === other) return true
31+
if (javaClass != other?.javaClass) return false
32+
33+
other as GoogleAccount
34+
35+
if (ownerRef != other.ownerRef) return false
36+
if (email != other.email) return false
37+
if (!refreshToken.contentEquals(other.refreshToken)) return false
38+
if (id != other.id) return false
39+
40+
return true
41+
}
42+
43+
override fun hashCode(): Int {
44+
var result = ownerRef.hashCode()
45+
result = 31 * result + email.hashCode()
46+
result = 31 * result + refreshToken.contentHashCode()
47+
result = 31 * result + id.hashCode()
48+
return result
49+
}
50+
51+
}

app/src/main/kotlin/pro/qyoga/core/calendar/google/GoogleCalendarsClient.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.google.api.services.calendar.Calendar
55
import com.google.api.services.calendar.model.Event
66
import com.google.auth.http.HttpCredentialsAdapter
77
import com.google.auth.oauth2.UserCredentials
8+
import org.slf4j.LoggerFactory
89
import org.springframework.beans.factory.annotation.Value
910
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties
1011
import org.springframework.cache.annotation.Cacheable
@@ -25,6 +26,8 @@ class GoogleCalendarsClient(
2526
@Value("\${trainer-advisor.integrations.google-calendar.root-url}") private val googleCalendarRootUri: URI
2627
) {
2728

29+
private val log = LoggerFactory.getLogger(javaClass)
30+
2831
private val servicesCache = mutableMapOf<GoogleAccount, Calendar>()
2932
.withDefault { createCalendarService(it) }
3033

@@ -37,6 +40,8 @@ class GoogleCalendarsClient(
3740
calendarSettings: GoogleCalendarSettings,
3841
interval: Interval<ZonedDateTime>
3942
): List<GoogleCalendarItem<ZonedDateTime>> {
43+
log.info("Fetching events in {} for calendar {} using {}", interval, calendarSettings.calendarId, account)
44+
4045
val service = servicesCache.getValue(account)
4146
val events =
4247
service.events().list(calendarSettings.calendarId)
@@ -77,6 +82,7 @@ class GoogleCalendarsClient(
7782
therapist: TherapistRef,
7883
account: GoogleAccount
7984
): List<GoogleCalendar> {
85+
log.info("Fetching calendars for therapist {} using {}", therapist, account)
8086
val service = servicesCache.getValue(account)
8187

8288
return service.CalendarList().list()
@@ -89,7 +95,7 @@ class GoogleCalendarsClient(
8995
val credentials = UserCredentials.newBuilder()
9096
.setClientId(googleOAuthProps.registration["google"]!!.clientId)
9197
.setClientSecret(googleOAuthProps.registration["google"]!!.clientSecret)
92-
.setRefreshToken(account.refreshToken)
98+
.setRefreshToken(String(account.refreshToken))
9399
.setTokenServerUri(tokenUri)
94100
.build()
95101

0 commit comments

Comments
 (0)