spring-projects / spring-projects/spring-security
Kotlin Extension Functions for ReactiveUserDetailsService
Open
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()
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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