mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 09:26:53 +00:00
bugfix/endpoint_show_wrong_dependent_connector_methods: createTransactionRequest have multiple ResourceDoc, they did not show auto validate logic called connector methods.
This commit is contained in:
parent
7ecc3c6a1c
commit
fe02a423e2
4
FAQ.md
4
FAQ.md
@ -51,9 +51,7 @@ getAllowedEndpoints(endpointsOf3_0_0, Implementations3_0_0.resourceDocs)
|
||||
|
||||
4) Once we have a final list of routes we serve them:
|
||||
|
||||
routes.foreach(route => {
|
||||
oauthServe(apiPrefix{route}, findResourceDoc(route))
|
||||
})
|
||||
`registerRoutes(routes, allResourceDocs, apiPrefix, autoValidateAll = true)`
|
||||
|
||||
|
||||
|
||||
|
||||
@ -474,26 +474,33 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
|
||||
result
|
||||
}
|
||||
|
||||
protected def findResourceDoc(pf: OBPEndpoint, allResourceDocs: ArrayBuffer[ResourceDoc]): Option[ResourceDoc] = {
|
||||
allResourceDocs.find(_.partialFunction == pf)
|
||||
}
|
||||
|
||||
protected def registerRoutes(routes: List[OBPEndpoint],
|
||||
allResourceDocs: ArrayBuffer[ResourceDoc],
|
||||
apiPrefix:OBPEndpoint => OBPEndpoint,
|
||||
autoValidateAll: Boolean = false): Unit = {
|
||||
routes.foreach(route => {
|
||||
val maybeResourceDoc = findResourceDoc(route, allResourceDocs)
|
||||
val isAutoValidate = maybeResourceDoc.map { doc =>
|
||||
doc.isValidateEnabled || (autoValidateAll && !doc.isValidateDisabled && doc.implementedInApiVersion == version)
|
||||
}.getOrElse(false)
|
||||
|
||||
// if rd contains ResourceDoc, when autoValidateAll or doc isAutoValidate, just wrapped to auth check endpoint
|
||||
val authCheckRoute: OBPEndpoint = (maybeResourceDoc, isAutoValidate) match {
|
||||
case (Some(doc), true) => doc.wrappedWithAuthCheck(route)
|
||||
case _ => route
|
||||
def isAutoValidate(doc: ResourceDoc): Boolean =
|
||||
doc.isValidateEnabled || (autoValidateAll && !doc.isValidateDisabled && doc.implementedInApiVersion == version)
|
||||
|
||||
for(route <- routes) {
|
||||
// one endpoint can have multiple ResourceDocs, so here use filter instead of find, e.g APIMethods400.Implementations400.createTransactionRequest
|
||||
val resourceDocs = allResourceDocs.filter(_.partialFunction == route)
|
||||
|
||||
if(resourceDocs.isEmpty) {
|
||||
oauthServe(apiPrefix(route), None)
|
||||
} else {
|
||||
val (autoValidateDocs, other) = resourceDocs.partition(isAutoValidate)
|
||||
// autoValidateAll or doc isAutoValidate, just wrapped to auth check endpoint
|
||||
autoValidateDocs.foreach { doc =>
|
||||
val wrappedEndpoint = doc.wrappedWithAuthCheck(route)
|
||||
oauthServe(apiPrefix(wrappedEndpoint), Some(doc))
|
||||
}
|
||||
//just register once for those not auto validate endpoints .
|
||||
if (other.nonEmpty) {
|
||||
oauthServe(apiPrefix(route), other.headOption)
|
||||
}
|
||||
}
|
||||
oauthServe(apiPrefix(authCheckRoute), maybeResourceDoc)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1373,25 +1373,25 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
|
||||
}
|
||||
// reset connectorMethods
|
||||
{
|
||||
val checkerClassNames = mutable.ListBuffer[String]()
|
||||
val checkerFunctions = mutable.ListBuffer[PartialFunction[_, _]]()
|
||||
if (isNeedCheckAuth) {
|
||||
checkerClassNames += authenticatedAccessFun.getClass.getName
|
||||
checkerFunctions += authenticatedAccessFun
|
||||
} else {
|
||||
checkerClassNames += anonymousAccessFun.getClass.getName
|
||||
checkerFunctions += anonymousAccessFun
|
||||
}
|
||||
if (isNeedCheckRoles) {
|
||||
checkerClassNames += checkRolesFun.getClass.getName
|
||||
checkerFunctions += checkRolesFun
|
||||
}
|
||||
if (isNeedCheckBank) {
|
||||
checkerClassNames += checkBankFun.getClass.getName
|
||||
checkerFunctions += checkBankFun
|
||||
}
|
||||
if (isNeedCheckAccount) {
|
||||
checkerClassNames += checkAccountFun.getClass.getName
|
||||
checkerFunctions += checkAccountFun
|
||||
}
|
||||
if (isNeedCheckView) {
|
||||
checkerClassNames += checkViewFun.getClass.getName
|
||||
checkerFunctions += checkViewFun
|
||||
}
|
||||
val addedMethods: List[String] = checkerClassNames.toList.flatMap(getDependentConnectorMethods(_)).map("obp." +)
|
||||
val addedMethods: List[String] = checkerFunctions.toList.flatMap(getDependentConnectorMethods(_)).map("obp." +)
|
||||
|
||||
// add connector method to endpoint info
|
||||
addEndpointInfos(addedMethods, partialFunctionName, implementedInApiVersion)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user