Skip to content

Commit daa97ea

Browse files
authored
Merge pull request #2722 from hongwei1/obp-develop
feature/removed findAuthUserByUsernameLocallyLegacy method
2 parents e9ebb7c + fa6214c commit daa97ea

File tree

7 files changed

+241
-300
lines changed

7 files changed

+241
-300
lines changed

obp-api/src/main/scala/code/api/directlogin.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ object DirectLogin extends RestHelper with MdcLoggable {
165165
} else if (userId == AuthUser.usernameLockedStateCode) {
166166
message = ErrorMessages.UsernameHasBeenLocked
167167
httpCode = 401
168+
} else if (userId == AuthUser.userEmailNotValidatedStateCode) {
169+
message = ErrorMessages.UserEmailNotValidated
170+
httpCode = 401
168171
} else {
169172
val jwtPayloadAsJson =
170173
"""{

obp-api/src/main/scala/code/api/util/ErrorMessages.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ object ErrorMessages {
159159
val InvalidDirectLoginParameters = "OBP-20012: Invalid direct login parameters"
160160

161161
val UsernameHasBeenLocked = "OBP-20013: The account has been locked, please contact an administrator!"
162+
val UserEmailNotValidated = "OBP-20073: The user email has not been validated. Please validate your email address first."
162163

163164
val InvalidConsumerId = "OBP-20014: Invalid Consumer ID. Please specify a valid value for CONSUMER_ID."
164165

@@ -883,6 +884,7 @@ object ErrorMessages {
883884
InvalidConsumerKey -> 401,
884885
// InvalidConsumerCredentials -> 401, // or 400
885886
UsernameHasBeenLocked -> 401,
887+
UserEmailNotValidated -> 401,
886888
UserNoPermissionAccessView -> 403,
887889
UserLacksPermissionCanGrantAccessToViewForTargetAccount -> 403,
888890
UserLacksPermissionCanRevokeAccessToViewForTargetAccount -> 403,

obp-api/src/main/scala/code/api/v6_0_0/APIMethods600.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ import code.api.util.ExampleValue
7171
import code.api.util.ExampleValue.dynamicEntityResponseBodyExample
7272
import net.liftweb.common.Box
7373

74+
import java.net.URLDecoder
75+
import java.nio.charset.StandardCharsets
7476
import java.text.SimpleDateFormat
7577
import java.util.UUID.randomUUID
7678
import scala.collection.immutable.{List, Nil}
@@ -8754,10 +8756,12 @@ trait APIMethods600 {
87548756
postedData <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the PostVerifyUserCredentialsJsonV600", 400, callContext) {
87558757
json.extract[PostVerifyUserCredentialsJsonV600]
87568758
}
8759+
// Decode the provider in case it's URL-encoded (e.g., "http%3A%2F%2Fexample.com" -> "http://example.com")
8760+
decodedProvider = URLDecoder.decode(postedData.provider, StandardCharsets.UTF_8)
87578761
// Validate credentials using the existing AuthUser mechanism
87588762

87598763
resourceUserIdBox =
8760-
if (postedData.provider == Constant.localIdentityProvider || postedData.provider.isEmpty) {
8764+
if (decodedProvider == Constant.localIdentityProvider || decodedProvider.isEmpty) {
87618765
// Local provider: only check local credentials. No external fallback.
87628766
val result = code.model.dataAccess.AuthUser.getResourceUserId(
87638767
postedData.username, postedData.password, Constant.localIdentityProvider
@@ -8767,8 +8771,8 @@ trait APIMethods600 {
87678771
} else {
87688772
// External provider: validate via connector. Local DB stores a random UUID
87698773
// as password for external users, so getResourceUserId would always fail.
8770-
if (LoginAttempt.userIsLocked(postedData.provider, postedData.username)) {
8771-
logger.info(s"verifyUserCredentials says: external user is locked, provider: ${postedData.provider}, username: ${postedData.username}")
8774+
if (LoginAttempt.userIsLocked(decodedProvider, postedData.username)) {
8775+
logger.info(s"verifyUserCredentials says: external user is locked, provider: ${decodedProvider}, username: ${postedData.username}")
87728776
Full(code.model.dataAccess.AuthUser.usernameLockedStateCode)
87738777
} else {
87748778
val connectorResult = code.model.dataAccess.AuthUser.externalUserHelper(
@@ -8777,10 +8781,10 @@ trait APIMethods600 {
87778781
logger.info(s"verifyUserCredentials says: externalUserHelper result: $connectorResult")
87788782
connectorResult match {
87798783
case Full(_) =>
8780-
LoginAttempt.resetBadLoginAttempts(postedData.provider, postedData.username)
8784+
LoginAttempt.resetBadLoginAttempts(decodedProvider, postedData.username)
87818785
connectorResult
87828786
case _ =>
8783-
LoginAttempt.incrementBadLoginAttempts(postedData.provider, postedData.username)
8787+
LoginAttempt.incrementBadLoginAttempts(decodedProvider, postedData.username)
87848788
connectorResult
87858789
}
87868790
}
@@ -8803,7 +8807,7 @@ trait APIMethods600 {
88038807
}
88048808
// Verify provider matches if specified and not empty
88058809
_ <- Helper.booleanToFuture(s"$InvalidLoginCredentials Authentication provider mismatch.", 401, callContext) {
8806-
postedData.provider.isEmpty || user.provider == postedData.provider
8810+
decodedProvider.isEmpty || user.provider == decodedProvider
88078811
}
88088812
} yield {
88098813
(JSONFactory200.createUserJSON(user), HttpCode.`200`(callContext))

obp-api/src/main/scala/code/bankconnectors/LocalMappedConnector.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import code.kycstatuses.KycStatuses
4040
import code.meetings.Meetings
4141
import code.metadata.counterparties.Counterparties
4242
import code.model._
43-
import code.model.dataAccess.AuthUser.findAuthUserByUsernameLocallyLegacy
4443
import code.model.dataAccess._
4544
import code.productAttributeattribute.MappedProductAttribute
4645
import code.productattribute.ProductAttributeX
@@ -5356,7 +5355,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
53565355
//NOTE: this method is not for mapped connector, we put it here for the star default implementation.
53575356
// : we call that method only when we set external authentication and provider is not OBP-API
53585357
override def checkExternalUserExists(username: String, callContext: Option[CallContext]): Box[InboundExternalUser] = {
5359-
findAuthUserByUsernameLocallyLegacy(username).map(user =>
5358+
AuthUser.findAuthUserByUsernameAndProvider(username, Constant.localIdentityProvider).map(user =>
53605359
InboundExternalUser(aud = "",
53615360
exp = "",
53625361
iat = "",

0 commit comments

Comments
 (0)