-
Notifications
You must be signed in to change notification settings - Fork 4
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 #21 from ing-bank/feature/endpoint-security
Add token authentication for isActiveCredentials endpoint
- Loading branch information
Showing
7 changed files
with
96 additions
and
32 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
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
33 changes: 33 additions & 0 deletions
33
src/main/scala/com/ing/wbaa/airlock/sts/util/JwtToken.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,33 @@ | ||
package com.ing.wbaa.airlock.sts.util | ||
|
||
import com.auth0.jwt.JWT | ||
import com.auth0.jwt.algorithms.Algorithm | ||
import com.ing.wbaa.airlock.sts.config.StsSettings | ||
import com.typesafe.scalalogging.LazyLogging | ||
|
||
import scala.util.{ Failure, Success, Try } | ||
|
||
trait JwtToken extends LazyLogging { | ||
protected[this] def stsSettings: StsSettings | ||
|
||
def verifyInternalToken(bearerToken: String): Boolean = | ||
Try { | ||
val algorithm = Algorithm.HMAC256(stsSettings.decodeSecret) | ||
val verifier = JWT.require(algorithm) | ||
.withIssuer("airlock") | ||
.build() | ||
verifier.verify(bearerToken) | ||
} match { | ||
case Success(t) => | ||
val serviceName = t.getClaim("service").asString() | ||
if (serviceName == "airlock") { | ||
logger.debug(s"Successfully verified internal token for $serviceName") | ||
true | ||
} else { | ||
logger.debug(s"Failed to verify internal token") | ||
false | ||
} | ||
case Failure(exception) => throw exception | ||
} | ||
|
||
} |
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