Skip to content

Commit

Permalink
Update to Latest One-Time Token API Names
Browse files Browse the repository at this point in the history
Issue gh-15887
  • Loading branch information
jzheaux committed Oct 14, 2024
1 parent 57f07b4 commit b558c32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.springframework.security.authentication.ott.reactive.ReactiveOneTimeT
import org.springframework.security.web.server.authentication.ServerAuthenticationConverter
import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler
import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler
import org.springframework.security.web.server.authentication.ott.ServerGeneratedOneTimeTokenHandler
import org.springframework.security.web.server.authentication.ott.ServerOneTimeTokenGenerationSuccessHandler
import org.springframework.security.web.server.context.ServerSecurityContextRepository


Expand All @@ -39,7 +39,7 @@ import org.springframework.security.web.server.context.ServerSecurityContextRepo
* @property showDefaultSubmitPage configures whether the default one-time token submit page should be shown
* @property loginProcessingUrl the URL to process the login request
* @property generateTokenUrl the URL that a One-Time Token generate request will be processed
* @property generatedOneTimeTokenHandler the strategy to be used to handle generated one-time tokens
* @property tokenGenerationSuccessHandler the strategy to be used to handle generated one-time tokens
* @property securityContextRepository the [ServerSecurityContextRepository] used to save the [Authentication]. For the [SecurityContext] to be loaded on subsequent requests the [ReactorContextWebFilter] must be configured to be able to load the value (they are not implicitly linked).
*/
@ServerSecurityMarker
Expand All @@ -49,7 +49,7 @@ class ServerOneTimeTokenLoginDsl {
var authenticationConverter: ServerAuthenticationConverter? = null
var authenticationFailureHandler: ServerAuthenticationFailureHandler? = null
var authenticationSuccessHandler: ServerAuthenticationSuccessHandler? = null
var generatedOneTimeTokenHandler: ServerGeneratedOneTimeTokenHandler? = null
var tokenGenerationSuccessHandler: ServerOneTimeTokenGenerationSuccessHandler? = null
var securityContextRepository: ServerSecurityContextRepository? = null
var defaultSubmitPageUrl: String? = null
var loginProcessingUrl: String? = null
Expand All @@ -59,7 +59,7 @@ class ServerOneTimeTokenLoginDsl {
internal fun get(): (ServerHttpSecurity.OneTimeTokenLoginSpec) -> Unit {
return { oneTimeTokenLogin ->
authenticationManager?.also { oneTimeTokenLogin.authenticationManager(authenticationManager) }
oneTimeTokenService?.also { oneTimeTokenLogin.oneTimeTokenService(oneTimeTokenService) }
oneTimeTokenService?.also { oneTimeTokenLogin.tokenService(oneTimeTokenService) }
authenticationConverter?.also { oneTimeTokenLogin.authenticationConverter(authenticationConverter) }
authenticationFailureHandler?.also {
oneTimeTokenLogin.authenticationFailureHandler(
Expand All @@ -75,10 +75,10 @@ class ServerOneTimeTokenLoginDsl {
defaultSubmitPageUrl?.also { oneTimeTokenLogin.defaultSubmitPageUrl(defaultSubmitPageUrl) }
showDefaultSubmitPage?.also { oneTimeTokenLogin.showDefaultSubmitPage(showDefaultSubmitPage!!) }
loginProcessingUrl?.also { oneTimeTokenLogin.loginProcessingUrl(loginProcessingUrl) }
generateTokenUrl?.also { oneTimeTokenLogin.generateTokenUrl(generateTokenUrl) }
generatedOneTimeTokenHandler?.also {
oneTimeTokenLogin.generatedOneTimeTokenHandler(
generatedOneTimeTokenHandler
generateTokenUrl?.also { oneTimeTokenLogin.tokenGeneratingUrl(generateTokenUrl) }
tokenGenerationSuccessHandler?.also {
oneTimeTokenLogin.tokenGenerationSuccessHandler(
tokenGenerationSuccessHandler
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ package org.springframework.security.config.web.server

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import reactor.core.publisher.Mono

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.context.ApplicationContext
import org.springframework.http.MediaType
import org.springframework.security.authentication.ott.OneTimeToken
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
Expand All @@ -36,13 +34,14 @@ import org.springframework.security.core.userdetails.User
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers
import org.springframework.security.web.server.SecurityWebFilterChain
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler
import org.springframework.security.web.server.authentication.ott.ServerGeneratedOneTimeTokenHandler
import org.springframework.security.web.server.authentication.ott.ServerRedirectGeneratedOneTimeTokenHandler
import org.springframework.security.web.server.authentication.ott.ServerOneTimeTokenGenerationSuccessHandler
import org.springframework.security.web.server.authentication.ott.ServerRedirectOneTimeTokenGenerationSuccessHandler
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.web.reactive.config.EnableWebFlux
import org.springframework.web.reactive.function.BodyInserters
import org.springframework.web.server.ServerWebExchange
import org.springframework.web.util.UriBuilder
import reactor.core.publisher.Mono

/**
* Tests for [ServerOneTimeTokenLoginDsl]
Expand Down Expand Up @@ -95,7 +94,7 @@ class ServerOneTimeTokenLoginDslTests {
.is3xxRedirection()
.expectHeader().valueEquals("Location", "/login/ott")

val token = TestServerGeneratedOneTimeTokenHandler.lastToken?.tokenValue
val token = TestServerOneTimeTokenGenerationSuccessHandler.lastToken?.tokenValue

client.mutateWith(SecurityMockServerConfigurers.csrf())
.post()
Expand Down Expand Up @@ -129,7 +128,7 @@ class ServerOneTimeTokenLoginDslTests {
.is3xxRedirection()
.expectHeader().valueEquals("Location", "/redirected")

val token = TestServerGeneratedOneTimeTokenHandler.lastToken?.tokenValue
val token = TestServerOneTimeTokenGenerationSuccessHandler.lastToken?.tokenValue

client.mutateWith(SecurityMockServerConfigurers.csrf())
.post()
Expand Down Expand Up @@ -160,7 +159,7 @@ class ServerOneTimeTokenLoginDslTests {
authorize(anyExchange, authenticated)
}
oneTimeTokenLogin {
generatedOneTimeTokenHandler = TestServerGeneratedOneTimeTokenHandler()
tokenGenerationSuccessHandler = TestServerOneTimeTokenGenerationSuccessHandler()
}
}
// @formatter:on
Expand All @@ -182,7 +181,7 @@ class ServerOneTimeTokenLoginDslTests {
}
oneTimeTokenLogin {
generateTokenUrl = "/generateurl"
generatedOneTimeTokenHandler = TestServerGeneratedOneTimeTokenHandler("/redirected")
tokenGenerationSuccessHandler = TestServerOneTimeTokenGenerationSuccessHandler("/redirected")
loginProcessingUrl = "/loginprocessingurl"
authenticationSuccessHandler = RedirectServerAuthenticationSuccessHandler("/authenticated")
}
Expand All @@ -199,19 +198,19 @@ class ServerOneTimeTokenLoginDslTests {
MapReactiveUserDetailsService(User("user", "password", listOf()))
}

private class TestServerGeneratedOneTimeTokenHandler: ServerGeneratedOneTimeTokenHandler {
private var delegate: ServerRedirectGeneratedOneTimeTokenHandler? = null
private class TestServerOneTimeTokenGenerationSuccessHandler: ServerOneTimeTokenGenerationSuccessHandler {
private var delegate: ServerRedirectOneTimeTokenGenerationSuccessHandler? = null

companion object {
var lastToken: OneTimeToken? = null
}

constructor() {
this.delegate = ServerRedirectGeneratedOneTimeTokenHandler("/login/ott")
this.delegate = ServerRedirectOneTimeTokenGenerationSuccessHandler("/login/ott")
}

constructor(redirectUrl: String?) {
this.delegate = ServerRedirectGeneratedOneTimeTokenHandler(redirectUrl)
this.delegate = ServerRedirectOneTimeTokenGenerationSuccessHandler(redirectUrl)
}

override fun handle(exchange: ServerWebExchange?, oneTimeToken: OneTimeToken?): Mono<Void> {
Expand Down

0 comments on commit b558c32

Please sign in to comment.