spring-projects / spring-projects/spring-security

Kotlin Extension Functions for ReactiveUserDetailsService

Open
#8,510 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Spring (WebFlux) has e.g. this extension function:

suspend fun ServerResponse.BodyBuilder.bodyValueAndAwait(body: Any): ServerResponse =
        bodyValue(body).awaitSingle()

See https://github.com/spring-projects/spring-framework/blob/master/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensions.kt#L62

According to the ...AndAwait naming convention I propose these Kotlin extension functions for ReactiveUserDetailsService:

suspend fun ReactiveUserDetailsService.findByUsernameAndAwait(username: String): UserDetails? =
    findByUsername(username).awaitFirstOrNull()

suspend fun ReactiveUserDetailsService.getAuthoritiesAndAwait(username: String): Collection<GrantedAuthority> {
    val userDetails = findByUsernameAndAwait(username) ?: return emptyList()
    return userDetails.authorities
}

suspend fun ReactiveUserDetailsService.getRolesAndAwait(username: String): Collection<String?> =
    getAuthoritiesAndAwait(username).map { grantedAuthority -> grantedAuthority.authority }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ReactiveUserDetailsService and compare the proposed functions with Spring WebFlux's referenced ServerResponseExtensions.kt example. Determine where Kotlin extensions for this service belong and verify that the proposed await-based lookups return the expected user details, authorities, and roles.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, spring
Domain
authentication
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.