Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/code/api/util/ApiSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class CallContext(
dauthResponseHeader: Option[String] = None,
spelling: Option[String] = None,
user: Box[User] = Empty,
onBehalfOfUser: Option[User] = None,
onBehalfOfUser: Box[User] = Empty,
consenter: Box[User] = Empty,
consumer: Box[Consumer] = Empty,
ipAddress: String = "",
Expand Down
53 changes: 29 additions & 24 deletions obp-api/src/main/scala/code/api/util/ConsentUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -431,33 +431,38 @@ object Consent extends MdcLoggable {

def applyConsentRules(consent: ConsentJWT): Future[(Box[User], Option[CallContext])] = {
val cc = callContext
if(consent.createdByUserId.nonEmpty) {
if(consent.createdByUserId.nonEmpty) { // Populate on behalf of user in case of OBP Consent
val onBehalfOfUser = Users.users.vend.getUserByUserId(consent.createdByUserId)
cc.copy(onBehalfOfUser = onBehalfOfUser.toOption)
}
// 1. Get or Create a User
getOrCreateUser(consent.sub, consent.iss, Some(consent.jti), None, None) map {
case (Full(user), newUser) =>
// 2. Assign entitlements to the User
addEntitlements(user, consent) match {
case (Full(user)) =>
// 3. Copy Auth Context to the User
copyAuthContextOfConsentToUser(consent.jti, user.userId, newUser) match {
case Full(_) =>
// 4. Assign views to the User
(grantAccessToViews(user, consent), Some(cc))
case failure@Failure(_, _, _) => // Handled errors
(failure, Some(callContext))
case _ =>
(Failure(ErrorMessages.UnknownError), Some(cc))
}
case failure@Failure(msg, exp, chain) => // Handled errors
(Failure(msg), Some(cc))
case _ =>
(Failure(CannotAddEntitlement + consentAsJwt), Some(cc))
}
case _ =>
(Failure(CannotGetOrCreateUser + consentAsJwt), Some(cc))
if (cc.onBehalfOfUser.nonEmpty &&
APIUtil.getPropsAsBoolValue(nameOfProperty = "experimental_become_user_that_created_consent", defaultValue = false)) {
Future(cc.onBehalfOfUser, Some(cc)) // Just propagate on behalf of user back
} else {
// 1. Get or Create a User
getOrCreateUser(consent.sub, consent.iss, Some(consent.jti), None, None) map {
case (Full(user), newUser) =>
// 2. Assign entitlements to the User
addEntitlements(user, consent) match {
case (Full(user)) =>
// 3. Copy Auth Context to the User
copyAuthContextOfConsentToUser(consent.jti, user.userId, newUser) match {
case Full(_) =>
// 4. Assign views to the User
(grantAccessToViews(user, consent), Some(cc))
case failure@Failure(_, _, _) => // Handled errors
(failure, Some(callContext))
case _ =>
(Failure(ErrorMessages.UnknownError), Some(cc))
}
case failure@Failure(msg, exp, chain) => // Handled errors
(Failure(msg), Some(cc))
case _ =>
(Failure(CannotAddEntitlement + consentAsJwt), Some(cc))
}
case _ =>
(Failure(CannotGetOrCreateUser + consentAsJwt), Some(cc))
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions obp-api/src/main/scala/code/api/v6_0_0/APIMethods600.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ trait APIMethods600 {
val permissions: Option[Permission] = Views.views.vend.getPermissionForUser(u).toOption
val currentUser = UserV600(u, entitlements, permissions)
val onBehalfOfUser = if(cc.onBehalfOfUser.isDefined) {
val entitlements = Entitlement.entitlement.vend.getEntitlementsByUserId(cc.onBehalfOfUser.get.userId).headOption.toList.flatten
val permissions: Option[Permission] = Views.views.vend.getPermissionForUser(cc.onBehalfOfUser.get).toOption
Some(UserV600(cc.onBehalfOfUser.get, entitlements, permissions))
val user = cc.onBehalfOfUser.toOption.get
val entitlements = Entitlement.entitlement.vend.getEntitlementsByUserId(user.userId).headOption.toList.flatten
val permissions: Option[Permission] = Views.views.vend.getPermissionForUser(user).toOption
Some(UserV600(user, entitlements, permissions))
} else {
None
}
Expand Down