mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:37:00 +00:00
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
68d1826465
@ -1648,7 +1648,7 @@ object SwaggerDefinitionsJSON {
|
||||
|
||||
val createEntitlementJSON = CreateEntitlementJSON(
|
||||
bank_id = bankIdExample.value,
|
||||
role_name = "String"
|
||||
role_name = CanCreateBranch.toString()
|
||||
)
|
||||
|
||||
val coreCounterpartyJSON = CoreCounterpartyJSON(
|
||||
|
||||
@ -1998,7 +1998,9 @@ trait APIMethods200 {
|
||||
allowedEntitlements = canCreateEntitlementAtOneBank ::
|
||||
canCreateEntitlementAtAnyBank ::
|
||||
Nil
|
||||
_ <- booleanToBox(isSuperAdmin(u.userId) || hasAtLeastOneEntitlement(postedData.bank_id, u.userId, allowedEntitlements) == true) ?~! { UserNotSuperAdminOrMissRole + allowedEntitlements.mkString(", ") + "!" }
|
||||
_ <- booleanToBox(isSuperAdmin(u.userId) || hasAtLeastOneEntitlement(postedData.bank_id, u.userId, allowedEntitlements) == true) ?~! {
|
||||
UserNotSuperAdmin +" or" + UserHasMissingRoles + canCreateEntitlementAtOneBank + s" BankId(${postedData.bank_id})." + " or" + UserHasMissingRoles + canCreateEntitlementAtAnyBank
|
||||
}
|
||||
_ <- booleanToBox(postedData.bank_id.nonEmpty == false || BankX(BankId(postedData.bank_id), Some(cc)).map(_._1).isEmpty == false) ?~! BankNotFound
|
||||
_ <- booleanToBox(hasEntitlement(postedData.bank_id, userId, role) == false, EntitlementAlreadyExists )
|
||||
addedEntitlement <- Entitlement.entitlement.vend.addEntitlement(postedData.bank_id, userId, postedData.role_name)
|
||||
@ -2043,7 +2045,7 @@ trait APIMethods200 {
|
||||
// Format the data as V2.0.0 json
|
||||
if (isSuperAdmin(userId)) {
|
||||
// If the user is SuperAdmin add it to the list
|
||||
json = EntitlementJSONs(JSONFactory200.createEntitlementJSONs(entitlements).list:::List(EntitlementJSON("", "SuperAdmin", "")))
|
||||
json = addedSuperAdminEntitlementJson(entitlements)
|
||||
successJsonResponse(Extraction.decompose(json))
|
||||
} else {
|
||||
json = JSONFactory200.createEntitlementJSONs(entitlements)
|
||||
@ -2070,7 +2072,7 @@ trait APIMethods200 {
|
||||
""".stripMargin,
|
||||
emptyObjectJson,
|
||||
emptyObjectJson,
|
||||
List(UserNotLoggedIn, UserNotSuperAdmin, EntitlementNotFound, UnknownError),
|
||||
List(UserNotLoggedIn, UserHasMissingRoles, EntitlementNotFound, UnknownError),
|
||||
Catalogs(notCore, notPSD2, notOBWG),
|
||||
List(apiTagRole, apiTagUser, apiTagEntitlement))
|
||||
|
||||
@ -2080,7 +2082,7 @@ trait APIMethods200 {
|
||||
cc =>
|
||||
for {
|
||||
u <- cc.user ?~ ErrorMessages.UserNotLoggedIn
|
||||
_ <- booleanToBox(isSuperAdmin(u.userId)) ?~ UserNotSuperAdmin
|
||||
_ <- booleanToBox(hasEntitlement("", u.userId, canDeleteEntitlementAtAnyBank), UserHasMissingRoles + CanDeleteEntitlementAtAnyBank)
|
||||
entitlement <- tryo{Entitlement.entitlement.vend.getEntitlementById(entitlementId)} ?~ EntitlementNotFound
|
||||
_ <- entitlement.filter(_.userId == userId) ?~ UserDoesNotHaveEntitlement
|
||||
_ <- Entitlement.entitlement.vend.deleteEntitlement(entitlement)
|
||||
@ -2115,8 +2117,8 @@ trait APIMethods200 {
|
||||
cc =>
|
||||
for {
|
||||
(Full(u), callContext) <- authenticatedAccess(cc)
|
||||
_ <- Helper.booleanToFuture(failMsg = UserNotSuperAdmin) {
|
||||
isSuperAdmin(u.userId)
|
||||
_ <- Helper.booleanToFuture(failMsg = UserHasMissingRoles + CanGetEntitlementsForAnyUserAtAnyBank) {
|
||||
hasEntitlement("", u.userId, canGetEntitlementsForAnyUserAtAnyBank)
|
||||
}
|
||||
entitlements <- Entitlement.entitlement.vend.getEntitlementsFuture() map {
|
||||
connectorEmptyResponse(_, callContext)
|
||||
|
||||
@ -837,6 +837,10 @@ def createTransactionTypeJSON(transactionType : TransactionType) : TransactionTy
|
||||
))
|
||||
)))
|
||||
|
||||
def addedSuperAdminEntitlementJson(entitlements: List[Entitlement]) = {
|
||||
EntitlementJSONs(JSONFactory200.createEntitlementJSONs(entitlements).list ::: List(EntitlementJSON("", "SuperAdmin", "")))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -821,7 +821,7 @@ trait APIMethods210 {
|
||||
// Format the data as V2.1.0 json
|
||||
if (isSuperAdmin(userId)) {
|
||||
// If the user is SuperAdmin add it to the list
|
||||
json = EntitlementJSONs(JSONFactory200.createEntitlementJSONs(filteredEntitlements).list:::List(EntitlementJSON("", "SuperAdmin", "")))
|
||||
json = JSONFactory200.addedSuperAdminEntitlementJson(filteredEntitlements)
|
||||
successJsonResponse(Extraction.decompose(json))
|
||||
} else {
|
||||
json = JSONFactory200.createEntitlementJSONs(filteredEntitlements)
|
||||
|
||||
@ -1718,7 +1718,7 @@ trait APIMethods310 {
|
||||
""".stripMargin,
|
||||
emptyObjectJson,
|
||||
entitlementJSONs,
|
||||
List(UserNotLoggedIn, UserNotSuperAdmin, UnknownError),
|
||||
List(UserNotLoggedIn, UserHasMissingRoles, UnknownError),
|
||||
Catalogs(notCore, notPSD2, notOBWG),
|
||||
List(apiTagRole, apiTagEntitlement, apiTagNewStyle))
|
||||
|
||||
@ -1728,8 +1728,8 @@ trait APIMethods310 {
|
||||
cc =>
|
||||
for {
|
||||
(Full(u), callContext) <- authenticatedAccess(cc)
|
||||
_ <- Helper.booleanToFuture(failMsg = UserNotSuperAdmin) {
|
||||
isSuperAdmin(u.userId)
|
||||
_ <- Helper.booleanToFuture(failMsg = UserHasMissingRoles + CanGetEntitlementsForAnyUserAtAnyBank) {
|
||||
hasEntitlement("", u.userId, canGetEntitlementsForAnyUserAtAnyBank)
|
||||
}
|
||||
roleName = APIUtil.getHttpRequestUrlParam(cc.url, "role")
|
||||
entitlements <- Entitlement.entitlement.vend.getEntitlementsByRoleFuture(roleName) map {
|
||||
|
||||
@ -1326,7 +1326,7 @@ trait APIMethods400 {
|
||||
// Format the data as V2.0.0 json
|
||||
if (isSuperAdmin(userId)) {
|
||||
// If the user is SuperAdmin add it to the list
|
||||
json = EntitlementJSONs(JSONFactory200.createEntitlementJSONs(entitlements).list:::List(EntitlementJSON("", "SuperAdmin", "")))
|
||||
json = JSONFactory200.addedSuperAdminEntitlementJson(entitlements)
|
||||
} else {
|
||||
json = JSONFactory200.createEntitlementJSONs(entitlements)
|
||||
}
|
||||
@ -2778,8 +2778,8 @@ trait APIMethods400 {
|
||||
nameOf(createDynamicEndpoint),
|
||||
"POST",
|
||||
"/management/dynamic-endpoints",
|
||||
" Create DynamicEndpoint",
|
||||
s"""Create a DynamicEndpoint.
|
||||
" Create Dynamic Endpoint",
|
||||
s"""Create a Dynamic Endpoint.
|
||||
|
|
||||
|Create one DynamicEndpoint,
|
||||
|
|
||||
@ -2828,8 +2828,8 @@ trait APIMethods400 {
|
||||
nameOf(getDynamicEndpoint),
|
||||
"GET",
|
||||
"/management/dynamic-endpoints/DYNAMIC_ENDPOINT_ID",
|
||||
" Get DynamicEndpoint",
|
||||
s"""Get a DynamicEndpoint.
|
||||
" Get Dynamic Endpoint",
|
||||
s"""Get a Dynamic Endpoint.
|
||||
|
|
||||
|
|
||||
|Get one DynamicEndpoint,
|
||||
@ -2867,10 +2867,10 @@ trait APIMethods400 {
|
||||
nameOf(getDynamicEndpoints),
|
||||
"GET",
|
||||
"/management/dynamic-endpoints",
|
||||
" Get DynamicEndpoints",
|
||||
" Get Dynamic Endpoints",
|
||||
s"""
|
||||
|
|
||||
|Get DynamicEndpoints.
|
||||
|Get Dynamic Endpoints.
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
@ -2946,9 +2946,14 @@ trait APIMethods400 {
|
||||
(box, _) <- NewStyle.function.dynamicEndpointProcess(url, json, method, params, pathParams, callContext)
|
||||
} yield {
|
||||
box match {
|
||||
case Full(v) => (v, HttpCode.`200`(Some(cc)))
|
||||
case e: Failure => (e.messageChain, HttpCode.`200`(Some(cc))) // TODO code need change
|
||||
case _ => ("fail", HttpCode.`200`(Some(cc)))
|
||||
case Full(v) =>
|
||||
val code = (v \ "code").asInstanceOf[JInt].num.toInt
|
||||
(v \ "value", callContext.map(_.copy(httpCode = Some(code))))
|
||||
|
||||
case e: Failure =>
|
||||
val changedMsgFailure = e.copy(msg = s"$InternalServerError ${e.msg}")
|
||||
fullBoxOrException[JValue](changedMsgFailure)
|
||||
??? // will not execute to here, Because the failure message is thrown by upper line.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ object DynamicEndpointHelper extends RestHelper {
|
||||
private val ExpressionRegx = """\{(.+?)\}""".r
|
||||
/**
|
||||
* unapply Request to (request url, json, http method, request parameters, path parameters, role)
|
||||
* request url is current request url
|
||||
* request url is current request target url to remote server
|
||||
* json is request body
|
||||
* http method is request http method
|
||||
* request parameters is http request parameters
|
||||
@ -220,7 +220,6 @@ object DynamicEndpointHelper extends RestHelper {
|
||||
ApiRole.getOrCreateDynamicApiRole(roleName)
|
||||
))
|
||||
}
|
||||
val connectorMethods = Some(List("dynamicEndpointProcess"))
|
||||
val doc = ResourceDoc(
|
||||
partialFunction,
|
||||
implementedInApiVersion,
|
||||
@ -234,8 +233,7 @@ object DynamicEndpointHelper extends RestHelper {
|
||||
errorResponseBodies,
|
||||
catalogs,
|
||||
tags,
|
||||
roles,
|
||||
connectorMethods = connectorMethods
|
||||
roles
|
||||
)
|
||||
(doc, path)
|
||||
}
|
||||
|
||||
@ -104,10 +104,16 @@ package object bankconnectors extends MdcLoggable {
|
||||
NewStyle.function.getMethodRoutings(Some(methodName))
|
||||
.find(routing => {
|
||||
routing.parameters.exists(it => it.key == "http_method" && it.value.equalsIgnoreCase(method.value)) &&
|
||||
routing.parameters.exists(it => it.key == "url")&&
|
||||
routing.parameters.exists(it => it.key == "url") &&
|
||||
routing.parameters.exists(
|
||||
it => it.key == "url_pattern" &&
|
||||
(it.value == url || Pattern.compile(it.value).matcher(url).matches())
|
||||
it => {
|
||||
val value = it.value
|
||||
it.key == "url_pattern" && // url_pattern is equals with current target url to remote server or as regex match
|
||||
(value == url || {
|
||||
val regexStr = value.replaceAll("""\{[^/]+?\}""", "[^/]+?")
|
||||
Pattern.compile(regexStr).matcher(url).matches()
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -58,12 +58,14 @@ import code.api.util.APIUtil._
|
||||
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA
|
||||
import code.customer.internalMapping.MappedCustomerIdMappingProvider
|
||||
import code.model.dataAccess.internalMapping.MappedAccountIdMappingProvider
|
||||
import code.util.{Helper, JsonUtils}
|
||||
import code.util.JsonUtils
|
||||
import com.openbankproject.commons.model.enums.{AccountAttributeType, CardAttributeType, DynamicEntityOperation, ProductAttributeType}
|
||||
import com.openbankproject.commons.util.{ReflectUtils, RequiredFieldValidation}
|
||||
import com.openbankproject.commons.util.ReflectUtils
|
||||
import net.liftweb.json
|
||||
import net.liftweb.json.{JValue, _}
|
||||
import net.liftweb.json.JsonDSL._
|
||||
import net.liftweb.json.Extraction.decompose
|
||||
import net.liftweb.json.JsonParser.ParseException
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
|
||||
trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable {
|
||||
@ -9382,21 +9384,34 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
|
||||
case (status, entity) if status.isSuccess() =>
|
||||
this.extractBody(entity)
|
||||
.map{
|
||||
case v if StringUtils.isBlank(v) => (Empty, callContext)
|
||||
case v => (Full(json.parse(v)), callContext)
|
||||
case v if StringUtils.isBlank(v) =>
|
||||
(Full{
|
||||
("code", status.intValue()) ~ ("value", JString(""))
|
||||
}, callContext)
|
||||
case v =>
|
||||
(Full{
|
||||
("code", status.intValue()) ~ ("value", json.parse(v))
|
||||
}, callContext)
|
||||
}
|
||||
case (status, entity) => {
|
||||
val future: Future[Box[Box[JValue]]] = extractBody(entity) map { msg =>
|
||||
tryo {
|
||||
val failure: Box[JValue] = ParamFailure(msg, APIFailureNewStyle(msg, status.intValue()))
|
||||
failure
|
||||
} ~> APIFailureNewStyle(msg, status.intValue())
|
||||
val future: Future[JObject] = extractBody(entity) map { msg =>
|
||||
try {
|
||||
("code", status.intValue()) ~ ("value", json.parse(msg))
|
||||
} catch {
|
||||
case _: ParseException => ("code", status.intValue()) ~ ("value", JString(msg))
|
||||
}
|
||||
}
|
||||
future.map{
|
||||
case Full(v) => (v, callContext)
|
||||
case e: EmptyBox => (e, callContext)
|
||||
future.map { jObject =>
|
||||
(Full(jObject), callContext)
|
||||
}
|
||||
}
|
||||
}.recoverWith {
|
||||
case e: Exception if e.getMessage.contains(s"$httpRequestTimeout seconds") =>
|
||||
Future.failed(
|
||||
new Exception(s"$AdapterTimeOurError Please Check Adapter Side, the response should be returned to OBP-Side in $httpRequestTimeout seconds. Details: ${e.getMessage}", e)
|
||||
)
|
||||
case e: Exception =>
|
||||
Future.failed(new Exception(s"$AdapterUnknownError Please Check Adapter Side! Details: ${e.getMessage}", e))
|
||||
}
|
||||
|
||||
result
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package code.api.v2_0_0
|
||||
|
||||
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
|
||||
import com.openbankproject.commons.model.ErrorMessage
|
||||
import code.api.util.APIUtil.OAuth._
|
||||
import code.api.util.ApiRole.CanGetEntitlementsForAnyUserAtAnyBank
|
||||
@ -7,6 +8,7 @@ import code.api.util.ErrorMessages.{UserHasMissingRoles, _}
|
||||
import code.api.util.{ApiRole, ErrorMessages}
|
||||
import code.entitlement.Entitlement
|
||||
import code.setup.DefaultUsers
|
||||
import net.liftweb.json.Serialization.write
|
||||
|
||||
class EntitlementTests extends V200ServerSetup with DefaultUsers {
|
||||
|
||||
@ -31,7 +33,7 @@ class EntitlementTests extends V200ServerSetup with DefaultUsers {
|
||||
|
||||
}
|
||||
|
||||
scenario("We try to get entitlements without credentials - getEntitlements") {
|
||||
scenario("We try to get entitlements without roles - getEntitlements") {
|
||||
When("We make the request")
|
||||
val requestGet = (v2_0Request / "users" / resourceUser1.userId / "entitlements").GET <@ (user1)
|
||||
val responseGet = makeGetRequest(requestGet)
|
||||
@ -41,7 +43,7 @@ class EntitlementTests extends V200ServerSetup with DefaultUsers {
|
||||
responseGet.body.extract[ErrorMessage].message should equal (UserHasMissingRoles + CanGetEntitlementsForAnyUserAtAnyBank)
|
||||
}
|
||||
|
||||
scenario("We try to get entitlements with credentials - getEntitlements") {
|
||||
scenario("We try to get entitlements with roles - getEntitlements") {
|
||||
When("We add required entitlement")
|
||||
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.CanGetEntitlementsForAnyUserAtAnyBank.toString)
|
||||
And("We make the request")
|
||||
@ -51,16 +53,70 @@ class EntitlementTests extends V200ServerSetup with DefaultUsers {
|
||||
responseGet.code should equal(200)
|
||||
}
|
||||
|
||||
scenario("We try to delete some entitlement as a super admin - deleteEntitlement") {
|
||||
scenario("We try to delete some entitlement - deleteEntitlement") {
|
||||
When("We add required entitlement")
|
||||
val ent = Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.CanGetAnyUser.toString).openOrThrowException(attemptedToOpenAnEmptyBox)
|
||||
And("We make the request")
|
||||
val requestDelete = (v2_0Request / "users" / resourceUser1.userId / "entitlement" / ent.entitlementId).DELETE <@ (user1)
|
||||
And("We grant the role to the user")
|
||||
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.canDeleteEntitlementAtAnyBank.toString)
|
||||
val responseDelete = makeDeleteRequest(requestDelete)
|
||||
Then("We should get a 400")
|
||||
responseDelete.code should equal(400)
|
||||
And("We should get a message: " + ErrorMessages.UserNotSuperAdmin)
|
||||
responseDelete.body.extract[ErrorMessage].message should equal (ErrorMessages.UserNotSuperAdmin)
|
||||
Then("We should get a 204")
|
||||
responseDelete.code should equal(204)
|
||||
}
|
||||
|
||||
scenario("We try to create entitlement - addEntitlement-canCreateEntitlementAtOneBank") {
|
||||
val requestBody = SwaggerDefinitionsJSON.createEntitlementJSON
|
||||
And("We make the request")
|
||||
val requestPost = (v2_0Request / "users" / resourceUser1.userId / "entitlements").POST <@ (user1)
|
||||
And("We grant the role to the user")
|
||||
val responsePost = makePostRequest(requestPost , write(requestBody))
|
||||
|
||||
Then("We should get a 403")
|
||||
responsePost.code should equal(403)
|
||||
responsePost.body.toString contains (UserHasMissingRoles) should be (true)
|
||||
|
||||
Then("We grant the canCreateEntitlementAtOneBank role")
|
||||
Entitlement.entitlement.vend.addEntitlement(testBankId1.value, resourceUser1.userId, ApiRole.canCreateEntitlementAtOneBank.toString)
|
||||
|
||||
Then("We call addEntitlement with canCreateEntitlementAtOneBank, but wrong bankId .")
|
||||
val responsePost2 = makePostRequest(requestPost , write(requestBody))
|
||||
responsePost2.code should equal(403)
|
||||
|
||||
Then("We call addEntitlement with canCreateEntitlementAtOneBank.")
|
||||
val requestBody2 = SwaggerDefinitionsJSON.createEntitlementJSON.copy(bank_id = testBankId1.value)
|
||||
val responsePost3 = makePostRequest(requestPost , write(requestBody2))
|
||||
|
||||
Then("We should get a 201")
|
||||
responsePost3.code should equal(201)
|
||||
responsePost3.body.extract[EntitlementJSON].bank_id should equal(testBankId1.value)
|
||||
}
|
||||
|
||||
scenario("We try to create entitlement - addEntitlement-canCreateEntitlementAtAnyBank") {
|
||||
val requestBody = SwaggerDefinitionsJSON.createEntitlementJSON.copy(bank_id = testBankId1.value)
|
||||
And("We make the request")
|
||||
val requestPost = (v2_0Request / "users" / resourceUser1.userId / "entitlements").POST <@ (user1)
|
||||
And("We grant the role to the user")
|
||||
val responsePost = makePostRequest(requestPost , write(requestBody))
|
||||
|
||||
Then("We should get a 403")
|
||||
responsePost.code should equal(403)
|
||||
responsePost.body.toString contains (UserHasMissingRoles) should be (true)
|
||||
|
||||
Then("We grant the canCreateEntitlementAtOneBank role")
|
||||
Entitlement.entitlement.vend.addEntitlement("wrongbankId", resourceUser1.userId, ApiRole.canCreateEntitlementAtOneBank.toString)
|
||||
|
||||
Then("We call addEntitlement with canCreateEntitlementAtOneBank, but wrong bankId .")
|
||||
val responsePost2 = makePostRequest(requestPost , write(requestBody))
|
||||
responsePost2.code should equal(403)
|
||||
|
||||
Then("We call addEntitlement with canCreateEntitlementAtOneBank, but correct bankId .")
|
||||
Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, ApiRole.canCreateEntitlementAtAnyBank.toString)
|
||||
val responsePost3 = makePostRequest(requestPost , write(requestBody))
|
||||
|
||||
Then("We should get a 201")
|
||||
responsePost3.code should equal(201)
|
||||
responsePost3.body.extract[EntitlementJSON].bank_id should equal(testBankId1.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user