From 9bf1a6f30a7a37fe39a5774cd279185581d5ddbd Mon Sep 17 00:00:00 2001 From: Brian Schlining Date: Tue, 2 Jul 2024 11:23:21 -0700 Subject: [PATCH] #1 - The old vars user auth is snake case. Changed Oni's auth to snake case --- build.sbt | 54 +++++++++---------- .../AuthorizationEndpointsSuite.scala | 10 ++-- ...horization.scala => AuthorizationSC.scala} | 6 +-- .../endpoints/AuthorizationEndpoints.scala | 12 ++--- .../org/mbari/oni/etc/circe/CirceCodecs.scala | 4 +- project/Dependencies.scala | 13 ++--- 6 files changed, 50 insertions(+), 49 deletions(-) rename oni/src/main/scala/org/mbari/oni/domain/{Authorization.scala => AuthorizationSC.scala} (62%) diff --git a/build.sbt b/build.sbt index d906b5e..88fe417 100644 --- a/build.sbt +++ b/build.sbt @@ -81,33 +81,33 @@ lazy val oni = project ) ), libraryDependencies ++= Seq( - auth0, - circeCore, - circeGeneric, - circeParser, - commonsCodec, - helidonEncodingDeflate, - helidonEncodingGzip, - hibernateCore, - hibernateEnvers, - hibernateHikari, - hikariCp, - jansi % Runtime, - jaspyt, - junit % Test, - logback, - mssqlserver, - munit % Test, - oracle, - postgresql, - slf4jSystem, - tapirCirce, - tapirHelidon, - tapirPrometheus, - tapirServerStub % Test, - tapirSttpCirce, - tapirSwagger, - typesafeConfig + auth0, + circeCore, + circeGeneric, + circeParser, + commonsCodec, + helidonEncodingDeflate, + helidonEncodingGzip, + hibernateCore, + hibernateEnvers, + hibernateHikari, + hikariCp, + jansi % Runtime, + jaspyt, + junit % Test, + logback, + mssqlserver, + munit % Test, + oracle, + postgresql, + slf4jSystem, + tapirCirce, + tapirHelidon, + tapirPrometheus, + tapirServerStub % Test, + tapirSttpCirce, + tapirSwagger, + typesafeConfig ) ) diff --git a/it/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpointsSuite.scala b/it/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpointsSuite.scala index dc195fb..ca999a2 100644 --- a/it/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpointsSuite.scala +++ b/it/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpointsSuite.scala @@ -17,7 +17,7 @@ package org.mbari.oni.endpoints import io.circe.parser.decode -import org.mbari.oni.domain.{Authorization, UserAccount, UserAccountRoles} +import org.mbari.oni.domain.{AuthorizationSC, UserAccount, UserAccountRoles} import org.mbari.oni.etc.circe.CirceCodecs.given import org.mbari.oni.etc.jwt.JwtService import org.mbari.oni.jpa.DatabaseFunSuite @@ -49,10 +49,10 @@ trait AuthorizationEndpointsSuite extends DatabaseFunSuite with EndpointsSuite: assert(response.body.isRight) // println(body) - val d = decode[Authorization](body) + val d = decode[AuthorizationSC](body) assert(d.isRight) val bearerAuth = d.getOrElse(throw new Exception("No bearer auth")) - assert(jwtService.verify(bearerAuth.accessToken)) + assert(jwtService.verify(bearerAuth.access_token)) test("login"): val userService = UserAccountService(entityManagerFactory) @@ -81,7 +81,7 @@ trait AuthorizationEndpointsSuite extends DatabaseFunSuite with EndpointsSuite: assert(response.body.isRight) // println(body) - val d = decode[Authorization](body) + val d = decode[AuthorizationSC](body) assert(d.isRight) val bearerAuth = d.getOrElse(throw new Exception("No bearer auth")) - assert(jwtService.verify(bearerAuth.accessToken)) + assert(jwtService.verify(bearerAuth.access_token)) diff --git a/oni/src/main/scala/org/mbari/oni/domain/Authorization.scala b/oni/src/main/scala/org/mbari/oni/domain/AuthorizationSC.scala similarity index 62% rename from oni/src/main/scala/org/mbari/oni/domain/Authorization.scala rename to oni/src/main/scala/org/mbari/oni/domain/AuthorizationSC.scala index 5af2c23..ea94d9e 100644 --- a/oni/src/main/scala/org/mbari/oni/domain/Authorization.scala +++ b/oni/src/main/scala/org/mbari/oni/domain/AuthorizationSC.scala @@ -7,10 +7,10 @@ package org.mbari.oni.domain -final case class Authorization(tokenType: String, accessToken: String) +final case class AuthorizationSC(token_type: String, access_token: String) -object Authorization: +object AuthorizationSC: val TokenTypeBearer: String = "Bearer" val TokenTypeApiKey: String = "APIKey" - def bearer(accessToken: String): Authorization = Authorization(TokenTypeBearer, accessToken) + def bearer(accessToken: String): AuthorizationSC = AuthorizationSC(TokenTypeBearer, accessToken) diff --git a/oni/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpoints.scala b/oni/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpoints.scala index 89730ea..cc09754 100644 --- a/oni/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpoints.scala +++ b/oni/src/main/scala/org/mbari/oni/endpoints/AuthorizationEndpoints.scala @@ -15,7 +15,7 @@ import sttp.tapir.Endpoint import sttp.tapir.generic.auto.* import sttp.tapir.json.circe.* import sttp.tapir.server.ServerEndpoint -import org.mbari.oni.domain.{Authorization, BadRequest, ErrorMsg, NotFound, ServerError, Unauthorized} +import org.mbari.oni.domain.{AuthorizationSC, BadRequest, ErrorMsg, NotFound, ServerError, Unauthorized} import org.mbari.oni.etc.circe.CirceCodecs.given import org.mbari.oni.services.UserAccountService import sttp.tapir.model.UsernamePassword @@ -29,7 +29,7 @@ class AuthorizationEndpoints(entityManagerFactory: EntityManagerFactory)(using j private val base = "auth" private val tag = "Authorization" - val authEndpoint: Endpoint[String, Unit, ErrorMsg, Authorization, Any] = + val authEndpoint: Endpoint[String, Unit, ErrorMsg, AuthorizationSC, Any] = baseEndpoint .post .in(base) @@ -38,7 +38,7 @@ class AuthorizationEndpoints(entityManagerFactory: EntityManagerFactory)(using j "Header format is `Authorization: APIKEY `" ) ) - .out(jsonBody[Authorization]) + .out(jsonBody[AuthorizationSC]) .errorOut( oneOf[ErrorMsg]( oneOfVariant(statusCode(StatusCode.BadRequest).and(jsonBody[BadRequest])), @@ -65,7 +65,7 @@ class AuthorizationEndpoints(entityManagerFactory: EntityManagerFactory)(using j val apiKey = parts(1) jwtService.authorize(apiKey) match case None => Left(Unauthorized("Invalid API key")) - case Some(jwt) => Right(Authorization.bearer(jwt)) + case Some(jwt) => Right(AuthorizationSC.bearer(jwt)) ) .serverLogic(bearerAuth => Unit => Right(bearerAuth)) @@ -74,7 +74,7 @@ class AuthorizationEndpoints(entityManagerFactory: EntityManagerFactory)(using j .post .in(base / "login") .securityIn(auth.basic[UsernamePassword](WWWAuthenticateChallenge.basic(AuthenticationScheme.Basic.name))) - .out(jsonBody[Authorization]) + .out(jsonBody[AuthorizationSC]) .errorOut( oneOf[ErrorMsg]( oneOfVariant(statusCode(StatusCode.BadRequest).and(jsonBody[BadRequest])), @@ -103,7 +103,7 @@ class AuthorizationEndpoints(entityManagerFactory: EntityManagerFactory)(using j jwt <- jwtService .login(usernamePassword.username, usernamePassword.password.getOrElse(""), entity) .toRight(Unauthorized("Invalid username or password")) - yield Authorization.bearer(jwt) + yield AuthorizationSC.bearer(jwt) } .serverLogic(bearerAuth => Unit => Right(bearerAuth)) diff --git a/oni/src/main/scala/org/mbari/oni/etc/circe/CirceCodecs.scala b/oni/src/main/scala/org/mbari/oni/etc/circe/CirceCodecs.scala index 36aa6d9..ae32bb6 100644 --- a/oni/src/main/scala/org/mbari/oni/etc/circe/CirceCodecs.scala +++ b/oni/src/main/scala/org/mbari/oni/etc/circe/CirceCodecs.scala @@ -54,8 +54,8 @@ object CirceCodecs: given Encoder[Unauthorized] = deriveEncoder // --- Domain Objects --- - given Decoder[Authorization] = deriveDecoder - given Encoder[Authorization] = deriveEncoder + given Decoder[AuthorizationSC] = deriveDecoder + given Encoder[AuthorizationSC] = deriveEncoder given Decoder[Concept] = deriveDecoder given Encoder[Concept] = deriveEncoder diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 1da9313..e78faa9 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -11,10 +11,11 @@ object Dependencies { lazy val commonsCodec = "commons-codec" % "commons-codec" % "1.17.0" lazy val gson = "com.google.code.gson" % "gson" % "2.11.0" - // THis needs to match the version used by tapirHelidon + // THis needs to match the version used by tapirHelidon. + // Just including these in the build allows Helidon to use them for content encoding. val helidonVersion = "4.0.0" lazy val helidonEncodingDeflate = "io.helidon.http.encoding" % "helidon-http-encoding-deflate" % helidonVersion - lazy val helidonEncodingGzip = "io.helidon.http.encoding" % "helidon-http-encoding-gzip" % helidonVersion + lazy val helidonEncodingGzip = "io.helidon.http.encoding" % "helidon-http-encoding-gzip" % helidonVersion val hibernateVersion = "6.5.2.Final" lazy val hibernateCore = "org.hibernate.orm" % "hibernate-core" % hibernateVersion @@ -30,7 +31,7 @@ object Dependencies { lazy val munit = "org.scalameta" %% "munit" % "1.0.0" lazy val oracle = "com.oracle.ojdbc" % "ojdbc8" % "19.3.0.0" lazy val postgresql = "org.postgresql" % "postgresql" % "42.7.3" - lazy val scilube = "org.mbari.scilube" %% "scilube" % "3.0.1" +// lazy val scilube = "org.mbari.scilube" %% "scilube" % "3.0.1" val slf4jVersion = "2.0.13" lazy val slf4jJulBridge = "org.slf4j" % "jul-to-slf4j" % slf4jVersion @@ -54,8 +55,8 @@ object Dependencies { lazy val testcontainersPostgres = "org.testcontainers" % "postgresql" % testcontainersVersion lazy val typesafeConfig = "com.typesafe" % "config" % "1.4.3" - lazy val uuidgen = "org.mbari.uuid" % "uuid-gen" % "0.1.4" - lazy val vcr4jCore = "org.mbari.vcr4j" % "vcr4j-core" % "5.2.0" - lazy val zeromq = "org.zeromq" % "jeromq" % "0.6.0" +// lazy val uuidgen = "org.mbari.uuid" % "uuid-gen" % "0.1.4" +// lazy val vcr4jCore = "org.mbari.vcr4j" % "vcr4j-core" % "5.2.0" +// lazy val zeromq = "org.zeromq" % "jeromq" % "0.6.0" } \ No newline at end of file