-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from RADAR-base/feat/ory-auth
Add support for Ory auth
- Loading branch information
Showing
10 changed files
with
179 additions
and
37 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
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
50 changes: 50 additions & 0 deletions
50
...ckend/src/main/java/org/radarbase/authorizer/enhancer/ManagementPortalResourceEnhancer.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,50 @@ | ||
package org.radarbase.authorizer.enhancer | ||
|
||
import jakarta.inject.Singleton | ||
import org.glassfish.jersey.internal.inject.AbstractBinder | ||
import org.radarbase.auth.authentication.TokenValidator | ||
import org.radarbase.auth.authorization.AuthorizationOracle | ||
import org.radarbase.authorizer.service.MPClientFactory | ||
import org.radarbase.jersey.auth.AuthConfig | ||
import org.radarbase.jersey.auth.AuthValidator | ||
import org.radarbase.jersey.auth.jwt.AuthorizationOracleFactory | ||
import org.radarbase.jersey.auth.jwt.TokenValidatorFactory | ||
import org.radarbase.jersey.auth.managementportal.ManagementPortalTokenValidator | ||
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer | ||
import org.radarbase.jersey.service.ProjectService | ||
import org.radarbase.jersey.service.managementportal.MPProjectService | ||
import org.radarbase.jersey.service.managementportal.ProjectServiceWrapper | ||
import org.radarbase.jersey.service.managementportal.RadarProjectService | ||
import org.radarbase.management.client.MPClient | ||
|
||
class ManagementPortalResourceEnhancer(private val config: AuthConfig) : JerseyResourceEnhancer { | ||
override fun AbstractBinder.enhance() { | ||
val config = config.withEnv() | ||
|
||
bindFactory(TokenValidatorFactory::class.java) | ||
.to(TokenValidator::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
bind(ManagementPortalTokenValidator::class.java) | ||
.to(AuthValidator::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
bindFactory(AuthorizationOracleFactory::class.java) | ||
.to(AuthorizationOracle::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
if (config.managementPortal.clientId != null) { | ||
bindFactory(MPClientFactory::class.java) | ||
.to(MPClient::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
bind(ProjectServiceWrapper::class.java) | ||
.to(ProjectService::class.java) | ||
.`in`(Singleton::class.java) | ||
|
||
bind(MPProjectService::class.java) | ||
.to(RadarProjectService::class.java) | ||
.`in`(Singleton::class.java) | ||
} | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
authorizer-app-backend/src/main/java/org/radarbase/authorizer/service/MPClientFactory.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,46 @@ | ||
package org.radarbase.authorizer.service | ||
|
||
import jakarta.ws.rs.core.Context | ||
import org.radarbase.authorizer.config.AuthorizerConfig | ||
import org.radarbase.ktor.auth.ClientCredentialsConfig | ||
import org.radarbase.ktor.auth.clientCredentials | ||
import org.radarbase.management.client.MPClient | ||
import org.slf4j.LoggerFactory | ||
import java.net.URI | ||
import java.util.function.Supplier | ||
|
||
class MPClientFactory( | ||
@Context private val config: AuthorizerConfig, | ||
) : Supplier<MPClient> { | ||
|
||
override fun get(): MPClient { | ||
val baseUrl = config.auth.managementPortalUrl | ||
val clientId = config.auth.clientId | ||
val clientSecret = config.auth.clientSecret ?: throw IllegalArgumentException("Client Secret is required") | ||
val customTokenUrl = config.auth.authUrl | ||
|
||
val mpClientConfig = MPClient.Config().apply { | ||
url = baseUrl | ||
|
||
auth { | ||
val authConfig = ClientCredentialsConfig( | ||
tokenUrl = customTokenUrl, | ||
clientId = clientId, | ||
clientSecret = clientSecret, | ||
audience = "res_ManagementPortal", | ||
).copyWithEnv() | ||
|
||
return@auth clientCredentials( | ||
authConfig = authConfig, | ||
targetHost = URI.create(baseUrl).host, | ||
) | ||
} | ||
} | ||
|
||
return MPClient(mpClientConfig) | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(MPClientFactory::class.java) | ||
} | ||
} |
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