Skip to content

Commit bd5117f

Browse files
authored
Merge pull request #2718 from constantine2nd/develop
Direct Login
2 parents 83e4dae + bb67283 commit bd5117f

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ object DirectLogin extends RestHelper with MdcLoggable {
352352
case false => false
353353
}*/
354354
case _ => false
355+
} recover {
356+
case e: Throwable =>
357+
logger.error(s"validatorFuture.validAccessTokenFuture failed: ${e.getMessage}", e)
358+
false
355359
}
356360
}
357361

@@ -427,6 +431,10 @@ object DirectLogin extends RestHelper with MdcLoggable {
427431
Tokens.tokens.vend.getTokenByKeyAndTypeFuture(tokenKey, TokenType.Access) map {
428432
case Full(token) => token.isValid
429433
case _ => false
434+
} recover {
435+
case e: Throwable =>
436+
logger.error(s"validatorFutureWithParams.validAccessTokenFuture failed: ${e.getMessage}", e)
437+
false
430438
}
431439
}
432440

@@ -630,6 +638,10 @@ object DirectLogin extends RestHelper with MdcLoggable {
630638
Tokens.tokens.vend.getTokenByKeyFuture(token) map {
631639
case Full(t) => t.consumerId.foreign
632640
case _ => Empty
641+
} recover {
642+
case e: Throwable =>
643+
logger.error(s"getConsumerFromDirectLoginToken failed: ${e.getMessage}", e)
644+
Empty
633645
}
634646
}
635647

@@ -640,7 +652,7 @@ object DirectLogin extends RestHelper with MdcLoggable {
640652
* @return Future[Box[User]]
641653
*/
642654
def getUserFromDirectLoginToken(token: String): Future[Box[User]] = {
643-
for {
655+
(for {
644656
tokenBox <- Tokens.tokens.vend.getTokenByKeyFuture(token)
645657
userIdBox = tokenBox.map(_.userForeignKey.get)
646658
user <- userIdBox match {
@@ -649,6 +661,10 @@ object DirectLogin extends RestHelper with MdcLoggable {
649661
}
650662
} yield {
651663
user
664+
}) recover {
665+
case e: Throwable =>
666+
logger.error(s"getUserFromDirectLoginToken failed: ${e.getMessage}", e)
667+
Empty
652668
}
653669
}
654670
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8752,8 +8752,7 @@ trait APIMethods600 {
87528752
case "users" :: "verify-credentials" :: Nil JsonPost json -> _ => {
87538753
cc => implicit val ec = EndpointContext(Some(cc))
87548754
for {
8755-
(Full(u), callContext) <- authenticatedAccess(cc)
8756-
postedData <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the PostVerifyUserCredentialsJsonV600", 400, callContext) {
8755+
postedData <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the PostVerifyUserCredentialsJsonV600", 400, Some(cc)) {
87578756
json.extract[PostVerifyUserCredentialsJsonV600]
87588757
}
87598758
// Validate credentials using the existing AuthUser mechanism
@@ -8788,27 +8787,27 @@ trait APIMethods600 {
87888787
}
87898788
}
87908789
// Check if account is locked
8791-
_ <- Helper.booleanToFuture(UsernameHasBeenLocked, 401, callContext) {
8790+
_ <- Helper.booleanToFuture(UsernameHasBeenLocked, 401, Some(cc)) {
87928791
resourceUserIdBox != Full(code.model.dataAccess.AuthUser.usernameLockedStateCode)
87938792
}
87948793
// Check if credentials are valid
87958794
resourceUserId <- Future {
87968795
resourceUserIdBox
87978796
} map {
8798-
x => unboxFullOrFail(x, callContext, s"$InvalidLoginCredentials Failed to authenticate user credentials.", 401)
8797+
x => unboxFullOrFail(x, Some(cc), s"$InvalidLoginCredentials Failed to authenticate user credentials.", 401)
87998798
}
88008799
// Get the user object
88018800
user <- Future {
88028801
Users.users.vend.getUserByResourceUserId(resourceUserId)
88038802
} map {
8804-
x => unboxFullOrFail(x, callContext, s"$InvalidLoginCredentials User account not found in system.", 401)
8803+
x => unboxFullOrFail(x, Some(cc), s"$InvalidLoginCredentials User account not found in system.", 401)
88058804
}
88068805
// Verify provider matches if specified and not empty
8807-
_ <- Helper.booleanToFuture(s"$InvalidLoginCredentials Authentication provider mismatch.", 401, callContext) {
8806+
_ <- Helper.booleanToFuture(s"$InvalidLoginCredentials Authentication provider mismatch.", 401, Some(cc)) {
88088807
postedData.provider.isEmpty || user.provider == postedData.provider
88098808
}
88108809
} yield {
8811-
(JSONFactory200.createUserJSON(user), HttpCode.`200`(callContext))
8810+
(JSONFactory200.createUserJSON(user), HttpCode.`200`(Some(cc)))
88128811
}
88138812
}
88148813
}

0 commit comments

Comments
 (0)