-
Notifications
You must be signed in to change notification settings - Fork 54
Close #205: Admin services #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1bc34f3
Start admin service
Marchosiax 17e8f93
Add kafka config for admin events
Marchosiax 1ee9569
Added remaining files
Marchosiax 11192f8
Close #202: Currency CRUD
Marchosiax 35f5f20
Update realm config
Marchosiax 21a5bd3
Add impersonate service
Marchosiax 3e13098
Update opex realm config
Marchosiax 85bf0b9
Close #203: Add bc-gateway admin services
Marchosiax 2ec5a6a
Merge branch 'dev' of github.com:opexdev/OPEX-Core into 205-admin-con…
Marchosiax 2494d95
Fix security issue
Marchosiax b66db91
Add fetch services
Marchosiax 39ce864
Close #202: Currency services
Marchosiax 9deb392
Fix admin kafka host
Marchosiax b7e7b13
Fix admin vault issue
Marchosiax 4094112
Fix issues
Marchosiax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/controller/SystemConfigController.kt
This file contains hidden or 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,33 @@ | ||
| package co.nilin.opex.admin.app.controller | ||
|
|
||
| import co.nilin.opex.admin.app.data.AddCurrencyRequest | ||
| import co.nilin.opex.admin.app.data.EditCurrencyRequest | ||
| import co.nilin.opex.admin.app.service.SystemConfigService | ||
| import co.nilin.opex.utility.error.data.OpexError | ||
| import co.nilin.opex.utility.error.data.OpexException | ||
| import org.springframework.web.bind.annotation.* | ||
|
|
||
| @RestController | ||
| @RequestMapping("/system/v1") | ||
| class SystemConfigController(private val service: SystemConfigService) { | ||
|
|
||
| @PostMapping("/currency") | ||
| suspend fun addCurrency(@RequestBody body: AddCurrencyRequest) { | ||
| if (!body.isValid()) | ||
| throw OpexException(OpexError.BadRequest) | ||
| service.addCurrency(body) | ||
| } | ||
|
|
||
| @PutMapping("/currency/{name}") | ||
| suspend fun editCurrency(@RequestBody body: EditCurrencyRequest, @PathVariable name: String) { | ||
| if (!body.isValid()) | ||
| throw OpexException(OpexError.BadRequest) | ||
| service.editCurrency(name, body) | ||
| } | ||
|
|
||
| @DeleteMapping("/currency/{name}") | ||
| suspend fun deleteCurrency(@PathVariable name: String) { | ||
| service.deleteCurrency(name) | ||
| } | ||
|
|
||
| } |
13 changes: 13 additions & 0 deletions
13
admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/data/AddCurrencyRequest.kt
This file contains hidden or 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,13 @@ | ||
| package co.nilin.opex.admin.app.data | ||
|
|
||
| data class AddCurrencyRequest( | ||
| val name: String?, | ||
| val symbol: String?, | ||
| val precision: Double | ||
| ) { | ||
|
|
||
| fun isValid(): Boolean { | ||
| return !name.isNullOrEmpty() && !symbol.isNullOrEmpty() && precision > 0.0 && precision <= 1 | ||
| } | ||
|
|
||
| } | ||
10 changes: 10 additions & 0 deletions
10
admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/data/EditCurrencyRequest.kt
This file contains hidden or 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,10 @@ | ||
| package co.nilin.opex.admin.app.data | ||
|
|
||
| data class EditCurrencyRequest( | ||
| val symbol: String?, | ||
| val precision: Double | ||
| ){ | ||
| fun isValid(): Boolean { | ||
| return !symbol.isNullOrEmpty() && precision > 0.0 | ||
|
ebrahimmfadae marked this conversation as resolved.
|
||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/service/SystemConfigService.kt
This file contains hidden or 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,28 @@ | ||
| package co.nilin.opex.admin.app.service | ||
|
|
||
| import co.nilin.opex.admin.app.data.AddCurrencyRequest | ||
| import co.nilin.opex.admin.app.data.EditCurrencyRequest | ||
| import co.nilin.opex.admin.core.events.AddCurrencyEvent | ||
| import co.nilin.opex.admin.core.events.DeleteCurrencyEvent | ||
| import co.nilin.opex.admin.core.events.EditCurrencyEvent | ||
| import co.nilin.opex.admin.core.spi.AdminEventPublisher | ||
| import org.springframework.stereotype.Service | ||
|
|
||
| @Service | ||
| class SystemConfigService(private val publisher: AdminEventPublisher) { | ||
|
|
||
| suspend fun addCurrency(body: AddCurrencyRequest) { | ||
| with(body) { | ||
| publisher.publish(AddCurrencyEvent(name!!, symbol!!, precision)) | ||
| } | ||
| } | ||
|
|
||
| suspend fun editCurrency(name: String, body: EditCurrencyRequest) { | ||
| publisher.publish(EditCurrencyEvent(name, body.symbol!!, body.precision)) | ||
| } | ||
|
|
||
| suspend fun deleteCurrency(name: String) { | ||
| publisher.publish(DeleteCurrencyEvent(name)) | ||
| } | ||
|
|
||
| } |
11 changes: 4 additions & 7 deletions
11
admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/utils/Extensions.kt
This file contains hidden or 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,20 +1,17 @@ | ||
| package co.nilin.opex.admin.app.utils | ||
|
|
||
| import com.nimbusds.jose.shaded.json.JSONArray | ||
| import com.nimbusds.jose.shaded.json.JSONObject | ||
| import org.springframework.security.authorization.AuthorizationDecision | ||
| import org.springframework.security.config.web.server.ServerHttpSecurity | ||
| import org.springframework.security.oauth2.jwt.Jwt | ||
|
|
||
| fun ServerHttpSecurity.AuthorizeExchangeSpec.Access.hasRealmRole( | ||
| fun ServerHttpSecurity.AuthorizeExchangeSpec.Access.hasRole( | ||
| authority: String, | ||
| role: String | ||
| ): ServerHttpSecurity.AuthorizeExchangeSpec = access { mono, _ -> | ||
| mono.map { auth -> | ||
| auth.authorities.any { it.authority == authority } | ||
| && (((auth.principal as Jwt).claims["realm_access"] as JSONObject?)?.get("roles") as JSONArray?) | ||
| ?.contains(role) == true | ||
| }.map { granted -> | ||
| AuthorizationDecision(granted) | ||
| val hasAuthority = auth.authorities.any { it.authority == authority } | ||
| val hasRole = ((auth.principal as Jwt).claims["roles"] as JSONArray?)?.contains(role) == true | ||
| AuthorizationDecision(hasAuthority && hasRole) | ||
| } | ||
| } |
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/events/AddCurrencyEvent.kt
This file contains hidden or 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,7 @@ | ||
| package co.nilin.opex.admin.core.events | ||
|
|
||
| data class AddCurrencyEvent( | ||
| val name: String, | ||
| val symbol: String, | ||
| val precision: Double | ||
| ) : AdminEvent() |
4 changes: 4 additions & 0 deletions
4
admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/events/AdminEvent.kt
This file contains hidden or 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,4 @@ | ||
| package co.nilin.opex.admin.core.events | ||
|
|
||
| abstract class AdminEvent { | ||
| } |
3 changes: 3 additions & 0 deletions
3
admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/events/DeleteCurrencyEvent.kt
This file contains hidden or 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,3 @@ | ||
| package co.nilin.opex.admin.core.events | ||
|
|
||
| data class DeleteCurrencyEvent(val name: String) : AdminEvent() |
7 changes: 7 additions & 0 deletions
7
admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/events/EditCurrencyEvent.kt
This file contains hidden or 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,7 @@ | ||
| package co.nilin.opex.admin.core.events | ||
|
|
||
| data class EditCurrencyEvent( | ||
|
ebrahimmfadae marked this conversation as resolved.
|
||
| val name: String, | ||
| val symbol: String, | ||
| val precision: Double | ||
| ) : AdminEvent() | ||
9 changes: 9 additions & 0 deletions
9
admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/spi/AdminEventPublisher.kt
This file contains hidden or 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,9 @@ | ||
| package co.nilin.opex.admin.core.spi | ||
|
|
||
| import co.nilin.opex.admin.core.events.AdminEvent | ||
|
|
||
| interface AdminEventPublisher { | ||
|
|
||
| suspend fun publish(event: AdminEvent) | ||
|
|
||
| } |
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
...in-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/ImpersonateRequest.kt
This file contains hidden or 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,7 @@ | ||
| package co.nilin.opex.admin.ports.auth.data | ||
|
|
||
| data class ImpersonateRequest( | ||
| val clientId: String, | ||
| val clientSecret: String, | ||
| val userId: String | ||
| ) |
44 changes: 44 additions & 0 deletions
44
.../admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/proxy/KeycloakProxy.kt
This file contains hidden or 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,44 @@ | ||
| package co.nilin.opex.admin.ports.auth.proxy | ||
|
|
||
| import kotlinx.coroutines.reactor.awaitSingle | ||
| import org.slf4j.LoggerFactory | ||
| import org.springframework.beans.factory.annotation.Value | ||
| import org.springframework.http.MediaType | ||
| import org.springframework.stereotype.Component | ||
| import org.springframework.web.reactive.function.BodyInserters | ||
| import org.springframework.web.reactive.function.client.WebClient | ||
| import org.springframework.web.reactive.function.client.bodyToMono | ||
|
|
||
| @Component | ||
| class KeycloakProxy(private val webClient: WebClient) { | ||
|
|
||
| private val logger = LoggerFactory.getLogger(KeycloakProxy::class.java) | ||
|
|
||
| @Value("\${app.auth.token-url}") | ||
| private lateinit var tokenUrl: String | ||
|
|
||
| suspend fun impersonate( | ||
| token: String, | ||
| clientId: String, | ||
| clientSecret: String, | ||
| userId: String | ||
| ): String { | ||
| val body = BodyInserters.fromFormData("client_id", clientId) | ||
| .with("client_secret", clientSecret) | ||
| .with("requested_subject", userId) | ||
| .with("subject_token", token) | ||
| .with("grant_type", "urn:ietf:params:oauth:grant-type:token-exchange") | ||
|
|
||
| logger.info("Request token exchange for user $userId and client $clientId") | ||
| return webClient.post() | ||
| .uri(tokenUrl) | ||
| .accept(MediaType.APPLICATION_JSON) | ||
| .header("Content-Type", "application/x-www-form-urlencoded") | ||
| .body(body) | ||
| .retrieve() | ||
| .onStatus({ t -> t.isError }, { it.createException() }) | ||
| .bodyToMono<String>() | ||
| .awaitSingle() | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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,33 @@ | ||
| HELP.md | ||
| target/ | ||
| !.mvn/wrapper/maven-wrapper.jar | ||
| !**/src/main/**/target/ | ||
| !**/src/test/**/target/ | ||
|
|
||
| ### STS ### | ||
| .apt_generated | ||
| .classpath | ||
| .factorypath | ||
| .project | ||
| .settings | ||
| .springBeans | ||
| .sts4-cache | ||
|
|
||
| ### IntelliJ IDEA ### | ||
| .idea | ||
| *.iws | ||
| *.iml | ||
| *.ipr | ||
|
|
||
| ### NetBeans ### | ||
| /nbproject/private/ | ||
| /nbbuild/ | ||
| /dist/ | ||
| /nbdist/ | ||
| /.nb-gradle/ | ||
| build/ | ||
| !**/src/main/**/build/ | ||
| !**/src/test/**/build/ | ||
|
|
||
| ### VS Code ### | ||
| .vscode/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.