Skip to content
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

Release 4.4.0 #245

Merged
merged 45 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5807030
Bump dev versions
blootsvoets Mar 23, 2023
51b1c91
Readability fixes
blootsvoets Mar 30, 2023
a43e0cd
Store auth params in authorization page as well
mpgxvii May 10, 2023
13fb5a4
Merge pull request #235 from RADAR-base/fix/garmin-auth-url
mpgxvii May 10, 2023
0b05de8
Update to latest radar-auth
blootsvoets May 23, 2023
e3c468d
Code cleanup
blootsvoets May 24, 2023
082bc0e
Merge branch 'master' into dev
blootsvoets Sep 28, 2023
7c1e40c
Use radar-commons plugin
blootsvoets Sep 28, 2023
a18a121
Bump dockerfile versions
blootsvoets Sep 28, 2023
c074635
Bump dependencies and optimize imports
blootsvoets Oct 2, 2023
92ee7e0
Small build cleanup
blootsvoets Oct 2, 2023
28a6974
Merge branch 'dev' into update-radar-auth-2
blootsvoets Oct 2, 2023
f76adb1
Adding OuraAuthSerive and running it
Hsankesara Aug 22, 2023
34f323a
added Oura OAuth 2
Hsankesara Oct 11, 2023
a1c9c7c
merged dev and updated code
Hsankesara Oct 12, 2023
bd7ebb1
updated Resources
Hsankesara Oct 12, 2023
d70867a
fixed lint issues and solve permission error
Hsankesara Oct 12, 2023
10e041b
imports are in lexicographic order now
Hsankesara Oct 12, 2023
43f8519
minor changes from the PR review
Hsankesara Oct 16, 2023
0d66fd9
updated authorizer.yml
Hsankesara Oct 16, 2023
b35367a
added ring_configuration scope in Oura
Hsankesara Oct 16, 2023
3bfefd2
Merge pull request #241 from RADAR-base/Oura-oauth2
Hsankesara Oct 17, 2023
3e56a2e
Added code to get external id during auth Oura
Hsankesara Oct 18, 2023
f53462e
added exception handling
Hsankesara Oct 18, 2023
b09b453
fixed kotlin lint issue
Hsankesara Oct 18, 2023
a2f316a
fixed few other klint issue
Hsankesara Oct 18, 2023
c28db9f
simplify oura requestAccessToken function
Hsankesara Oct 18, 2023
c9b0c3a
Bumped dependencies
blootsvoets Oct 23, 2023
9357146
updated Oura getExternalId fun
Hsankesara Oct 24, 2023
99a0431
solved lint issues I think
Hsankesara Oct 24, 2023
9b6b703
changed OURA_USER_ID_ENDPOINT url
Hsankesara Oct 24, 2023
8931cd0
Merge remote-tracking branch 'origin/dev' into update-radar-auth-2
blootsvoets Oct 24, 2023
54d5c90
More consistent use of IO context
blootsvoets Oct 25, 2023
5309608
Code style
blootsvoets Oct 25, 2023
f77da45
Merge pull request #244 from RADAR-base/update-radar-auth-2
blootsvoets Oct 25, 2023
26be7d5
Bump versions
mpgxvii Oct 25, 2023
2433d9c
Merge branch 'dev' into oura-oauth-service-userid
blootsvoets Oct 25, 2023
c2742f1
Add message to checkNotNull
blootsvoets Oct 25, 2023
ae3fd8f
Merge pull request #243 from RADAR-base/oura-oauth-service-userid
mpgxvii Oct 25, 2023
0226407
Merge pull request #246 from RADAR-base/dev
mpgxvii Oct 25, 2023
c592c7d
solved error of fetching external id in Oura
Hsankesara Oct 25, 2023
638bfe5
removed repeated properties in gradle wrapper
Hsankesara Oct 25, 2023
7271c57
changed height into float
Hsankesara Oct 25, 2023
5bda732
Merge pull request #247 from RADAR-base/oura-oauth-debugging
Hsankesara Oct 25, 2023
7ed4f5e
Fix lint errors
mpgxvii Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.kt]
ktlint_standard_no-wildcard-imports=disabled

[*.md]
trim_trailing_whitespace = false

