From 837c8137c1b0d28acd5ecd7422e9b19dea4555d1 Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 24 Mar 2021 22:45:38 +0100 Subject: [PATCH] bugfix/tweaked the createOrUpdateUserAuthContexts for external users --- .../scala/code/model/dataAccess/AuthUser.scala | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala index d7a8c6cfe..4b2552455 100644 --- a/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala +++ b/obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala @@ -28,7 +28,7 @@ package code.model.dataAccess import code.UserRefreshes.UserRefreshes import code.accountholders.AccountHolders -import code.api.util.APIUtil.{hasAnOAuthHeader, isValidStrongPassword, _} +import code.api.util.APIUtil.{hasAnOAuthHeader, isValidStrongPassword, logger, _} import code.api.util.ErrorMessages._ import code.api.util._ import code.api.{APIFailure, DirectLogin, GatewayLogin, OAuthHandshake} @@ -864,7 +864,17 @@ import net.liftweb.util.Helpers._ // TODO add field stating external password check only. .provider(iss) .validated(emailVerified.exists(_.equalsIgnoreCase("true"))) - .saveMe() + .saveMe() //NOTE, we will create the resourceUser in the `saveMe()` method. + } + userAuthContexts match { + case Some(authContexts) => { // Write user auth context to the database + // get resourceUserId from AuthUser. + val resourceUserId = user.user.foreign.map(_.userId).getOrElse("") + // we try to catch this exception, the createOrUpdateUserAuthContexts can not break the login process. + tryo {UserAuthContextProvider.userAuthContextProvider.vend.createOrUpdateUserAuthContexts(resourceUserId, authContexts)} + .openOr(logger.error(s"${resourceUserId} checkExternalUserViaConnector.createOrUpdateUserAuthContexts throw exception! ")) + } + case None => // Do nothing } Full(user) case _ =>