Открыть боковую панель
Aurora OS
Kotlin Multiplatform
Libraries
ktor
Коммиты
5cdf819c
Не подтверждена
Коммит
5cdf819c
создал
Дек 05, 2019
по автору
Sergey Mashkov
Просмотр файлов
Make authentication feature's phases public (#1160)
владелец
f471bc33
Изменения
1
Скрыть пробелы
Построчно
Рядом
ktor-features/ktor-auth/jvm/src/io/ktor/auth/Authentication.kt
Просмотр файла @
5cdf819c
...
...
@@ -32,7 +32,7 @@ class Authentication(config: Configuration) {
* Authentication configuration
*/
class
Configuration
(
providers
:
List
<
AuthenticationProvider
>
=
emptyList
())
{
internal
val
providers
=
ArrayList
<
AuthenticationProvider
>
(
providers
)
internal
val
providers
=
ArrayList
(
providers
)
/**
* Register a provider with the specified [name] and [configure] it
...
...
@@ -112,10 +112,10 @@ class Authentication(config: Configuration) {
}
}
pipeline
.
insertPhaseAfter
(
ApplicationCallPipeline
.
Features
,
a
uthenticat
ion
Phase
)
pipeline
.
insertPhaseAfter
(
a
uthenticat
ion
Phase
,
c
hallengePhase
)
pipeline
.
insertPhaseAfter
(
ApplicationCallPipeline
.
Features
,
A
uthenticat
e
Phase
)
pipeline
.
insertPhaseAfter
(
A
uthenticat
e
Phase
,
C
hallengePhase
)
pipeline
.
intercept
(
a
uthenticat
ion
Phase
)
{
pipeline
.
intercept
(
A
uthenticat
e
Phase
)
{
val
call
=
call
val
authenticationContext
=
AuthenticationContext
.
from
(
call
)
if
(
authenticationContext
.
principal
!=
null
)
return
@intercept
...
...
@@ -123,7 +123,7 @@ class Authentication(config: Configuration) {
processAuthentication
(
call
,
authenticationContext
,
configurations
,
authenticationPipeline
)
}
pipeline
.
intercept
(
c
hallengePhase
)
{
pipeline
.
intercept
(
C
hallengePhase
)
{
val
context
=
AuthenticationContext
.
from
(
call
)
when
{
...
...
@@ -143,10 +143,21 @@ class Authentication(config: Configuration) {
* Installable feature for [Authentication].
*/
companion
object
Feature
:
ApplicationFeature
<
Application
,
Configuration
,
Authentication
>
{
private
val
authenticationPhase
=
PipelinePhase
(
"Authenticate"
)
private
val
challengePhase
=
PipelinePhase
(
"Challenge"
)
/**
* Authenticate phase in that authentication procedures are executed.
* Please note that referring to the phase is only possible *after* feature installation.
*/
@KtorExperimentalAPI
val
AuthenticatePhase
:
PipelinePhase
=
PipelinePhase
(
"Authenticate"
)
/**
* Authenticate phase in that auth provider's challenges performing.
* Please note that referring to the phase is only possible *after* feature installation.
*/
@KtorExperimentalAPI
val
ChallengePhase
:
PipelinePhase
=
PipelinePhase
(
"Challenge"
)
override
val
key
=
AttributeKey
<
Authentication
>(
"Authentication"
)
override
val
key
:
AttributeKey
<
Authentication
>
=
AttributeKey
(
"Authentication"
)
override
fun
install
(
pipeline
:
Application
,
configure
:
Configuration
.()
->
Unit
):
Authentication
{
return
Authentication
().
apply
{
...
...
@@ -177,11 +188,11 @@ class Authentication(config: Configuration) {
context
:
AuthenticationContext
,
handleErrors
:
Boolean
)
{
val
challengePipeline
=
Pipeline
<
AuthenticationProcedureChallenge
,
ApplicationCall
>(
c
hallengePhase
)
val
challengePipeline
=
Pipeline
<
AuthenticationProcedureChallenge
,
ApplicationCall
>(
C
hallengePhase
)
val
challenges
=
context
.
challenge
.
challenges
for
(
challenge
in
challenges
)
{
challengePipeline
.
intercept
(
c
hallengePhase
)
{
challengePipeline
.
intercept
(
C
hallengePhase
)
{
challenge
(
it
)
if
(
it
.
completed
)
finish
()
// finish challenge pipeline if it has been completed
...
...
@@ -190,7 +201,7 @@ class Authentication(config: Configuration) {
if
(
handleErrors
)
{
for
(
challenge
in
context
.
challenge
.
errorChallenges
)
{
challengePipeline
.
intercept
(
c
hallengePhase
)
{
challengePipeline
.
intercept
(
C
hallengePhase
)
{
challenge
(
it
)
if
(
it
.
completed
)
finish
()
// finish challenge pipeline if it has been completed
...
...
@@ -198,7 +209,7 @@ class Authentication(config: Configuration) {
}
for
(
error
in
context
.
errors
.
values
.
filterIsInstance
<
AuthenticationFailedCause
.
Error
>())
{
challengePipeline
.
intercept
(
c
hallengePhase
)
{
challengePipeline
.
intercept
(
C
hallengePhase
)
{
if
(!
it
.
completed
)
{
logger
.
trace
(
"Responding unauthorized because of error ${error.cause}"
)
call
.
respond
(
UnauthorizedResponse
())
...
...
@@ -267,7 +278,7 @@ val ApplicationCall.authentication: AuthenticationContext
/**
* Retrieves authenticated [Principal] for `this` call
*/
inline
fun
<
reified
P
:
Principal
>
ApplicationCall
.
principal
()
=
authentication
.
principal
<
P
>()
inline
fun
<
reified
P
:
Principal
>
ApplicationCall
.
principal
()
:
P
?
=
authentication
.
principal
<
P
>()
/**
* Creates an authentication route that does handle authentication by the specified providers referred by
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать