refactor/removed getUser and updateUserAccountViewsOld methods

This commit is contained in:
Hongwei 2024-10-17 08:35:29 +02:00
parent d00aa8bd82
commit 7c87aa61f4
7 changed files with 14 additions and 228 deletions

View File

@ -523,15 +523,6 @@ trait Connector extends MdcLoggable {
Failure(setUnimplementedError(nameOf(getBankAccountsForUser _)))
}
/**
* This method is for get User from external, eg kafka/obpjvm...
* getUserId --> externalUserHelper--> getUserFromConnector --> getUser
* @param name
* @param password
* @return
*/
def getUser(name: String, password: String): Box[InboundUser]= Failure(setUnimplementedError(nameOf(getUser _)))
/**
* This method is for checking external User via connector
* @param username
@ -547,16 +538,6 @@ trait Connector extends MdcLoggable {
*/
def checkExternalUserExists(username: String, callContext: Option[CallContext]): Box[InboundExternalUser] = Failure(setUnimplementedError(nameOf(checkExternalUserExists _)))
/**
* This is a helper method
* for remote user(means the user will get from kafka) to update the views, accountHolders for OBP side
* It depends different use cases, normally (also see it in KafkaMappedConnector_vJune2017.scala)
*
* @param user the user is from remote side
*/
@deprecated("Now move it to AuthUser.updateUserAccountViews","17-07-2017")
def updateUserAccountViewsOld(user: ResourceUser) = {}
//This one just added the callContext in parameters.
def getBankAccountLegacy(bankId : BankId, accountId : AccountId, callContext: Option[CallContext]) : Box[(BankAccount, Option[CallContext])]= Failure(setUnimplementedError(nameOf(getBankAccountLegacy _)))

View File

@ -464,8 +464,7 @@ object ConnectorBuilderUtil {
// "getDynamicEndpoint",
// "getDynamicEndpoints",
// "checkExternalUserCredentials",// this is not a standard connector method.
// "getUser", // this is not a standard connector method.
// "checkExternalUserCredentials",// this is not a standard connector method.
// "checkExternalUserExists", // this is not a standard connector method.
).distinct
}

View File

