-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1880 from betagouv/master
MEP (endpoints dsl)
- Loading branch information
Showing
34 changed files
with
395 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
package authentication.actions | ||
|
||
import authentication.actions.MaybeUserAction.MaybeUserRequest | ||
import models.User | ||
import play.api.mvc.Results.Forbidden | ||
import play.api.mvc.ActionFilter | ||
import play.api.mvc.Result | ||
import utils.EmailAddress | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.Future | ||
|
||
object ImpersonationAction { | ||
type UserRequest[A] = IdentifiedRequest[User, A] | ||
|
||
def ForbidImpersonation(implicit ec: ExecutionContext): ActionFilter[UserRequest] = new ActionFilter[UserRequest] { | ||
override protected def executionContext: ExecutionContext = ec | ||
|
||
override protected def filter[A](request: UserRequest[A]): Future[Option[Result]] = | ||
Future.successful( | ||
request.identity.impersonator match { | ||
case Some(_) => Some(Forbidden) | ||
case None => None | ||
} | ||
) | ||
} | ||
def forbidImpersonationFilter(implicit ec: ExecutionContext): ActionFilter[UserRequest] = | ||
new ActionFilter[UserRequest] { | ||
override protected def executionContext: ExecutionContext = ec | ||
override protected def filter[A](request: UserRequest[A]): Future[Option[Result]] = | ||
handleImpersonator(request.identity.impersonator) | ||
|
||
} | ||
|
||
def forbidImpersonationOnMaybeUserFilter(implicit ec: ExecutionContext): ActionFilter[MaybeUserRequest] = | ||
new ActionFilter[MaybeUserRequest] { | ||
override protected def executionContext: ExecutionContext = ec | ||
override protected def filter[A](request: MaybeUserRequest[A]): Future[Option[Result]] = | ||
handleImpersonator(request.identity.flatMap(_.impersonator)) | ||
} | ||
|
||
private def handleImpersonator(maybeImpersonator: Option[EmailAddress]) = | ||
Future.successful( | ||
maybeImpersonator match { | ||
case Some(_) => Some(Forbidden) | ||
case None => None | ||
} | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.