-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V4
- Loading branch information
Showing
78 changed files
with
1,583 additions
and
849 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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,6 +1,6 @@ | ||
#!/bin/bash | ||
|
||
NAME="Dark Lord Toni" | ||
NAME="Development" | ||
REMOVE=0 | ||
|
||
RED='\033[0;31m' | ||
|
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
File renamed without changes.
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 +1 @@ | ||
{"name":"sbt","version":"1.4.4","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["/Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/bin/java","-Xms100m","-Xmx100m","-classpath","/Users/patrickstadler/Library/Application Support/JetBrains/IntelliJIdea2020.3/plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp"]} | ||
{"name":"sbt","version":"1.5.0","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["/Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/bin/java","-Xms100m","-Xmx100m","-classpath","/Users/patrickstadler/Library/Application Support/JetBrains/IntelliJIdea2020.3/plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp","--sbt-launch-jar=/Users/patrickstadler/Library/Application%20Support/JetBrains/IntelliJIdea2020.3/plugins/Scala/launcher/sbt-launch.jar"]} |
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
50 changes: 38 additions & 12 deletions
50
app/de/innfactory/bootstrapplay2/actions/CompanyForUserExtractAction.scala
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,35 +1,61 @@ | ||
package de.innfactory.bootstrapplay2.actions | ||
|
||
import cats.implicits.catsSyntaxEitherId | ||
import com.google.inject.Inject | ||
import de.innfactory.bootstrapplay2.common.authorization.FirebaseEmailExtractor | ||
import de.innfactory.bootstrapplay2.common.request.TraceContext | ||
import de.innfactory.bootstrapplay2.common.results.ErrorResponse | ||
import de.innfactory.bootstrapplay2.db.CompaniesDAO | ||
import de.innfactory.bootstrapplay2.models.api.Company | ||
import play.api.mvc.{ ActionBuilder, ActionTransformer, AnyContent, BodyParsers, Request, WrappedRequest } | ||
import de.innfactory.play.tracing.{ RequestWithTrace, TraceRequest, UserExtractionActionBase } | ||
import io.opencensus.trace.Span | ||
import play.api.Environment | ||
import play.api.mvc.Results.Forbidden | ||
import play.api.mvc.{ BodyParsers, Request, Result, WrappedRequest } | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
class RequestWithCompany[A](val company: Option[Company], val email: Option[String], request: Request[A]) | ||
extends WrappedRequest[A](request) | ||
class RequestWithCompany[A]( | ||
val company: Company, | ||
val email: Option[String], | ||
val request: Request[A], | ||
val traceSpan: Span | ||
) extends WrappedRequest[A](request) | ||
with TraceRequest[A] | ||
|
||
class CompanyForUserExtractAction @Inject() ( | ||
val parser: BodyParsers.Default, | ||
companiesDAO: CompaniesDAO, | ||
firebaseEmailExtractor: FirebaseEmailExtractor[Any] | ||
)(implicit val executionContext: ExecutionContext) | ||
extends ActionBuilder[RequestWithCompany, AnyContent] | ||
with ActionTransformer[Request, RequestWithCompany] { | ||
def transform[A](request: Request[A]): Future[RequestWithCompany[A]] = | ||
)(implicit executionContext: ExecutionContext, parser: BodyParsers.Default, environment: Environment) | ||
extends UserExtractionActionBase[RequestWithTrace, RequestWithCompany] { | ||
|
||
override def extractUserAndCreateNewRequest[A](request: RequestWithTrace[A])(implicit | ||
environment: Environment, | ||
parser: BodyParsers.Default, | ||
executionContext: ExecutionContext | ||
): Future[Either[Result, RequestWithCompany[A]]] = | ||
Future.successful { | ||
val result: Option[Future[Option[Company]]] = for { | ||
email <- firebaseEmailExtractor.extractEmail(request) | ||
} yield for { | ||
user <- companiesDAO.internal_lookupByEmail(email) | ||
user <- companiesDAO.internal_lookupByEmail(email)(new TraceContext(request.traceSpan)) | ||
} yield user | ||
|
||
result match { | ||
case Some(v) => | ||
v.map(new RequestWithCompany(_, firebaseEmailExtractor.extractEmail(request), request)) | ||
case None => Future(new RequestWithCompany(None, firebaseEmailExtractor.extractEmail(request), request)) | ||
v.map { | ||
case Some(value) => | ||
new RequestWithCompany( | ||
value, | ||
firebaseEmailExtractor.extractEmail(request), | ||
request.request, | ||
request.traceSpan | ||
).asRight[Result] | ||
case None => Forbidden(ErrorResponse.fromMessage("Forbidden")).asLeft[RequestWithCompany[A]] | ||
} | ||
case None => | ||
Future( | ||
Forbidden(ErrorResponse.fromMessage("Forbidden")).asLeft[RequestWithCompany[A]] | ||
) | ||
} | ||
}.flatten | ||
} |
68 changes: 20 additions & 48 deletions
68
app/de/innfactory/bootstrapplay2/actions/JwtValidationAction.scala
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,56 +1,28 @@ | ||
package de.innfactory.bootstrapplay2.actions | ||
|
||
import com.google.inject.Inject | ||
import com.nimbusds.jwt.proc.BadJWTException | ||
import de.innfactory.auth.firebase.validator.{ JwtToken, JwtValidator } | ||
import play.api.Environment | ||
import play.api.mvc.Results.Forbidden | ||
import play.api.mvc.Results.Unauthorized | ||
import de.innfactory.auth.firebase.validator.JwtValidator | ||
import de.innfactory.bootstrapplay2.common.implicits.JWT.JwtTokenGenerator | ||
import de.innfactory.play.tracing.{ BaseAuthHeaderRefineAction, RequestWithTrace } | ||
import play.api.mvc.BodyParsers | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
import play.api.mvc._ | ||
import scala.concurrent.ExecutionContext | ||
|
||
class JwtValidationAction @Inject() (parser: BodyParsers.Default, jwtValidator: JwtValidator, environment: Environment)( | ||
implicit ec: ExecutionContext | ||
) extends ActionBuilderImpl(parser) { | ||
override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = | ||
if (extractAndCheckAuthHeader(request.headers).getOrElse(false)) | ||
block(request) | ||
else if (request.headers.get("Authorization").isEmpty) | ||
Future.successful(Unauthorized("Unauthorized")) | ||
else | ||
Future.successful(Forbidden("Forbidden")) | ||
class JwtValidationAction @Inject() ( | ||
parser: BodyParsers.Default, | ||
jwtValidator: JwtValidator | ||
)(implicit | ||
ec: ExecutionContext | ||
) extends BaseAuthHeaderRefineAction[RequestWithTrace](parser) { | ||
|
||
/** | ||
* Extract auth header from requestHeaders | ||
* @param requestHeader | ||
* @return | ||
*/ | ||
def extractAndCheckAuthHeader(requestHeader: Headers) = | ||
for { | ||
header <- requestHeader.get("Authorization") | ||
} yield checkAuthHeader(header) | ||
|
||
/** | ||
* check and validate auth header | ||
* @param authHeader | ||
* @return | ||
*/ | ||
def checkAuthHeader(authHeader: String): Boolean = | ||
// In Test env, jwt will not be validated | ||
if (environment.mode.toString != "Test") { | ||
val jwtToken = authHeader match { | ||
case token: String if token.startsWith("Bearer") => | ||
JwtToken(token.splitAt(7)._2) | ||
case token => JwtToken(token) | ||
} | ||
|
||
jwtValidator.validate(jwtToken) match { | ||
case Left(error: BadJWTException) => | ||
false | ||
case Right(_) => true | ||
} | ||
} else | ||
true | ||
override def checkAuthHeader(authHeader: String): Boolean = { | ||
val jwtToken = authHeader.toJwtToken | ||
val res = jwtValidator.validate(jwtToken) match { | ||
case Left(_) => false | ||
case Right(_) => true | ||
} | ||
println("Auth Header Check on " + authHeader + " " + res) | ||
res | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
app/de/innfactory/bootstrapplay2/actions/TracingCompanyAction.scala
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.innfactory.bootstrapplay2.actions | ||
|
||
import com.google.inject.Inject | ||
import de.innfactory.play.tracing.TracingAction | ||
import play.api.Environment | ||
import play.api.mvc._ | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
class TracingCompanyAction @Inject() ( | ||
val parser: BodyParsers.Default, | ||
companyAction: CompanyForUserExtractAction, | ||
jwtValidationAction: JwtValidationAction, | ||
traceAction: TracingAction, | ||
implicit val environment: Environment | ||
)(implicit val executionContext: ExecutionContext) { | ||
def apply(traceString: String): ActionBuilder[RequestWithCompany, AnyContent] = | ||
traceAction(traceString).andThen(jwtValidationAction).andThen(companyAction) | ||
} |
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.