mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 18:46:46 +00:00
Introuduced a new url parameter ?format=ISO20022 for New Style Endpoints
This commit is contained in:
parent
ab9d1c414e
commit
e8394cafbd
@ -552,8 +552,10 @@ object APIUtil extends MdcLoggable {
|
||||
def createdJsonResponse(json: JsExp, httpCode : Int = 201)(implicit headers: CustomResponseHeaders = CustomResponseHeaders(Nil)) : JsonResponse =
|
||||
JsonResponse(json, getHeaders() ::: headers.list, Nil, httpCode)
|
||||
|
||||
def successJsonResponseFromCaseClass(cc: Any, httpCode : Int = 200)(implicit headers: CustomResponseHeaders = CustomResponseHeaders(Nil)) : JsonResponse =
|
||||
JsonResponse(snakify(Extraction.decompose(cc)), getHeaders() ::: headers.list, Nil, httpCode)
|
||||
def successJsonResponseFromCaseClass(cc: Any, sc: Option[SessionContext], httpCode : Int = 200)(implicit headers: CustomResponseHeaders = CustomResponseHeaders(Nil)) : JsonResponse = {
|
||||
val jsonAst = ApiSession.processJson(snakify(Extraction.decompose(cc)), sc)
|
||||
JsonResponse(jsonAst, getHeaders() ::: headers.list, Nil, httpCode)
|
||||
}
|
||||
|
||||
def acceptedJsonResponse(json: JsExp, httpCode : Int = 202)(implicit headers: CustomResponseHeaders = CustomResponseHeaders(Nil)) : JsonResponse =
|
||||
JsonResponse(json, getHeaders() ::: headers.list, Nil, httpCode)
|
||||
@ -1724,7 +1726,7 @@ Versions are groups of endpoints in a file
|
||||
*/
|
||||
def futureToResponse[T](in: LAFuture[(T, Option[SessionContext])]): JsonResponse = {
|
||||
RestContinuation.async(reply => {
|
||||
in.onSuccess(t => reply.apply(successJsonResponseFromCaseClass(t._1)(getGatewayLoginHeader(t._2))))
|
||||
in.onSuccess(t => reply.apply(successJsonResponseFromCaseClass(cc = t._1, t._2)(getGatewayLoginHeader(t._2))))
|
||||
in.onFail {
|
||||
case Failure(msg, _, _) => reply.apply(errorJsonResponse(msg))
|
||||
case _ => reply.apply(errorJsonResponse("Error"))
|
||||
@ -1753,7 +1755,7 @@ Versions are groups of endpoints in a file
|
||||
*/
|
||||
def futureToBoxedResponse[T](in: LAFuture[(T, Option[SessionContext])]): Box[JsonResponse] = {
|
||||
RestContinuation.async(reply => {
|
||||
in.onSuccess(t => Full(reply.apply(successJsonResponseFromCaseClass(t._1)(getGatewayLoginHeader(t._2)))))
|
||||
in.onSuccess(t => Full(reply.apply(successJsonResponseFromCaseClass(t._1, t._2)(getGatewayLoginHeader(t._2)))))
|
||||
in.onFail {
|
||||
case Failure(msg, _, _) => Full(reply.apply(errorJsonResponse(msg)))
|
||||
case _ => Full(reply.apply(errorJsonResponse("Error")))
|
||||
@ -1797,6 +1799,9 @@ Versions are groups of endpoints in a file
|
||||
* @return An User wrapped into a Future
|
||||
*/
|
||||
def getUserFromAuthorizationHeaderFuture(): Future[(Box[User], Option[SessionContext])] = {
|
||||
val s = S
|
||||
val format = s.param("format")
|
||||
val res =
|
||||
if (hasAnOAuthHeader) {
|
||||
getUserFromOAuthHeaderFuture()
|
||||
} else if (Props.getBool("allow_direct_login", true) && hasDirectLoginHeader) {
|
||||
@ -1804,7 +1809,6 @@ Versions are groups of endpoints in a file
|
||||
} else if (Props.getBool("allow_gateway_login", false) && hasGatewayHeader) {
|
||||
Props.get("gateway.host") match {
|
||||
case Full(h) if h.split(",").toList.exists(_.equalsIgnoreCase(getRemoteIpAddress()) == true) => // Only addresses from white list can use this feature
|
||||
val s = S
|
||||
val (httpCode, message, parameters) = GatewayLogin.validator(s.request)
|
||||
httpCode match {
|
||||
case 200 =>
|
||||
@ -1844,6 +1848,9 @@ Versions are groups of endpoints in a file
|
||||
} else {
|
||||
Future { (Empty, None) }
|
||||
}
|
||||
res map {
|
||||
x => (x._1, ApiSession.updateSessionContext(FormatOfSpelling(format), x._2))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,19 +1,34 @@
|
||||
package code.api.util
|
||||
|
||||
import code.api.JSONFactoryGateway.PayloadOfJwtJSON
|
||||
import code.api.util.APIUtil.{useISO20022Spelling, useOBPSpelling}
|
||||
import net.liftweb.common.Box
|
||||
import net.liftweb.json.JsonAST.JValue
|
||||
|
||||
case class SessionContext(
|
||||
gatewayLoginRequestPayload: Option[PayloadOfJwtJSON],
|
||||
gatewayLoginResponseHeader: Option[String]
|
||||
gatewayLoginResponseHeader: Option[String],
|
||||
formatOfSpelling: Option[String]
|
||||
)
|
||||
trait GatewayLoginParam
|
||||
case class GatewayLoginRequestPayload(jwtPayload: Option[PayloadOfJwtJSON]) extends GatewayLoginParam
|
||||
case class GatewayLoginResponseHeader(jwt: Option[String]) extends GatewayLoginParam
|
||||
|
||||
case class FormatOfSpelling(formatOfSpelling: Box[String])
|
||||
|
||||
object ApiSession {
|
||||
|
||||
val emptyPayloadOfJwt = PayloadOfJwtJSON(login_user_name = "", is_first = true, app_id = "", app_name = "", cbs_id = "", time_stamp = "", cbs_token = None)
|
||||
|
||||
def updateSessionContext(fos: FormatOfSpelling, cnt: Option[SessionContext]): Option[SessionContext] = {
|
||||
cnt match {
|
||||
case None =>
|
||||
Some(SessionContext(gatewayLoginRequestPayload = None, gatewayLoginResponseHeader = None, formatOfSpelling = fos.formatOfSpelling))
|
||||
case Some(v) =>
|
||||
Some(v.copy(formatOfSpelling = fos.formatOfSpelling))
|
||||
}
|
||||
}
|
||||
|
||||
def updateSessionContext(jwt: GatewayLoginParam, cnt: Option[SessionContext]): Option[SessionContext] = {
|
||||
jwt match {
|
||||
case GatewayLoginRequestPayload(None) =>
|
||||
@ -25,14 +40,14 @@ object ApiSession {
|
||||
case Some(v) =>
|
||||
Some(v.copy(Some(jwtPayload)))
|
||||
case None =>
|
||||
Some(SessionContext(gatewayLoginRequestPayload = Some(jwtPayload), gatewayLoginResponseHeader = None))
|
||||
Some(SessionContext(gatewayLoginRequestPayload = Some(jwtPayload), gatewayLoginResponseHeader = None, formatOfSpelling = None))
|
||||
}
|
||||
case GatewayLoginResponseHeader(Some(j)) =>
|
||||
cnt match {
|
||||
case Some(v) =>
|
||||
Some(v.copy(gatewayLoginResponseHeader = Some(j)))
|
||||
case None =>
|
||||
Some(SessionContext(gatewayLoginRequestPayload = None, gatewayLoginResponseHeader = Some(j)))
|
||||
Some(SessionContext(gatewayLoginRequestPayload = None, gatewayLoginResponseHeader = Some(j), formatOfSpelling = None))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,4 +66,20 @@ object ApiSession {
|
||||
}
|
||||
}
|
||||
|
||||
def processJson(j: JValue, cnt: Option[SessionContext]): JValue = {
|
||||
cnt match {
|
||||
case Some(v) =>
|
||||
v.formatOfSpelling match {
|
||||
case Some(s) if s == "ISO20022" =>
|
||||
useISO20022Spelling(j)
|
||||
case Some(s) if s == "OBP" =>
|
||||
useOBPSpelling(j)
|
||||
case None =>
|
||||
j
|
||||
}
|
||||
case None =>
|
||||
j
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -705,7 +705,7 @@ trait APIMethods300 {
|
||||
ai: InboundAdapterInfoInternal <- Connector.connector.vend.getAdapterInfo() ?~ "Not implemented"
|
||||
}
|
||||
yield {
|
||||
successJsonResponseFromCaseClass(createAdapterInfoJson(ai))
|
||||
successJsonResponseFromCaseClass(createAdapterInfoJson(ai), None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user