[*.{json,yaml,yml}]
indent_style = space
indent_size = 2
4 changes: 3 additions & 1 deletion authorizer-app-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=$BUILDPLATFORM gradle:7.6-jdk17 as builder
FROM --platform=$BUILDPLATFORM gradle:8.3-jdk17 as builder

RUN mkdir /code
WORKDIR /code

ENV GRADLE_USER_HOME=/code/.gradlecache \
GRADLE_OPTS="-Djdk.lang.Process.launchMechanism=vfork -Dorg.gradle.vfs.watch=false"

COPY ./buildSrc /code/buildSrc
COPY ./build.gradle.kts ./settings.gradle.kts ./gradle.properties /code/
COPY ./buildSrc /code/buildSrc
COPY authorizer-app-backend/build.gradle.kts /code/authorizer-app-backend/
RUN gradle downloadDependencies copyDependencies startScripts

Expand Down
87 changes: 21 additions & 66 deletions authorizer-app-backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,86 +1,41 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
application
kotlin("jvm")
id("org.jetbrains.kotlin.plugin.noarg")
id("org.jetbrains.kotlin.plugin.jpa")
id("org.jetbrains.kotlin.plugin.allopen")
kotlin("plugin.serialization")
kotlin("plugin.noarg")
kotlin("plugin.jpa")
kotlin("plugin.allopen")
}

application {
mainClass.set("org.radarbase.authorizer.Main")
applicationDefaultJvmArgs = listOf(
"-Djava.security.egd=file:/dev/./urandom",
"-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager",
)
}

repositories {
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
api(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))

val radarJerseyVersion: String by project
implementation("org.radarbase:radar-jersey:$radarJerseyVersion")
implementation("org.radarbase:radar-jersey-hibernate:$radarJerseyVersion") {
val postgresVersion: String by project
runtimeOnly("org.postgresql:postgresql:$postgresVersion")
implementation("org.radarbase:radar-jersey:${Versions.radarJersey}")
implementation("org.radarbase:radar-jersey-hibernate:${Versions.radarJersey}") {
runtimeOnly("org.postgresql:postgresql:${Versions.postgresql}")
}
implementation("org.radarbase:radar-commons-kotlin:${Versions.radarCommons}")

val slf4jVersion: String by project
implementation("org.slf4j:slf4j-api:$slf4jVersion")

val okhttpVersion: String by project
implementation("com.squareup.okhttp3:okhttp:$okhttpVersion")
implementation("redis.clients:jedis:${Versions.jedis}")

val jedisVersion: String by project
implementation("redis.clients:jedis:$jedisVersion")
implementation(enforcedPlatform("io.ktor:ktor-bom:${Versions.ktor}"))
implementation("io.ktor:ktor-client-core")
implementation("io.ktor:ktor-client-auth")
implementation("io.ktor:ktor-client-cio")
implementation("io.ktor:ktor-client-content-negotiation")
implementation("io.ktor:ktor-serialization-kotlinx-json")

val log4j2Version: String by project
runtimeOnly("org.apache.logging.log4j:log4j-core:$log4j2Version")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:$log4j2Version")
runtimeOnly("org.apache.logging.log4j:log4j-jul:$log4j2Version")

val junitVersion: String by project
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
testImplementation("org.hamcrest:hamcrest-all:1.3")

val mockitoKotlinVersion: String by project
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion")

val jerseyVersion: String by project
testImplementation("org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:$jerseyVersion")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
apiVersion = "1.7"
languageVersion = "1.7"
}
}

tasks.withType<JavaCompile> {
options.release.set(17)
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = true
exceptionFormat = FULL
}
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
testImplementation("org.hamcrest:hamcrest:${Versions.hamcrest}")
testImplementation("org.mockito.kotlin:mockito-kotlin:${Versions.mockitoKotlin}")
testImplementation("org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:${Versions.jersey}")
}

