-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add One-Time Token Login support to Kotlin DSL
Closes gh-15698
- Loading branch information
Max Batischev
authored and
Max Batischev
committed
Sep 4, 2024
1 parent
00e4a8f
commit 4485118
Showing
4 changed files
with
498 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...rc/main/kotlin/org/springframework/security/config/annotation/web/OneTimeTokenLoginDsl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2002-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.security.config.annotation.web | ||
|
||
import org.springframework.security.authentication.AuthenticationProvider | ||
import org.springframework.security.authentication.ott.OneTimeTokenService | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.config.annotation.web.configurers.ott.OneTimeTokenLoginConfigurer | ||
import org.springframework.security.web.authentication.AuthenticationConverter | ||
import org.springframework.security.web.authentication.AuthenticationFailureHandler | ||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler | ||
import org.springframework.security.web.authentication.ott.GeneratedOneTimeTokenHandler | ||
|
||
/** | ||
* A Kotlin DSL to configure [HttpSecurity] OAuth 2.0 login using idiomatic Kotlin code. | ||
* | ||
* @author Max Batischev | ||
* @since 6.4 | ||
* @property oneTimeTokenService configures the [OneTimeTokenService] used to generate and consume | ||
* @property authenticationConverter Use this [AuthenticationConverter] when converting incoming requests to an authentication | ||
* @property authenticationFailureHandler the [AuthenticationFailureHandler] to use when authentication | ||
* @property authenticationSuccessHandler the [AuthenticationSuccessHandler] to be used | ||
* @property defaultSubmitPageUrl sets the URL that the default submit page will be generated | ||
* @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 authenticationProvider the [AuthenticationProvider] to use when authenticating the user | ||
*/ | ||
@SecurityMarker | ||
class OneTimeTokenLoginDsl { | ||
var oneTimeTokenService: OneTimeTokenService? = null | ||
var authenticationConverter: AuthenticationConverter? = null | ||
var authenticationFailureHandler: AuthenticationFailureHandler? = null | ||
var authenticationSuccessHandler: AuthenticationSuccessHandler? = null | ||
var defaultSubmitPageUrl: String? = null | ||
var loginProcessingUrl: String? = null | ||
var generateTokenUrl: String? = null | ||
var showDefaultSubmitPage: Boolean? = true | ||
var generatedOneTimeTokenHandler: GeneratedOneTimeTokenHandler? = null | ||
var authenticationProvider: AuthenticationProvider? = null | ||
|
||
internal fun get(): (OneTimeTokenLoginConfigurer<HttpSecurity>) -> Unit { | ||
return { oneTimeTokenLoginConfigurer -> | ||
oneTimeTokenService?.also { oneTimeTokenLoginConfigurer.oneTimeTokenService(oneTimeTokenService) } | ||
authenticationConverter?.also { oneTimeTokenLoginConfigurer.authenticationConverter(authenticationConverter) } | ||
authenticationFailureHandler?.also { | ||
oneTimeTokenLoginConfigurer.authenticationFailureHandler( | ||
authenticationFailureHandler | ||
) | ||
} | ||
authenticationSuccessHandler?.also { | ||
oneTimeTokenLoginConfigurer.authenticationSuccessHandler( | ||
authenticationSuccessHandler | ||
) | ||
} | ||
defaultSubmitPageUrl?.also { oneTimeTokenLoginConfigurer.defaultSubmitPageUrl(defaultSubmitPageUrl) } | ||
showDefaultSubmitPage?.also { oneTimeTokenLoginConfigurer.showDefaultSubmitPage(showDefaultSubmitPage!!) } | ||
loginProcessingUrl?.also { oneTimeTokenLoginConfigurer.loginProcessingUrl(loginProcessingUrl) } | ||
generateTokenUrl?.also { oneTimeTokenLoginConfigurer.generateTokenUrl(generateTokenUrl) } | ||
generatedOneTimeTokenHandler?.also { | ||
oneTimeTokenLoginConfigurer.generatedOneTimeTokenHandler( | ||
generatedOneTimeTokenHandler | ||
) | ||
} | ||
authenticationProvider?.also { oneTimeTokenLoginConfigurer.authenticationProvider(authenticationProvider) } | ||
} | ||
} | ||
} |
Oops, something went wrong.