Skip to content

Commit

Permalink
chore: ktlint 12.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
programadorthi committed Jan 13, 2024
1 parent 0202690 commit 7488777
Show file tree
Hide file tree
Showing 117 changed files with 8,589 additions and 7,958 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
ktlint_function_naming_ignore_when_annotated_with = Composable
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class AuthenticationConfig(providers: Map<String?, AuthenticationProvider
* Registers a provider with the specified [name] and allows you to [configure] it.
* @throws IllegalArgumentException if a provider with the same name is already installed.
*/
public fun provider(name: String? = null, configure: DynamicProviderConfig.() -> Unit) {
public fun provider(
name: String? = null,
configure: DynamicProviderConfig.() -> Unit,
) {
requireProviderNotRegistered(name)
val configuration = DynamicProviderConfig(name).apply(configure)
val provider = configuration.buildProvider()
Expand Down Expand Up @@ -83,7 +86,6 @@ public class AuthenticationConfig(providers: Map<String?, AuthenticationProvider
* [Authentication and authorization](https://ktor.io/docs/authentication.html).
*/
public class Authentication(internal var config: AuthenticationConfig) {

/**
* Configures an already installed plugin.
*/
Expand All @@ -99,7 +101,10 @@ public class Authentication(internal var config: AuthenticationConfig) {
public companion object : BaseApplicationPlugin<Application, AuthenticationConfig, Authentication> {
override val key: AttributeKey<Authentication> = AttributeKey("AuthenticationHolder")

override fun install(pipeline: Application, configure: AuthenticationConfig.() -> Unit): Authentication {
override fun install(
pipeline: Application,
configure: AuthenticationConfig.() -> Unit,
): Authentication {
val config = AuthenticationConfig().apply(configure)
return Authentication(config)
}
Expand All @@ -120,8 +125,7 @@ public inline fun <reified P : Principal> ApplicationCall.principal(): P? = prin
/**
* Retrieves an authenticated [Principal] for `this` call from provider with name [provider]
*/
public inline fun <reified P : Principal> ApplicationCall.principal(provider: String?): P? =
authentication.principal(provider)
public inline fun <reified P : Principal> ApplicationCall.principal(provider: String?): P? = authentication.principal(provider)

/**
* Installs the [Authentication] plugin if not yet installed and invokes [block] on its config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,33 @@ import kotlin.reflect.KClass
* @param call instance of [ApplicationCall] this context is for.
*/
public class AuthenticationContext(call: ApplicationCall) {

public var call: ApplicationCall = call
private set

private val _errors = HashMap<Any, AuthenticationFailedCause>()
private val errors = HashMap<Any, AuthenticationFailedCause>()

internal val _principal: CombinedPrincipal = CombinedPrincipal()
internal val combinedPrincipal: CombinedPrincipal = CombinedPrincipal()

/**
* All registered errors during auth procedure (only [AuthenticationFailedCause.Error]).
*/
public val allErrors: List<AuthenticationFailedCause.Error>
get() = _errors.values.filterIsInstance<AuthenticationFailedCause.Error>()
get() = errors.values.filterIsInstance<AuthenticationFailedCause.Error>()

/**
* All authentication failures during auth procedure including missing or invalid credentials.
*/
public val allFailures: List<AuthenticationFailedCause>
get() = _errors.values.toList()
get() = errors.values.toList()

/**
* Appends an error to the errors list. Overwrites if already registered for the same [key].
*/
public fun error(key: Any, cause: AuthenticationFailedCause) {
_errors[key] = cause
public fun error(
key: Any,
cause: AuthenticationFailedCause,
) {
errors[key] = cause
}

/**
Expand All @@ -49,14 +51,17 @@ public class AuthenticationContext(call: ApplicationCall) {
* Sets an authenticated principal for this context.
*/
public fun principal(principal: Principal) {
_principal.add(null, principal)
combinedPrincipal.add(null, principal)
}

/**
* Sets an authenticated principal for this context from provider with name [provider].
*/
public fun principal(provider: String? = null, principal: Principal) {
_principal.add(provider, principal)
public fun principal(
provider: String? = null,
principal: Principal,
) {
combinedPrincipal.add(provider, principal)
}

/**
Expand All @@ -69,8 +74,11 @@ public class AuthenticationContext(call: ApplicationCall) {
/**
* Retrieves a principal of the type [T], if any.
*/
public fun <T : Principal> principal(provider: String?, klass: KClass<T>): T? {
return _principal.get(provider, klass)
public fun <T : Principal> principal(
provider: String?,
klass: KClass<T>,
): T? {
return combinedPrincipal.get(provider, klass)
}

/**
Expand All @@ -79,7 +87,7 @@ public class AuthenticationContext(call: ApplicationCall) {
public fun challenge(
key: Any,
cause: AuthenticationFailedCause,
function: ChallengeFunction
function: ChallengeFunction,
) {
error(key, cause)
challenge.register.add(cause to function)
Expand Down
Loading

0 comments on commit 7488777

Please sign in to comment.