allOpen {
annotation("javax.persistence.Entity")
annotation("javax.persistence.MappedSuperclass")
annotation("javax.persistence.Embeddable")
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.MappedSuperclass")
annotation("jakarta.persistence.Embeddable")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,48 @@

package org.radarbase.authorizer.api

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.time.Instant

@JsonIgnoreProperties(ignoreUnknown = true)
@Serializable
data class RestOauth2AccessToken(
@JsonProperty("access_token") val accessToken: String,
@JsonProperty("refresh_token") val refreshToken: String? = null,
@JsonProperty("expires_in") val expiresIn: Int = 0,
@JsonProperty("token_type") val tokenType: String? = null,
@JsonProperty("user_id") val externalUserId: String? = null,
@SerialName("access_token")
val accessToken: String,
@SerialName("refresh_token")
val refreshToken: String? = null,
@SerialName("expires_in")
val expiresIn: Int = 0,
@SerialName("token_type")
val tokenType: String? = null,
@SerialName("user_id")
val externalUserId: String? = null,
)

@Serializable
data class RestOauth1AccessToken(
@JsonProperty("oauth_token") val token: String,
@JsonProperty("oauth_token_secret") val tokenSecret: String? = null,
@JsonProperty("oauth_verifier") val tokenVerifier: String? = null,
@SerialName("oauth_token")
val token: String,
@SerialName("oauth_token_secret")
val tokenSecret: String? = null,
@SerialName("oauth_verifier")
val tokenVerifier: String? = null,
)

@Serializable
data class RestOauth1UserId(
@JsonProperty("userId") val userId: String,
@SerialName("userId")
val userId: String,
)

@Serializable
data class OuraAuthUserId(
val age: Int,
val weight: Float,
val height: Float,
val gender: String,
val email: String,
@SerialName("user_id") val userId: String,
)

data class SignRequestParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package org.radarbase.authorizer.api
import jakarta.ws.rs.core.Context
import org.radarbase.authorizer.doa.entity.RestSourceUser
import org.radarbase.jersey.service.managementportal.RadarProjectService
import org.radarbase.kotlin.coroutines.forkJoin

class RestSourceUserMapper(
@Context private val projectService: RadarProjectService,
) {
fun fromEntity(user: RestSourceUser): RestSourceUserDTO {
suspend fun fromEntity(user: RestSourceUser): RestSourceUserDTO {
val mpUser = user.projectId?.let { p ->
user.userId?.let { u -> projectService.subject(p, u) }
}
Expand All @@ -48,8 +49,8 @@ class RestSourceUserMapper(
)
}

fun fromRestSourceUsers(records: List<RestSourceUser>, page: Page?) = RestSourceUsers(
users = records.map(::fromEntity),
suspend fun fromRestSourceUsers(records: List<RestSourceUser>, page: Page?) = RestSourceUsers(
users = records.forkJoin { fromEntity(it) },
metadata = page,
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.radarbase.authorizer.config

import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import io.ktor.http.URLBuilder
import io.ktor.http.Url
import io.ktor.http.appendPathSegments
import io.ktor.http.takeFrom
import org.radarbase.authorizer.enhancer.ManagementPortalEnhancerFactory
import org.radarbase.jersey.enhancer.EnhancerFactory
import java.net.URI
Expand All @@ -18,26 +20,20 @@ data class AuthorizerServiceConfig(
val tokenExpiryTimeInMinutes: Long = 15,
val persistentTokenExpiryInMin: Long = 3.days.inWholeMinutes,
) {
val callbackUrl: HttpUrl by lazy {
val callbackUrl: Url by lazy {
val frontendBaseUrlBuilder = when {
frontendBaseUri != null -> frontendBaseUri.toHttpUrlOrNull()?.newBuilder()
advertisedBaseUri != null -> {
advertisedBaseUri.toHttpUrlOrNull()?.let { advertisedUrl ->
advertisedUrl.newBuilder().apply {
advertisedUrl.pathSegments.asReversed()
.forEachIndexed { idx, segment ->
if (segment.isEmpty() || segment == "backend") {
removePathSegment(advertisedUrl.pathSize - 1 - idx)
}
}
addPathSegment("authorizer")
}
frontendBaseUri != null -> URLBuilder().takeFrom(frontendBaseUri)
advertisedBaseUri != null -> URLBuilder().apply {
takeFrom(advertisedBaseUri)
pathSegments = buildList(pathSegments.size) {
addAll(pathSegments.dropLastWhile { it.isEmpty() || it == "backend" })
add("authorizer")
}
}
else -> null
else -> throw IllegalStateException("Frontend URL parameter is not a valid HTTP URL.")
}
checkNotNull(frontendBaseUrlBuilder) { "Frontend URL parameter $frontendBaseUri is not a valid HTTP URL." }
.addPathSegment("users:new")
frontendBaseUrlBuilder
.appendPathSegments("users:new")
.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.radarbase.authorizer.config

import org.radarbase.jersey.config.ConfigLoader.copyEnv
import java.util.*
import java.util.Locale

data class RestSourceClient(
val sourceType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import org.radarbase.authorizer.config.AuthorizerConfig
import org.radarbase.authorizer.doa.entity.RegistrationState
import org.radarbase.authorizer.doa.entity.RestSourceUser
import org.radarbase.authorizer.util.Hmac256Secret
import org.radarbase.authorizer.util.Hmac256Secret.Companion.encodeToBase64
import org.radarbase.authorizer.util.Hmac256Secret.Companion.randomize
import org.radarbase.authorizer.util.encodeToBase64
import org.radarbase.authorizer.util.randomize
import org.radarbase.jersey.hibernate.HibernateRepository
import org.radarbase.jersey.service.AsyncCoroutineService
import java.time.Instant
import kotlin.time.Duration.Companion.minutes

class RegistrationRepository(
@Context private val config: AuthorizerConfig,
@Context em: Provider<EntityManager>,
) : HibernateRepository(em) {
@Context asyncService: AsyncCoroutineService,
) : HibernateRepository(em, asyncService) {

private val tokenExpiryTime = config.service.tokenExpiryTimeInMinutes.minutes
private val persistentTokenExpiryTime = config.service.persistentTokenExpiryInMin.minutes

fun generate(
suspend fun generate(
user: RestSourceUser,
secret: Hmac256Secret?,
persistent: Boolean,
Expand Down Expand Up @@ -53,11 +55,11 @@ class RegistrationRepository(
}
}

operator fun get(token: String): RegistrationState? = transact {
suspend fun get(token: String): RegistrationState? = transact {
find(RegistrationState::class.java, token)
}

fun cleanUp(): Int = transact {
suspend fun cleanUp(): Int = transact {
val cb = criteriaBuilder

// create delete
Expand All @@ -70,15 +72,11 @@ class RegistrationRepository(
createQuery(deleteQuery).executeUpdate()
}

operator fun minusAssign(token: String) = remove(token)

operator fun minusAssign(registrationState: RegistrationState) = remove(registrationState)

fun remove(registrationState: RegistrationState): Unit = transact {
suspend fun remove(registrationState: RegistrationState): Unit = transact {
remove(registrationState)
}

fun remove(token: String): Unit = transact {
suspend fun remove(token: String): Unit = transact {
val state = find(RegistrationState::class.java, token)
remove(state)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import org.radarbase.authorizer.doa.entity.RestSourceUser
import java.time.Instant

interface RestSourceUserRepository {
fun create(user: RestSourceUserDTO): RestSourceUser
fun updateToken(token: RestOauth2AccessToken?, user: RestSourceUser): RestSourceUser
fun read(id: Long): RestSourceUser?
fun update(userId: Long, user: RestSourceUserDTO): RestSourceUser
fun query(
suspend fun create(user: RestSourceUserDTO): RestSourceUser
suspend fun updateToken(token: RestOauth2AccessToken?, user: RestSourceUser): RestSourceUser
suspend fun read(id: Long): RestSourceUser?
suspend fun update(userId: Long, user: RestSourceUserDTO): RestSourceUser
suspend fun query(
page: Page,
projectIds: List<String>,
sourceType: String? = null,
search: String?,
userIds: List<String>,
isAuthorized: Boolean?,
): Pair<List<RestSourceUser>, Page>
fun queryAllWithElapsedEndDate(sourceType: String? = null): List<RestSourceUser>
fun delete(user: RestSourceUser)
fun reset(user: RestSourceUser, startDate: Instant, endDate: Instant?): RestSourceUser
fun findByExternalId(externalId: String, sourceType: String): RestSourceUser?
suspend fun queryAllWithElapsedEndDate(sourceType: String? = null): List<RestSourceUser>
suspend fun delete(user: RestSourceUser)
suspend fun reset(user: RestSourceUser, startDate: Instant, endDate: Instant?): RestSourceUser
suspend fun findByExternalId(externalId: String, sourceType: String): RestSourceUser?
}
Loading