diff --git a/obp-api/src/main/resources/props/sample.props.template b/obp-api/src/main/resources/props/sample.props.template index 54b915f8e..435c3246c 100644 --- a/obp-api/src/main/resources/props/sample.props.template +++ b/obp-api/src/main/resources/props/sample.props.template @@ -559,4 +559,10 @@ featured_apis=elasticSearchWarehouseV300 # Database scheduler interval in seconds. # Scheduler would not be started if delay is not set. database_messages_scheduler_interval=3600 -# --------------------------------------------------- \ No newline at end of file +# --------------------------------------------------- + +# -- Consents ----------------------------------------------- +# In case isn't defined default value is "false" +# consents.allowed=true +# consents.jwt_secret=Cannot get your at least 256 bit secret +# ----------------------------------------------------------- \ No newline at end of file diff --git a/obp-api/src/main/scala/code/api/util/ConsentUtil.scala b/obp-api/src/main/scala/code/api/util/ConsentUtil.scala index bbaad71ca..cc52b3239 100644 --- a/obp-api/src/main/scala/code/api/util/ConsentUtil.scala +++ b/obp-api/src/main/scala/code/api/util/ConsentUtil.scala @@ -1,5 +1,6 @@ package code.api.util +import code.api.util.ErrorMessages.attemptedToOpenAnEmptyBox import code.consumer.Consumers import code.entitlement.Entitlement import code.users.Users @@ -84,7 +85,7 @@ case class Consent(createdByUserId: String, object Consent { private def verifyHmacSignedJwt(jwtToken: String): Boolean = { - val secret = APIUtil.getPropsValue("consent.jwt_secret", "Cannot get your at least 256 bit secret") + val secret = APIUtil.getPropsValue("consents.jwt_secret").openOrThrowException(attemptedToOpenAnEmptyBox) JwtUtil.verifyHmacSignedJwt(jwtToken, secret) } @@ -225,9 +226,11 @@ object Consent { } def applyRules(consentId: Option[String], callContext: Option[CallContext]): Future[(Box[User], Option[CallContext])] = { - consentId match { - case Some(consentId) => hasConsent(consentId, callContext) - case None => Future((Failure("Cannot get Consent-Id"), callContext)) + val allowed = APIUtil.getPropsAsBoolValue(nameOfProperty="consents.allowed", defaultValue=false) + (consentId, allowed) match { + case (Some(consentId), true) => hasConsent(consentId, callContext) + case (_, false) => Future((Failure("Consents are not allowed at this instance."), callContext)) + case (None, _) => Future((Failure("Cannot get Consent-Id"), callContext)) } }