Skip to content

Commit

Permalink
Merge pull request #115 from RADAR-base/release-2.1.0
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
mpgxvii authored Mar 5, 2021
2 parents e3be534 + af78ac6 commit cb0ce94
Show file tree
Hide file tree
Showing 39 changed files with 1,285 additions and 372 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.kt]
continuation_indent_size = 4
disabled_rules=no-wildcard-imports

[*.md]
trim_trailing_whitespace = false

Expand Down
3 changes: 1 addition & 2 deletions authorizer-app-backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ plugins {
id("org.jetbrains.kotlin.plugin.noarg")
id("org.jetbrains.kotlin.plugin.jpa")
id("org.jetbrains.kotlin.plugin.allopen")
id("org.jlleitschuh.gradle.ktlint") version "9.4.1"
}


application {
mainClassName = "org.radarbase.authorizer.MainKt"
}
Expand All @@ -30,7 +30,6 @@ project.extra.apply {
set("description", "RADAR Rest Source Authorizer handles authorization for data access from third party APIs for wearable devices or other connected sources.")
}


repositories {
jcenter()
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class Config(
val service: AuthorizerServiceConfig = AuthorizerServiceConfig(),
val auth: AuthConfig = AuthConfig(),
val database: DatabaseConfig = DatabaseConfig(),
val restSourceClients: List<RestSourceClient> = emptyList()
val restSourceClients: List<RestSourceClient> = emptyList(),
)

data class AuthorizerServiceConfig(
Expand All @@ -37,7 +37,7 @@ data class AuthorizerServiceConfig(
var enableCors: Boolean? = false,
var syncProjectsIntervalMin: Long = 30,
var syncParticipantsIntervalMin: Long = 30,
val stateStoreExpiryInMin: Long = 5
val stateStoreExpiryInMin: Long = 5,
)

data class AuthConfig(
Expand All @@ -47,23 +47,26 @@ data class AuthConfig(
var jwtECPublicKeys: List<String>? = null,
var jwtRSAPublicKeys: List<String>? = null,
var jwtIssuer: String? = null,
var jwtResourceName: String = "res_restAuthorizer"
var jwtResourceName: String = "res_restAuthorizer",
)

data class RestSourceClient(
val sourceType: String,
val preAuthorizationEndpoint: String?,
val authorizationEndpoint: String,
val deregistrationEndpoint: String?,
val tokenEndpoint: String,
val clientId: String? = null,
val clientSecret: String? = null,
val grantType: String? = null,
val scope: String? = null
val scope: String? = null,
val state: String? = null,
) {
fun withEnv(): RestSourceClient = this
.copyEnv("${sourceType.toUpperCase(Locale.US)}_CLIENT_ID") { copy(clientId = it) }
.copyEnv("${sourceType.toUpperCase(Locale.US)}_CLIENT_SECRET") { copy(clientSecret = it) }
.copyEnv("${sourceType.toUpperCase(Locale.US)}_CLIENT_ID") { copy(clientId = it) }
.copyEnv("${sourceType.toUpperCase(Locale.US)}_CLIENT_SECRET") { copy(clientSecret = it) }
}

data class RestSourceClients(
val clients: List<RestSourceClient>
val clients: List<RestSourceClient>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,54 @@ import com.fasterxml.jackson.annotation.JsonProperty
import java.io.Serializable
import java.time.Instant


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


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

data class RestOauth1UserId(
@JsonProperty("userId") var userId: String,
)

data class SignRequestParams(
var url: String,
var method: String,
val parameters: Map<String, String?>,
)

data class DeregistrationsDTO(
val deregistrations: List<DeregistrationParams>
)

data class DeregistrationParams(
val userId: String,
val userAccessToken: String
)

data class RequestTokenPayload(
var sourceType: String,
var code: String? = null,
var state: String? = null,
var oauth_token: String? = null,
var oauth_verifier: String? = null,
var oauth_token_secret: String? = null,
)

data class ShareableClientDetail(
val sourceType: String,
val preAuthorizationEndpoint: String?,
val deregistrationEndpoint: String?,
val authorizationEndpoint: String,
val tokenEndpoint: String,
val grantType: String?,
Expand All @@ -42,11 +78,12 @@ data class ShareableClientDetail(
)

data class ShareableClientDetails(
val sourceClients: List<ShareableClientDetail>
val sourceClients: List<ShareableClientDetail>,
)

class RestSourceUserDTO(
val id: String?,
val createdAt: Instant?,
val projectId: String?,
val userId: String?,
val humanReadableUserId: String?,
Expand All @@ -56,28 +93,31 @@ class RestSourceUserDTO(
val startDate: Instant,
val endDate: Instant? = null,
val sourceType: String,
val isAuthorized: Boolean = false,
var isAuthorized: Boolean = false,
val hasValidToken: Boolean = false,
val version: String? = null,
val timesReset: Long = 0) : Serializable {
val timesReset: Long = 0,
) : Serializable {
companion object {
private const val serialVersionUID = 1L
}
}

data class RestSourceUsers(
val users: List<RestSourceUserDTO>
val users: List<RestSourceUserDTO>,
val metadata: Page?
)

class TokenDTO(
data class TokenDTO(
val accessToken: String?,
val expiresAt: Instant?
val expiresAt: Instant?,
)

data class Page(
val pageNumber: Int = 1,
val pageSize: Int? = null,
val totalElements: Long? = null) {
val pageSize: Int = Integer.MAX_VALUE,
val totalElements: Long? = null
) {
val offset: Int
get() = (this.pageNumber - 1) * this.pageSize!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ import org.radarbase.jersey.service.managementportal.MPUser

data class ProjectList(val projects: List<Project>)

data class Project(val id: String, val name: String? = null, val location: String? = null, val organization: String? = null, val description: String? = null)
data class Project(
val id: String,
val name: String? = null,
val location: String? = null,
val organization: String? = null,
val description: String? = null,
)

fun MPProject.toProject() = Project(
id = id,
name = name,
location = location,
organization = organization,
description = description,
id = id,
name = name,
location = location,
organization = organization,
description = description,
)

data class UserList(val users: List<User>)

data class User(val id: String, val projectId: String, val externalId: String? = null, val status: String)

fun MPUser.toUser() = User(
id = id,
projectId = checkNotNull(projectId) { "User must have a project ID" },
externalId = externalId,
status = status,
id = id,
projectId = checkNotNull(projectId) { "User must have a project ID" },
externalId = externalId,
status = status,
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class RestSourceClientMapper {
clientId = requireNotNull(client.clientId) { "Client ID of sourceType ${client.sourceType} not specified" },
sourceType = client.sourceType,
scope = client.scope,
preAuthorizationEndpoint = client.preAuthorizationEndpoint,
authorizationEndpoint = client.authorizationEndpoint,
deregistrationEndpoint = client.deregistrationEndpoint,
tokenEndpoint = client.tokenEndpoint,
grantType = client.grantType,
grantType = client.grantType
)

fun fromSourceClientConfigs(clientConfigs: List<RestSourceClient>) = ShareableClientDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.radarbase.authorizer.doa.entity.RestSourceUser
import org.radarbase.jersey.service.managementportal.RadarProjectService
import javax.ws.rs.core.Context


class RestSourceUserMapper(
@Context private val projectService: RadarProjectService,
) {
Expand All @@ -30,10 +29,11 @@ class RestSourceUserMapper(
}
return RestSourceUserDTO(
id = user.id.toString(),
createdAt = user.createdAt,
projectId = user.projectId,
userId = user.userId,
humanReadableUserId = mpUser?.attributes?.get("Human-readable-identifier")
?.takeIf { it.isNotBlank() && it != "null" },
?.takeIf { it.isNotBlank() && it != "null" },
externalId = mpUser?.externalId,
sourceId = user.sourceId,
isAuthorized = user.authorized,
Expand All @@ -48,7 +48,7 @@ class RestSourceUserMapper(
}

fun fromRestSourceUsers(records: List<RestSourceUser>, page: Page?) = RestSourceUsers(
users = records.map(::fromEntity)
users = records.map(::fromEntity),
metadata = page
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface RestSourceUserRepository {
fun read(id: Long): RestSourceUser?
fun update(existingUser: RestSourceUser, user: RestSourceUserDTO): RestSourceUser
fun query(page: Page, projects: List<String>, sourceType: String? = null): 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?
}
Loading

0 comments on commit cb0ce94

Please sign in to comment.