@ -829,34 +829,7 @@ object AkkaConnector_vDec2018 extends Connector with AkkaConnectorActorInit {
val response: Future[Box[InBound]] = (southSideActor ? req).mapTo[InBound].recoverWith(recoverFunction).map(Box !! _)
response.map(convertToTuple[ChallengeCommons](callContext))
}
messageDocs += getUserDoc
def getUserDoc = MessageDoc(
process = "obp.getUser",
messageFormat = messageFormat,
description = "Get User",
outboundTopic = None,
inboundTopic = None,
exampleOutboundMessage = (
OutBoundGetUser(name=userNameExample.value,
password=passwordExample.value)
),
exampleInboundMessage = (
InBoundGetUser(status=MessageDocsSwaggerDefinitions.inboundStatus,
data= InboundUser(email=emailExample.value,
password=passwordExample.value,
displayName=displayNameExample.value))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
override def getUser(name: String, password: String): Box[InboundUser] = {
import com.openbankproject.commons.dto.{InBoundGetUser => InBound, OutBoundGetUser => OutBound}
val callContext: Option[CallContext] = None
val req = OutBound(name, password)
val response: Future[Box[InBound]] = (southSideActor ? req).mapTo[InBound].recoverWith(recoverFunction).map(Box !! _)
response.map(convertToTuple[InboundUser](callContext))
}
messageDocs += checkExternalUserCredentialsDoc
def checkExternalUserCredentialsDoc = MessageDoc(

View File

@ -759,35 +759,8 @@ trait RestConnector_vMar2019 extends Connector with KafkaHelper with MdcLoggable
val response: Future[Box[InBound]] = sendRequest[InBound](getUrl(callContext, "getBankAccountsForUser"), HttpMethods.POST, req, callContext)
response.map(convertToTuple[List[InboundAccountCommons]](callContext))
}
messageDocs += getUserDoc
def getUserDoc = MessageDoc(
process = "obp.getUser",
messageFormat = messageFormat,
description = "Get User",
outboundTopic = None,
inboundTopic = None,
exampleOutboundMessage = (
OutBoundGetUser(name=userNameExample.value,
password=passwordExample.value)
),
exampleInboundMessage = (
InBoundGetUser(status=MessageDocsSwaggerDefinitions.inboundStatus,
data= InboundUser(email=emailExample.value,
password=passwordExample.value,
displayName=displayNameExample.value))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
override def getUser(name: String, password: String): Box[InboundUser] = {
import com.openbankproject.commons.dto.{InBoundGetUser => InBound, OutBoundGetUser => OutBound}
val callContext: Option[CallContext] = None
val req = OutBound(name, password)
val response: Future[Box[InBound]] = sendRequest[InBound](getUrl(callContext, "getUser"), HttpMethods.POST, req, callContext)
response.map(convertToTuple[InboundUser](callContext))
}
messageDocs += checkExternalUserCredentialsDoc
def checkExternalUserCredentialsDoc = MessageDoc(
process = "obp.checkExternalUserCredentials",

View File

@ -889,35 +889,8 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable {
val response: Future[Box[InBound]] = sendRequest[InBound]("obp_get_bank_accounts_for_user", req, callContext)
response.map(convertToTuple[List[InboundAccountCommons]](callContext))
}
messageDocs += getUserDoc
def getUserDoc = MessageDoc(
process = "obp.getUser",
messageFormat = messageFormat,
description = "Get User",
outboundTopic = None,
inboundTopic = None,
exampleOutboundMessage = (
OutBoundGetUser(name=userNameExample.value,
password=passwordExample.value)
),
exampleInboundMessage = (
InBoundGetUser(status=MessageDocsSwaggerDefinitions.inboundStatus,
data= InboundUser(email=emailExample.value,
password=passwordExample.value,
displayName=displayNameExample.value))
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
override def getUser(name: String, password: String): Box[InboundUser] = {
import com.openbankproject.commons.dto.{InBoundGetUser => InBound, OutBoundGetUser => OutBound}
val callContext: Option[CallContext] = None
val req = OutBound(name, password)
val response: Future[Box[InBound]] = sendRequest[InBound]("obp_get_user", req, callContext)
response.map(convertToTuple[InboundUser](callContext))
}
messageDocs += checkExternalUserCredentialsDoc
def checkExternalUserCredentialsDoc = MessageDoc(
process = "obp.checkExternalUserCredentials",

View File

@ -297,56 +297,6 @@ trait KafkaMappedConnector_vSept2018 extends Connector with KafkaHelper with Mdc
}
}
messageDocs += MessageDoc(
process = "obp.getUser",
messageFormat = messageFormat,
description = "Gets the User as identifiedgetAdapterInfo by the the credentials (username and password) supplied.",
outboundTopic = Some(Topics.createTopicByClassName(OutboundGetUserByUsernamePassword.getClass.getSimpleName).request),
inboundTopic = Some(Topics.createTopicByClassName(OutboundGetUserByUsernamePassword.getClass.getSimpleName).response),
exampleOutboundMessage = (
OutboundGetUserByUsernamePassword(
authInfoExample,
password = "2b78e8"
)
),
exampleInboundMessage = (
InboundGetUserByUsernamePassword(
inboundAuthInfoExample,
InboundValidatedUser(
errorCodeExample,
inboundStatusMessagesExample,
email = "susan.uk.29@example.com",
displayName = "susan"
)
)
),
outboundAvroSchema = Some(parse(SchemaFor[OutboundGetUserByUsernamePassword]().toString(true))),
inboundAvroSchema = Some(parse(SchemaFor[InboundGetUserByUsernamePassword]().toString(true))),
adapterImplementation = Some(AdapterImplementation("User", 1))
)
//TODO This method is not used in api level, so not CallContext here for now..
override def getUser(username: String, password: String): Box[InboundUser] = writeMetricEndpointTiming {
/**
* Please note that "var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)"
* is just a temporary value field with UUID values in order to prevent any ambiguity.
* The real value will be assigned by Macro during compile time at this line of a code:
* https://github.com/OpenBankProject/scala-macros/blob/master/macros/src/main/scala/com/tesobe/CacheKeyFromArgumentsMacro.scala#L49
*/
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
CacheKeyFromArguments.buildCacheKey {
Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(userTTL second) {
val req = OutboundGetUserByUsernamePassword(AuthInfo("", username, ""), password = password)
val InboundFuture = processRequest[InboundGetUserByUsernamePassword](req) map { inbound =>
inbound.map(_.data).map(inboundValidatedUser =>(InboundUser(inboundValidatedUser.email, password, inboundValidatedUser.displayName)))
}
getValueFromFuture(InboundFuture)
}
}
}("getUser")
messageDocs += MessageDoc(
process = s"obp.getBanks",
messageFormat = messageFormat,

View File

@ -906,51 +906,6 @@ import net.liftweb.util.Helpers._
}
}
/**
* This method is belong to AuthUser, it is used for authentication(Login stuff)
* 1 get the user over connector.
* 2 check whether it is existing in AuthUser table in obp side.
* 3 if not existing, will create new AuthUser.
* @return Return the authUser
*/
@deprecated("we have @checkExternalUserViaConnector method ","01-07-2020")
def getUserFromConnector(name: String, password: String):Box[AuthUser] = {
Connector.connector.vend.getUser(name, password) match {
case Full(InboundUser(extEmail, extPassword, extUsername)) => {
val extProvider = connector
val user = findAuthUserByUsernameLocallyLegacy(name) match {
// Check if the external user is already created locally
case Full(user) if user.validated_?
// && user.provider == extProvider
=> {
// Return existing user if found
logger.info("external user already exists locally, using that one")
user
}
// If not found, create a new user
case _ =>
// Create AuthUser using fetched data from connector
// assuming that user's email is always validated
logger.info("external user "+ extEmail +" does not exist locally, creating one")
val newUser = AuthUser.create
.firstName(extUsername)
.email(extEmail)
.username(extUsername)
// No need to store password, so store dummy string instead
.password(generateUUID())
.provider(extProvider)
.validated(true)
// Return created user
newUser.saveMe()
}
Full(user)
}
case _ => {
Empty
}
}
}
/**
* This method is belong to AuthUser, it is used for authentication(Login stuff)
* 1 get the user over connector.
@ -1255,17 +1210,9 @@ def restoreSomeSessions(): Unit = {
* The user authentications is not exciting in obp side, it need get the user via connector
*/
def testExternalPassword(usernameFromGui: String, passwordFromGui: String): Boolean = {
// TODO Remove kafka and obpjvm special cases
if (connector.startsWith("kafka")) {
getUserFromConnector(usernameFromGui, passwordFromGui) match {
case Full(user:AuthUser) => true
case _ => false
}
} else {
checkExternalUserViaConnector(usernameFromGui, passwordFromGui) match {
case Full(user:AuthUser) => true
case _ => false
}
checkExternalUserViaConnector(usernameFromGui, passwordFromGui) match {
case Full(user:AuthUser) => true
case _ => false
}
}
@ -1273,21 +1220,11 @@ def restoreSomeSessions(): Unit = {
* This method will update the views and createAccountHolder ....
*/
def externalUserHelper(name: String, password: String): Box[AuthUser] = {
// TODO Remove kafka and obpjvm special cases
if (connector.startsWith("kafka") ) {
for {
user <- getUserFromConnector(name, password)
u <- Users.users.vend.getUserByProviderAndUsername(user.getProvider(), name)
} yield {
user
}
} else {
for {
user <- checkExternalUserViaConnector(name, password)
u <- Users.users.vend.getUserByProviderAndUsername(user.getProvider(), name)
} yield {
user
}
for {
user <- checkExternalUserViaConnector(name, password)
u <- Users.users.vend.getUserByProviderAndUsername(user.getProvider(), name)
} yield {
user
}
}