-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6b3c36
commit 29afbb0
Showing
12 changed files
with
91 additions
and
50 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
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
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
13 changes: 2 additions & 11 deletions
13
example/src/main/kotlin/org/babyfish/graphql/provider/example/query/FavoriteQuery.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
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
allprojects { | ||
group = "org.babyfish.graphql.provider" | ||
version = "0.0.8" | ||
version = "0.0.13" | ||
} |
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
21 changes: 19 additions & 2 deletions
21
...raphql-provider/src/main/kotlin/org/babyfish/graphql/provider/security/Authentications.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 |
---|---|---|
@@ -1,11 +1,28 @@ | ||
package org.babyfish.graphql.provider.security | ||
|
||
import kotlinx.coroutines.reactor.awaitSingleOrNull | ||
import org.springframework.security.access.AccessDeniedException | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.security.core.context.ReactiveSecurityContextHolder | ||
import org.springframework.security.core.userdetails.UserDetails | ||
import java.rmi.server.UID | ||
|
||
suspend fun authentication(): Authentication = | ||
authenticationOrNull() ?: error("No authentication") | ||
authenticationOrNull() ?: | ||
error("No authentication") | ||
|
||
suspend fun authenticationOrNull(): Authentication? = | ||
ReactiveSecurityContextHolder.getContext().awaitSingleOrNull()?.authentication | ||
ReactiveSecurityContextHolder.getContext().awaitSingleOrNull()?.authentication | ||
|
||
@SuppressWarnings("UNCHECKED_CAST") | ||
suspend fun <UD: UserDetails> currentUserDetails(): UD = | ||
authenticationOrNull()?.principal.let { | ||
when { | ||
it is UserDetails -> | ||
it as UD | ||
it === null -> | ||
throw AccessDeniedException("Access Denied") | ||
else -> | ||
throw AccessDeniedException("Current principal is not UserDetails") | ||
} | ||
} |
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
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
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