-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
To-om
committed
Mar 27, 2017
1 parent
fb66d75
commit dfd75f3
Showing
4 changed files
with
55 additions
and
28 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
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,13 +1,44 @@ | ||
package global | ||
|
||
import javax.inject.{ Inject, Singleton } | ||
import javax.inject.{ Inject, Provider, Singleton } | ||
|
||
import akka.stream.Materializer | ||
import play.api.Logger | ||
import play.api.http.HttpFilters | ||
import play.api.libs.crypto.CSRFTokenSigner | ||
import play.api.mvc.{ EssentialFilter, RequestHeader } | ||
import play.filters.csrf.CSRF.{ ErrorHandler, TokenProvider } | ||
import play.filters.csrf.CSRFConfig | ||
|
||
import scala.collection.immutable | ||
|
||
import play.api.http.HttpFilters | ||
import play.api.mvc.Filter | ||
@Singleton | ||
class TheHiveFilters @Inject() (injectedFilters: immutable.Set[EssentialFilter]) extends HttpFilters { | ||
override val filters = injectedFilters.toSeq | ||
} | ||
|
||
object CSRFFilter { | ||
private[CSRFFilter] lazy val logger = Logger(getClass) | ||
|
||
def shouldProtect(request: RequestHeader): Boolean = { | ||
val isLogin = request.uri.startsWith("/api/login") | ||
val isApi = request.uri.startsWith("/api") | ||
val isInSession = request.session.data.nonEmpty | ||
val check = !isLogin && isApi && isInSession | ||
logger.debug(s"[csrf] uri ${request.uri} (isLogin=$isLogin, isApi=$isApi, isInSession=$isInSession): ${if (check) "" else "don't"} check") | ||
check | ||
} | ||
|
||
} | ||
|
||
@Singleton | ||
class TheHiveFilters @Inject() (injectedFilters: immutable.Set[Filter]) extends HttpFilters { | ||
val filters = injectedFilters.toSeq | ||
} | ||
class CSRFFilter @Inject() ( | ||
config: Provider[CSRFConfig], | ||
tokenSignerProvider: Provider[CSRFTokenSigner], | ||
tokenProvider: TokenProvider, | ||
errorHandler: ErrorHandler)(mat: Materializer) | ||
extends play.filters.csrf.CSRFFilter( | ||
config.get.copy(shouldProtect = CSRFFilter.shouldProtect), | ||
tokenSignerProvider.get, | ||
tokenProvider, | ||
errorHandler)(mat) |
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