feature/Add connector method checkExternalUserExists

This commit is contained in:
Marko Milić 2020-08-10 08:29:44 +02:00
parent 14bd0a2846
commit e40e9be5ff
6 changed files with 8554 additions and 460 deletions

View File

@ -420,6 +420,13 @@ trait Connector extends MdcLoggable {
* @return
*/
def checkExternalUserCredentials(username: String, password: String, callContext: Option[CallContext]): Box[InboundExternalUser] = Failure(setUnimplementedError)
/**
* This method is for checking external User via connector
* @param username
* @return
*/
def checkExternalUserExists(username: String, callContext: Option[CallContext]): Box[InboundExternalUser] = Failure(setUnimplementedError)
/**
* This is a helper method

View File

@ -357,7 +357,8 @@ object ConnectorBuilderUtil {
// The follow methods's parameter or return type are special
"getCurrentFxRate",
"getBankAccountOld", // old method, but v3.0.0 apis use a lot
"checkExternalUserCredentials"
"checkExternalUserCredentials",
"checkExternalUserExists"
).distinct
/**

View File

@ -121,9 +121,30 @@ class AuthUser extends MegaProtoUser[AuthUser] with MdcLoggable {
override def displayName = S.?("Username")
override def dbIndexed_? = true
override def validations = isEmpty(Helper.i18n("Please.enter.your.username")) _ ::
valUnique(Helper.i18n("unique.username")) _ ::
valUnique(Helper.i18n("unique.username")) _ ::
valUniqueExternally(Helper.i18n("unique.username")) _ ::
super.validations
override val fieldId = Some(Text("txtUsername"))
/**
* Make sure that the field is unique in the CBS
*/
def valUniqueExternally(msg: => String)(value: String): List[FieldError] ={
if (APIUtil.getPropsAsBoolValue("connector.user.authentication", false)) {
Connector.connector.vend.checkExternalUserExists(value, None).map(_.name) match {
case Full(name) =>
value match {
case username if username == name => List(FieldError(this, Text(msg))) // issue 179
case _ => Nil
}
case _ => List(FieldError(this, Text(msg))) // issue 179
}
} else {
Nil
}
}
}
override lazy val password = new MyPasswordNew
@ -820,7 +841,7 @@ def restoreSomeSessions(): Unit = {
user.validated_? && !LoginAttempt.userIsLocked(usernameFromGui) &&
!isObpProvider(user)
}
def loginAction = {
if (S.post_?) {
val usernameFromGui = S.param("username").getOrElse("")

View File

@ -1277,4 +1277,7 @@ case class InBoundDeleteCustomerAttribute(inboundAdapterCallContext: InboundAdap
case class OutBoundCheckExternalUserCredentials(outboundAdapterCallContext: OutboundAdapterCallContext, username: String, password: String) extends TopicTrait
case class InBoundCheckExternalUserCredentials(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, data: InboundExternalUser) extends InBoundTrait[InboundExternalUser]
case class OutBoundCheckExternalUserExists(outboundAdapterCallContext: OutboundAdapterCallContext, username: String) extends TopicTrait
case class InBoundCheckExternalUserExists(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, data: InboundExternalUser) extends InBoundTrait[InboundExternalUser]
// --------------------- some special connector methods corresponding InBound and OutBound -- end --