Skip to content

Commit

Permalink
fix: Respond with internal error instead of bad credentials when trip…
Browse files Browse the repository at this point in the history
…lestore is down during authentication (DEV-4019) (#3342)
  • Loading branch information
BalduinLandolt authored Aug 27, 2024
1 parent 8f7172d commit cb3f69a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ final case class AuthenticatorLive(
} yield user

private def getUserByIri(iri: UserIri): IO[AuthenticatorError, User] =
userService.findUserByIri(iri).some.orElseFail(UserNotFound).tap(ensureActiveUser).logError
userService.findUserByIri(iri).orDie.someOrFail(UserNotFound).tap(ensureActiveUser)

private def getUserByEmail(email: Email): IO[AuthenticatorError, User] =
userService.findUserByEmail(email).some.orElseFail(UserNotFound).tap(ensureActiveUser)
userService.findUserByEmail(email).orDie.someOrFail(UserNotFound).tap(ensureActiveUser)

private def getUserByUsername(username: Username): IO[AuthenticatorError, User] =
userService.findUserByUsername(username).some.orElseFail(UserNotFound).tap(ensureActiveUser)
userService.findUserByUsername(username).orDie.someOrFail(UserNotFound).tap(ensureActiveUser)

private def ensureActiveUser(user: User): IO[AuthenticatorError, Unit] = for {
_ <- ZIO.fail(UserNotActive).when(!user.isActive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import zio.ZLayer

import java.time.Instant

import dsp.errors.AuthenticationException
import dsp.errors.BadCredentialsException
import org.knora.webapi.config.AppConfig
import org.knora.webapi.slice.admin.domain.model.Username
Expand Down Expand Up @@ -51,6 +52,8 @@ case class AuthenticationEndpointsV2Handler(
}).mapBoth(
_ => BadCredentialsException(BAD_CRED_NOT_VALID),
(_, token) => setCookieAndResponse(token),
).catchAllDefect(e =>
ZIO.fail(AuthenticationException("An internal error happened during authentication", Some(e))),
)
},
)
Expand Down

0 comments on commit cb3f69a

Please sign in to comment.