Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamstar-enterprises authored Aug 18, 2024
1 parent d3bea07 commit efd837b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ internal class RedisServerOAuth2AuthorizedClientRepository(
clientRegistrationId: String,
principal: Authentication,
exchange: ServerWebExchange
): Mono<T> {
): Mono<T?> {

return constructRedisKey(exchange).flatMap { redisKey ->
return constructRedisKey(clientRegistrationId, principal.name).flatMap { redisKey ->
println("LOADING AUTHORIZED CLIENT - REPOSITORY")
println("Redis Key: $redisKey")

redisTemplate.opsForHash<String, Any>().entries(redisKey)
.doOnNext { entries ->
println("Redis Entries: $entries")
//
}
.collectMap({ it.key as String }, { it.value })
.doOnSuccess { map ->
println("Loaded Map from Redis: $map")
println("Loaded Map from Redis")
}
.mapNotNull { map ->
if (map.isEmpty()) {
Expand Down Expand Up @@ -73,7 +73,10 @@ internal class RedisServerOAuth2AuthorizedClientRepository(
principal: Authentication,
exchange: ServerWebExchange
): Mono<Void> {
return constructRedisKey(exchange).flatMap { redisKey ->

val clientRegistrationId = authorizedClient.clientRegistration.registrationId

return constructRedisKey(clientRegistrationId, principal.name).flatMap { redisKey ->
println("SAVING AUTHORIZED CLIENT - REPOSITORY")
println("Redis Key: $redisKey")

Expand All @@ -83,11 +86,6 @@ internal class RedisServerOAuth2AuthorizedClientRepository(
object : TypeReference<Map<String, Any?>>() {}
)

println("Authorized Client: $authorizedClient")

// log the original fields map
println("Original Fields Map: $fieldsMap")

// remove the clientSecret from the fieldsMap if present
@Suppress("UNCHECKED_CAST")
(fieldsMap["clientRegistration"] as? MutableMap<String, Any?>)?.apply {
Expand All @@ -99,14 +97,14 @@ internal class RedisServerOAuth2AuthorizedClientRepository(
}
}

// log the modified fields map
println("Modified Fields Map: $fieldsMap")

hashOperations.putAll(redisKey, fieldsMap).doOnSuccess {
println("Successfully saved authorized client to Redis")
}.doOnError { e ->
println("Error saving authorized client to Redis: ${e.message}")
}.then()
hashOperations.putAll(redisKey, fieldsMap)
.doOnSuccess {
println("Successfully saved authorized client to Redis")
}
.doOnError { e ->
println("Error saving authorized client to Redis: ${e.message}")
}
.then()
}
}

Expand All @@ -115,25 +113,25 @@ internal class RedisServerOAuth2AuthorizedClientRepository(
principal: Authentication,
exchange: ServerWebExchange
): Mono<Void> {
return constructRedisKey(exchange).flatMap { redisKey ->

return constructRedisKey(clientRegistrationId, principal.name).flatMap { redisKey ->
println("REMOVING AUTHORIZED CLIENT - REPOSITORY")
println("Redis Key: $redisKey")

redisTemplate.opsForHash<String, Any>().delete(redisKey)
.doOnSuccess {
println("Successfully removed authorized client from Redis")
}
.doOnError { e ->
println("Error removing authorized client from Redis: ${e.message}")
}
}.then()
redisTemplate.opsForHash<String, Any>().delete(redisKey)
.doOnSuccess {
println("Successfully removed authorized client from Redis")
}
.doOnError { e ->
println("Error removing authorized client from Redis: ${e.message}")
}
.then()
}
}

// Helper method to construct the Redis key using a unique identifier from the exchange
private fun constructRedisKey(exchange: ServerWebExchange): Mono<String> {
return exchange.session
.map { it.id }
.map { "$redisKeyPrefix:$it" }
private fun constructRedisKey(clientRegistrationId: String, principalName: String): Mono<String> {
return Mono.just("$redisKeyPrefix:$clientRegistrationId:$principalName")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ internal class RedisReactiveOAuth2AuthorizedClientService(

redisTemplate.opsForHash<String, Any>().entries(redisKey)
.doOnNext { entries ->
println("Redis Entries: $entries")
//
}
.collectMap({ it.key as String }, { it.value })
.doOnSuccess { map ->
println("Loaded Map from Redis: $map")
println("Loaded Map from Redis")
}
.mapNotNull { map ->
if (map.isEmpty()) {
Expand Down Expand Up @@ -81,11 +81,6 @@ internal class RedisReactiveOAuth2AuthorizedClientService(
object : TypeReference<Map<String, Any?>>() {}
)

println("Authorized Client: $authorizedClient")

// log the original fields map
println("Original Fields Map: $fieldsMap")

// remove the clientSecret from the fieldsMap if present
@Suppress("UNCHECKED_CAST")
(fieldsMap["clientRegistration"] as? MutableMap<String, Any?>)?.apply {
Expand All @@ -97,9 +92,6 @@ internal class RedisReactiveOAuth2AuthorizedClientService(
}
}

// log the modified fields map
println("Modified Fields Map: $fieldsMap")

redisTemplate.opsForHash<String, Any>().putAll(redisKey, fieldsMap)
.doOnSuccess {
println("Successfully saved authorized client to Redis")
Expand Down

0 comments on commit efd837b

Please sign in to comment.