Skip to content

Commit

Permalink
feature/Tweak endpoint getConsumers v5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine2nd committed Dec 23, 2024
1 parent 82629d8 commit 6c703a4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,6 @@ object SwaggerDefinitionsJSON {
val consumerJsonV510: ConsumerJsonV510 = ConsumerJsonV510(
consumer_id = consumerIdExample.value,
consumer_key = consumerKeyExample.value,
consumer_secret = consumerSecretExample.value,
app_name = appNameExample.value,
app_type = appTypeExample.value,
description = descriptionExample.value,
Expand Down
10 changes: 8 additions & 2 deletions obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
} yield deleted
case "status" => Full(OBPStatus(values.head))
case "consumer_id" => Full(OBPConsumerId(values.head))
case "azp" => Full(OBPAzp(values.head))
case "iss" => Full(OBPIss(values.head))
case "consent_id" => Full(OBPConsentId(values.head))
case "user_id" => Full(OBPUserId(values.head))
case "bank_id" => Full(OBPBankId(values.head))
Expand Down Expand Up @@ -1140,6 +1142,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
anon <- getHttpParamValuesByName(httpParams,"anon")
deletedStatus <- getHttpParamValuesByName(httpParams,"is_deleted")
consumerId <- getHttpParamValuesByName(httpParams,"consumer_id")
azp <- getHttpParamValuesByName(httpParams,"azp")
iss <- getHttpParamValuesByName(httpParams,"iss")
consentId <- getHttpParamValuesByName(httpParams,"consent_id")
userId <- getHttpParamValuesByName(httpParams, "user_id")
bankId <- getHttpParamValuesByName(httpParams, "bank_id")
Expand Down Expand Up @@ -1178,7 +1182,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
val ordering = OBPOrdering(sortBy, sortDirection)
//This guarantee the order
List(limit, offset, ordering, fromDate, toDate,
anon, status, consumerId, consentId, userId, url, appName, implementedByPartialFunction, implementedInVersion,
anon, status, consumerId, azp, iss, consentId, userId, url, appName, implementedByPartialFunction, implementedInVersion,
verb, correlationId, duration, excludeAppNames, excludeUrlPattern, excludeImplementedByPartialfunctions,
includeAppNames, includeUrlPattern, includeImplementedByPartialfunctions,
connectorName,functionName, bankId, accountId, customerId, lockedStatus, deletedStatus
Expand Down Expand Up @@ -1216,6 +1220,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
val status = getHttpRequestUrlParam(httpRequestUrl,"status")
val isDeleted = getHttpRequestUrlParam(httpRequestUrl, "is_deleted")
val consumerId = getHttpRequestUrlParam(httpRequestUrl,"consumer_id")
val iss = getHttpRequestUrlParam(httpRequestUrl,"iss")
val azp = getHttpRequestUrlParam(httpRequestUrl,"azp")
val consentId = getHttpRequestUrlParam(httpRequestUrl,"consent_id")
val userId = getHttpRequestUrlParam(httpRequestUrl, "user_id")
val bankId = getHttpRequestUrlParam(httpRequestUrl, "bank_id")
Expand Down Expand Up @@ -1247,7 +1253,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{

Full(List(
HTTPParam("sort_direction",sortDirection), HTTPParam("from_date",fromDate), HTTPParam("to_date", toDate), HTTPParam("limit",limit), HTTPParam("offset",offset),
HTTPParam("anon", anon), HTTPParam("status", status), HTTPParam("consumer_id", consumerId), HTTPParam("consent_id", consentId), HTTPParam("user_id", userId), HTTPParam("url", url), HTTPParam("app_name", appName),
HTTPParam("anon", anon), HTTPParam("status", status), HTTPParam("consumer_id", consumerId), HTTPParam("azp", azp), HTTPParam("iss", iss), HTTPParam("consent_id", consentId), HTTPParam("user_id", userId), HTTPParam("url", url), HTTPParam("app_name", appName),
HTTPParam("implemented_by_partial_function",implementedByPartialFunction), HTTPParam("implemented_in_version",implementedInVersion), HTTPParam("verb", verb),
HTTPParam("correlation_id", correlationId), HTTPParam("duration", duration), HTTPParam("exclude_app_names", excludeAppNames),
HTTPParam("exclude_url_patterns", excludeUrlPattern),HTTPParam("exclude_implemented_by_partial_functions", excludeImplementedByPartialfunctions),
Expand Down
2 changes: 2 additions & 0 deletions obp-api/src/main/scala/code/api/util/OBPParam.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ case class OBPFromDate(value: Date) extends OBPQueryParam
case class OBPToDate(value: Date) extends OBPQueryParam
case class OBPOrdering(field: Option[String], order: OBPOrder) extends OBPQueryParam
case class OBPConsumerId(value: String) extends OBPQueryParam
case class OBPAzp(value: String) extends OBPQueryParam
case class OBPIss(value: String) extends OBPQueryParam
case class OBPConsentId(value: String) extends OBPQueryParam
case class OBPUserId(value: String) extends OBPQueryParam
case class OBPStatus(value: String) extends OBPQueryParam
Expand Down
2 changes: 0 additions & 2 deletions obp-api/src/main/scala/code/api/v5_1_0/JSONFactory5.1.0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ case class ConsumerPostJsonV510(app_name: Option[String],
)
case class ConsumerJsonV510(consumer_id: String,
consumer_key: String,
consumer_secret: String,
app_name: String,
app_type: String,
description: String,
Expand Down Expand Up @@ -1025,7 +1024,6 @@ object JSONFactory510 extends CustomJsonFormats {
ConsumerJsonV510(
consumer_id = c.consumerId.get,
consumer_key = c.key.get,
consumer_secret = c.secret.get,
app_name = c.name.get,
app_type = c.appType.toString(),
description = c.description.get,
Expand Down
34 changes: 17 additions & 17 deletions obp-api/src/main/scala/code/model/OAuth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,27 @@ TESOBE (http://www.tesobe.com/)
*/
package code.model
import java.util.{Collections, Date}

import code.api.util.{APIUtil, CallContext, OBPAscending, OBPDescending, OBPFromDate, OBPLimit, OBPOffset, OBPOrdering, OBPQueryParam, OBPToDate}
import code.api.util.CommonFunctions.validUri
import code.api.util.migration.Migration.DbFunction
import code.api.util._
import code.consumer.{Consumers, ConsumersProvider}
import code.model.AppType.{Confidential, Public, Unknown}
import code.model.dataAccess.ResourceUser
import code.nonce.NoncesProvider
import code.token.TokensProvider
import code.users.Users
import code.util.Helper.MdcLoggable
import code.util.HydraUtil
import code.util.HydraUtil._
import code.views.system.{AccountAccess, ViewDefinition}
import com.github.dwickern.macros.NameOf
import com.openbankproject.commons.ExecutionContext.Implicits.global
import com.openbankproject.commons.model.{BankIdAccountId, User, View}
import net.liftweb.common._
import net.liftweb.http.S
import net.liftweb.mapper.{LongKeyedMetaMapper, _}
import net.liftweb.util.Helpers.{now, _}
import net.liftweb.mapper._
import net.liftweb.util.Helpers._
import net.liftweb.util.{FieldError, Helpers}
import org.apache.commons.lang3.StringUtils

import scala.collection.immutable.List
import java.util.Date
import scala.concurrent.Future


Expand Down Expand Up @@ -128,6 +123,8 @@ object MappedConsumersProvider extends ConsumersProvider with MdcLoggable {
val offset = queryParams.collect { case OBPOffset(value) => StartAt[Consumer](value) }.headOption
val fromDate = queryParams.collect { case OBPFromDate(date) => By_>=(Consumer.createdAt, date) }.headOption
val toDate = queryParams.collect { case OBPToDate(date) => By_<=(Consumer.createdAt, date) }.headOption
val azp = queryParams.collect { case OBPAzp(value) => By(Consumer.azp, value) }.headOption
val iss = queryParams.collect { case OBPIss(value) => By(Consumer.iss, value) }.headOption
val ordering = queryParams.collect {
case OBPOrdering(_, direction) =>
direction match {
Expand All @@ -136,7 +133,8 @@ object MappedConsumersProvider extends ConsumersProvider with MdcLoggable {
}
}

val mapperParams: Seq[QueryParam[Consumer]] = Seq(limit.toSeq, offset.toSeq, fromDate.toSeq, toDate.toSeq, ordering.toSeq).flatten
val mapperParams: Seq[QueryParam[Consumer]] =
Seq(limit.toSeq, offset.toSeq, fromDate.toSeq, toDate.toSeq, ordering, azp.toSeq, iss.toSeq).flatten

Consumer.findAll(mapperParams: _*)
}
Expand Down Expand Up @@ -387,13 +385,15 @@ object MappedConsumersProvider extends ConsumersProvider with MdcLoggable {
createdByUserId: Option[String]): Box[Consumer] = {

val consumer: Box[Consumer] =
// 1st try represent GatewayLogin usage of this function
Consumer.find(By(Consumer.consumerId, consumerId.getOrElse("None"))) or {
// 2nd try represent OAuth2 usage of this function
Consumer.find(By(Consumer.azp, azp.getOrElse("None")), By(Consumer.sub, sub.getOrElse("None")))
} or {
aud.flatMap(consumerKey => Consumer.find(By(Consumer.key, consumerKey)))
}
// 1st try to find via UUID issued by OBP-API back end
Consumer.find(By(Consumer.consumerId, consumerId.getOrElse("None"))) or
// 2nd try to find via the pair (azp, iss) issued by External Identity Provider
{
// The azp field in the payload of a JWT (JSON Web Token) represents the Authorized Party.
// It is typically used in the context of OAuth 2.0 and OpenID Connect to identify the client application that the token is issued for.
// The pair (azp, iss) is a unique key in case of Client of an Identity Provider
Consumer.find(By(Consumer.azp, azp.getOrElse("None")), By(Consumer.iss, iss.getOrElse("None")))
}
consumer match {
case Full(c) => Full(c)
case Failure(msg, t, c) => Failure(msg, t, c)
Expand Down

0 comments on commit 6c703a4

Please sign in to comment.